Get the excluded files test to pass again on Windows

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
This commit is contained in:
Kevin Ottens 2020-12-11 02:13:51 +01:00
Родитель c57eff6fd8
Коммит 0756497c3e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 074BBBCB8DECC9E2
2 изменённых файлов: 18 добавлений и 27 удалений

Просмотреть файл

@ -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()) {

Просмотреть файл

@ -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()