mirror of
https://github.com/chylex/Nextcloud-Desktop.git
synced 2025-05-29 10:34:09 +02:00
Get the excluded files test to pass again on Windows
Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
This commit is contained in:
parent
c57eff6fd8
commit
0756497c3e
@ -263,11 +263,6 @@ void ExcludedFiles::addManualExclude(const QString &expr)
|
|||||||
|
|
||||||
void ExcludedFiles::addManualExclude(const QString &expr, const QString &basePath)
|
void ExcludedFiles::addManualExclude(const QString &expr, const QString &basePath)
|
||||||
{
|
{
|
||||||
#if defined(Q_OS_WIN)
|
|
||||||
Q_ASSERT(basePath.size() >= 2 && basePath.at(1) == QLatin1Char(':'));
|
|
||||||
#else
|
|
||||||
Q_ASSERT(basePath.startsWith(QLatin1Char('/')));
|
|
||||||
#endif
|
|
||||||
Q_ASSERT(basePath.endsWith(QLatin1Char('/')));
|
Q_ASSERT(basePath.endsWith(QLatin1Char('/')));
|
||||||
|
|
||||||
auto key = basePath;
|
auto key = basePath;
|
||||||
@ -503,8 +498,8 @@ CSYNC_EXCLUDE_TYPE ExcludedFiles::fullPatternMatch(const QString &p, ItemType fi
|
|||||||
// `path` seems to always be relative to `_localPath`, the tests however have not been
|
// `path` seems to always be relative to `_localPath`, the tests however have not been
|
||||||
// written that way... this makes the tests happy for now. TODO Fix the tests at some point
|
// written that way... this makes the tests happy for now. TODO Fix the tests at some point
|
||||||
QString path = p;
|
QString path = p;
|
||||||
if (path[0] == QLatin1Char('/'))
|
if (path.startsWith(_localPath))
|
||||||
path = path.mid(1);
|
path = path.mid(_localPath.size());
|
||||||
|
|
||||||
QString basePath(_localPath + path);
|
QString basePath(_localPath + path);
|
||||||
while (basePath.size() > _localPath.size()) {
|
while (basePath.size() > _localPath.size()) {
|
||||||
|
@ -234,45 +234,41 @@ private slots:
|
|||||||
|
|
||||||
void check_csync_excluded_per_dir()
|
void check_csync_excluded_per_dir()
|
||||||
{
|
{
|
||||||
setup();
|
const auto tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
||||||
|
excludedFiles.reset(new ExcludedFiles(tempDir + "/"));
|
||||||
|
excludedFiles->setWildcardsMatchSlash(false);
|
||||||
excludedFiles->addManualExclude("A");
|
excludedFiles->addManualExclude("A");
|
||||||
excludedFiles->reloadExcludeFiles();
|
excludedFiles->reloadExcludeFiles();
|
||||||
|
|
||||||
QCOMPARE(check_file_full("A"), CSYNC_FILE_EXCLUDE_LIST);
|
QCOMPARE(check_file_full("A"), CSYNC_FILE_EXCLUDE_LIST);
|
||||||
|
|
||||||
excludedFiles->clearManualExcludes();
|
excludedFiles->clearManualExcludes();
|
||||||
excludedFiles->addManualExclude("A", "/B/");
|
excludedFiles->addManualExclude("A", tempDir + "/B/");
|
||||||
excludedFiles->reloadExcludeFiles();
|
excludedFiles->reloadExcludeFiles();
|
||||||
|
|
||||||
QCOMPARE(check_file_full("A"), CSYNC_NOT_EXCLUDED);
|
QCOMPARE(check_file_full("A"), CSYNC_NOT_EXCLUDED);
|
||||||
QCOMPARE(check_file_full("B/A"), CSYNC_FILE_EXCLUDE_LIST);
|
QCOMPARE(check_file_full("B/A"), CSYNC_FILE_EXCLUDE_LIST);
|
||||||
|
|
||||||
excludedFiles->clearManualExcludes();
|
excludedFiles->clearManualExcludes();
|
||||||
excludedFiles->addManualExclude("A/a1", "/B/");
|
excludedFiles->addManualExclude("A/a1", tempDir + "/B/");
|
||||||
excludedFiles->reloadExcludeFiles();
|
excludedFiles->reloadExcludeFiles();
|
||||||
|
|
||||||
QCOMPARE(check_file_full("A"), CSYNC_NOT_EXCLUDED);
|
QCOMPARE(check_file_full("A"), CSYNC_NOT_EXCLUDED);
|
||||||
QCOMPARE(check_file_full("B/A/a1"), CSYNC_FILE_EXCLUDE_LIST);
|
QCOMPARE(check_file_full("B/A/a1"), CSYNC_FILE_EXCLUDE_LIST);
|
||||||
|
|
||||||
#define FOO_DIR "/tmp/check_csync1/foo"
|
const auto fooDir = QStringLiteral("check_csync1/foo");
|
||||||
#define FOO_EXCLUDE_LIST FOO_DIR "/.sync-exclude.lst"
|
QVERIFY(QDir(tempDir).mkpath(fooDir));
|
||||||
int rc = 0;
|
|
||||||
rc = system("mkdir -p " FOO_DIR);
|
|
||||||
QCOMPARE(rc, 0);
|
|
||||||
FILE *fh = fopen(FOO_EXCLUDE_LIST, "w");
|
|
||||||
QVERIFY(fh != nullptr);
|
|
||||||
rc = fprintf(fh, "bar");
|
|
||||||
QVERIFY(rc != 0);
|
|
||||||
rc = fclose(fh);
|
|
||||||
QCOMPARE(rc, 0);
|
|
||||||
|
|
||||||
excludedFiles->addInTreeExcludeFilePath(FOO_EXCLUDE_LIST);
|
const auto fooExcludeList = QString(tempDir + '/' + fooDir + "/.sync-exclude.lst");
|
||||||
|
QFile excludeList(fooExcludeList);
|
||||||
|
QVERIFY(excludeList.open(QFile::WriteOnly));
|
||||||
|
QCOMPARE(excludeList.write("bar"), 3);
|
||||||
|
excludeList.close();
|
||||||
|
|
||||||
|
excludedFiles->addInTreeExcludeFilePath(fooExcludeList);
|
||||||
excludedFiles->reloadExcludeFiles();
|
excludedFiles->reloadExcludeFiles();
|
||||||
QCOMPARE(check_file_full(FOO_DIR), CSYNC_NOT_EXCLUDED);
|
QCOMPARE(check_file_full(QByteArray(fooDir.toUtf8() + "/bar")), CSYNC_FILE_EXCLUDE_LIST);
|
||||||
QCOMPARE(check_file_full(FOO_DIR "/bar"), CSYNC_FILE_EXCLUDE_LIST);
|
QCOMPARE(check_file_full(QByteArray(fooDir.toUtf8() + "/baz")), CSYNC_NOT_EXCLUDED);
|
||||||
QCOMPARE(check_file_full(FOO_DIR "/baz"), CSYNC_NOT_EXCLUDED);
|
|
||||||
#undef FOO_DIR
|
|
||||||
#undef FOO_EXCLUDE_LIST
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_csync_excluded_traversal_per_dir()
|
void check_csync_excluded_traversal_per_dir()
|
||||||
|
Loading…
Reference in New Issue
Block a user