Get the excluded files test to pass again on Windows
authorKevin Ottens <kevin.ottens@nextcloud.com>
Fri, 11 Dec 2020 01:13:51 +0000 (02:13 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 10:01:53 +0000 (11:01 +0100)
Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/csync/csync_exclude.cpp
test/testexcludedfiles.cpp

index f531c2d15f9f127b03555c355f0e7aa5eaa684c1..eb0fdfb527cf7e1810bc86df21e4bb3aef45294c 100644 (file)
@@ -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()) {
index c91b918fcfb3808a10aff31ea8513e24fa68074c..ba48e5c2c8136031144313b36b3ea9bbd018d285 100644 (file)
@@ -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);
-
-        excludedFiles->addInTreeExcludeFilePath(FOO_EXCLUDE_LIST);
+        const auto fooDir = QStringLiteral("check_csync1/foo");
+        QVERIFY(QDir(tempDir).mkpath(fooDir));
+
+        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()