if an exclude file is deleted, skip it and remove it from internal list

ignore files can be removed: not an error so adjust tests

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
This commit is contained in:
Matthieu Gallien 2022-05-12 09:56:50 +02:00 committed by Matthieu Gallien
parent 522d8024cd
commit 5f6277b3ee
2 changed files with 16 additions and 4 deletions

View File

@ -318,14 +318,26 @@ bool ExcludedFiles::reloadExcludeFiles()
bool success = true;
const auto keys = _excludeFiles.keys();
for (const auto& basePath : keys) {
for (const auto &excludeFile : _excludeFiles.value(basePath)) {
const auto itValue = _excludeFiles.find(basePath);
if (itValue == std::end(_excludeFiles)) {
continue;
}
auto &excludeFiles = *itValue;
for (auto excludeFileIt = std::begin(excludeFiles); excludeFileIt != std::end(excludeFiles); ) {
const auto &excludeFile = *excludeFileIt;
QFile file(excludeFile);
if (file.exists() && file.open(QIODevice::ReadOnly)) {
if (!file.exists()) {
excludeFileIt = excludeFiles.erase(excludeFileIt);
continue;
}
if (file.open(QIODevice::ReadOnly)) {
loadExcludeFilePatterns(basePath, file);
} else {
success = false;
qWarning() << "System exclude list file could not be opened:" << excludeFile;
}
++excludeFileIt;
}
}

View File

@ -746,11 +746,11 @@ private slots:
QCOMPARE(excludedFiles->_excludeFiles[folder2].first(), folder2ExcludeList);
}
void testReloadExcludeFiles_fileDoesNotExist_returnFalse() {
void testReloadExcludeFiles_fileDoesNotExist_returnTrue() {
excludedFiles.reset(new ExcludedFiles());
const QString nonExistingFile("directory/.sync-exclude.lst");
excludedFiles->addExcludeFilePath(nonExistingFile);
QCOMPARE(excludedFiles->reloadExcludeFiles(), false);
QCOMPARE(excludedFiles->reloadExcludeFiles(), true);
QCOMPARE(excludedFiles->_allExcludes.size(), 0);
}