diff --git a/src/csync/csync_exclude.cpp b/src/csync/csync_exclude.cpp index f531c2d15..eb0fdfb52 100644 --- a/src/csync/csync_exclude.cpp +++ b/src/csync/csync_exclude.cpp @@ -263,11 +263,6 @@ void ExcludedFiles::addManualExclude(const QString &expr) 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('/'))); 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 // written that way... this makes the tests happy for now. TODO Fix the tests at some point QString path = p; - if (path[0] == QLatin1Char('/')) - path = path.mid(1); + if (path.startsWith(_localPath)) + path = path.mid(_localPath.size()); QString basePath(_localPath + path); while (basePath.size() > _localPath.size()) { diff --git a/test/testexcludedfiles.cpp b/test/testexcludedfiles.cpp index c91b918fc..ba48e5c2c 100644 --- a/test/testexcludedfiles.cpp +++ b/test/testexcludedfiles.cpp @@ -234,45 +234,41 @@ private slots: 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->reloadExcludeFiles(); QCOMPARE(check_file_full("A"), CSYNC_FILE_EXCLUDE_LIST); excludedFiles->clearManualExcludes(); - excludedFiles->addManualExclude("A", "/B/"); + excludedFiles->addManualExclude("A", tempDir + "/B/"); excludedFiles->reloadExcludeFiles(); QCOMPARE(check_file_full("A"), CSYNC_NOT_EXCLUDED); QCOMPARE(check_file_full("B/A"), CSYNC_FILE_EXCLUDE_LIST); excludedFiles->clearManualExcludes(); - excludedFiles->addManualExclude("A/a1", "/B/"); + excludedFiles->addManualExclude("A/a1", tempDir + "/B/"); excludedFiles->reloadExcludeFiles(); QCOMPARE(check_file_full("A"), CSYNC_NOT_EXCLUDED); QCOMPARE(check_file_full("B/A/a1"), CSYNC_FILE_EXCLUDE_LIST); - #define FOO_DIR "/tmp/check_csync1/foo" - #define FOO_EXCLUDE_LIST FOO_DIR "/.sync-exclude.lst" - 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); + const auto fooDir = QStringLiteral("check_csync1/foo"); + QVERIFY(QDir(tempDir).mkpath(fooDir)); - 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(); - QCOMPARE(check_file_full(FOO_DIR), CSYNC_NOT_EXCLUDED); - QCOMPARE(check_file_full(FOO_DIR "/bar"), CSYNC_FILE_EXCLUDE_LIST); - QCOMPARE(check_file_full(FOO_DIR "/baz"), CSYNC_NOT_EXCLUDED); - #undef FOO_DIR - #undef FOO_EXCLUDE_LIST + QCOMPARE(check_file_full(QByteArray(fooDir.toUtf8() + "/bar")), CSYNC_FILE_EXCLUDE_LIST); + QCOMPARE(check_file_full(QByteArray(fooDir.toUtf8() + "/baz")), CSYNC_NOT_EXCLUDED); } void check_csync_excluded_traversal_per_dir()