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;
// `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()) {
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()