From: Matthieu Gallien Date: Thu, 12 May 2022 07:56:50 +0000 (+0200) Subject: if an exclude file is deleted, skip it and remove it from internal list X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~15^2~208^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=5f6277b3ee70ac5668d8421486401524e3d5c364;p=nextcloud-desktop.git 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 --- diff --git a/src/csync/csync_exclude.cpp b/src/csync/csync_exclude.cpp index e367f37dd..4e9c9660d 100644 --- a/src/csync/csync_exclude.cpp +++ b/src/csync/csync_exclude.cpp @@ -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; } } diff --git a/test/testexcludedfiles.cpp b/test/testexcludedfiles.cpp index c044f5e59..22fbf1fa7 100644 --- a/test/testexcludedfiles.cpp +++ b/test/testexcludedfiles.cpp @@ -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); }