diff options
author | Camila <hello@camila.codes> | 2020-12-09 18:59:10 +0300 |
---|---|---|
committer | Camila <hello@camila.codes> | 2021-10-28 12:37:56 +0300 |
commit | 5788f35e82359356476c18673ffe2fa23f1cb7b5 (patch) | |
tree | fe8598b27e378d917710bcb2ead2df269e6027bf /src/csync | |
parent | 5d08936e378fa105ddc5b8ea1d08a984c522e3aa (diff) |
Skip sync exclude file from list of exclude files if it doesn't exist.
The file might not exist anymore because the user deleted it by hand or
the folder where it was located got unchecked in the selective sync
view. It is a fix for #2632.
Signed-off-by: Camila <hello@camila.codes>
Diffstat (limited to 'src/csync')
-rw-r--r-- | src/csync/csync_exclude.cpp | 52 | ||||
-rw-r--r-- | src/csync/csync_exclude.h | 4 |
2 files changed, 28 insertions, 28 deletions
diff --git a/src/csync/csync_exclude.cpp b/src/csync/csync_exclude.cpp index c15fc5e01..eb8507589 100644 --- a/src/csync/csync_exclude.cpp +++ b/src/csync/csync_exclude.cpp @@ -35,10 +35,8 @@ #include <QString> #include <QFileInfo> -#include <QFile> #include <QDir> - /** Expands C-like escape sequences (in place) */ OCSYNC_EXPORT void csync_exclude_expand_escapes(QByteArray &input) @@ -238,18 +236,17 @@ ExcludedFiles::~ExcludedFiles() = default; void ExcludedFiles::addExcludeFilePath(const QString &path) { - auto &excludeFilesLocalPath = _excludeFiles[_localPath]; + const QFileInfo excludeFileInfo(path); + const auto fileName = excludeFileInfo.fileName(); + const auto basePath = fileName.compare(QStringLiteral("sync-exclude.lst"), Qt::CaseInsensitive) == 0 + ? _localPath + : leftIncludeLast(path, QLatin1Char('/')); + auto &excludeFilesLocalPath = _excludeFiles[basePath]; if (std::find(excludeFilesLocalPath.cbegin(), excludeFilesLocalPath.cend(), path) == excludeFilesLocalPath.cend()) { excludeFilesLocalPath.append(path); } } -void ExcludedFiles::addInTreeExcludeFilePath(const QString &path) -{ - BasePathString basePath = leftIncludeLast(path, QLatin1Char('/')); - _excludeFiles[basePath].append(path); -} - void ExcludedFiles::setExcludeConflictFiles(bool onoff) { _excludeConflictFiles = onoff; @@ -287,32 +284,26 @@ void ExcludedFiles::setClientVersion(ExcludedFiles::Version version) _clientVersion = version; } -bool ExcludedFiles::loadExcludeFile(const QString &basePath, const QString & file) +void ExcludedFiles::loadExcludeFilePatterns(const QString &basePath, QFile &file) { - QFile f(file); - if (!f.open(QIODevice::ReadOnly)) - return false; - QStringList patterns; - while (!f.atEnd()) { - QByteArray line = f.readLine().trimmed(); + while (!file.atEnd()) { + QByteArray line = file.readLine().trimmed(); if (line.startsWith("#!version")) { if (!versionDirectiveKeepNextLine(line)) - f.readLine(); + file.readLine(); } if (line.isEmpty() || line.startsWith('#')) continue; csync_exclude_expand_escapes(line); patterns.append(QString::fromUtf8(line)); } - _allExcludes.insert(basePath, patterns); + _allExcludes[basePath].append(patterns); // nothing to prepare if the user decided to not exclude anything if (!_allExcludes.value(basePath).isEmpty()){ prepare(basePath); } - - return true; } bool ExcludedFiles::reloadExcludeFiles() @@ -329,8 +320,14 @@ bool ExcludedFiles::reloadExcludeFiles() bool success = true; const auto keys = _excludeFiles.keys(); for (const auto& basePath : keys) { - for (const auto& file : _excludeFiles.value(basePath)) { - success = loadExcludeFile(basePath, file); + for (const auto &excludeFile : _excludeFiles.value(basePath)) { + QFile file(excludeFile); + if (file.exists() && file.open(QIODevice::ReadOnly)) { + loadExcludeFilePatterns(basePath, file); + } else { + success = false; + qWarning() << "System exclude list file could not be opened:" << excludeFile; + } } } @@ -421,11 +418,14 @@ CSYNC_EXCLUDE_TYPE ExcludedFiles::traversalPatternMatch(const QString &path, Ite // Directories are guaranteed to be visited before their files if (filetype == ItemTypeDirectory) { const auto basePath = QString(_localPath + path + QLatin1Char('/')); - const auto fi = QFileInfo(basePath + QStringLiteral(".sync-exclude.lst")); + const QString absolutePath = basePath + QStringLiteral(".sync-exclude.lst"); + QFileInfo excludeFileInfo(absolutePath); - if (fi.isReadable()) { - addInTreeExcludeFilePath(fi.absoluteFilePath()); - loadExcludeFile(basePath, fi.absoluteFilePath()); + if (excludeFileInfo.isReadable()) { + addExcludeFilePath(absolutePath); + reloadExcludeFiles(); + } else { + qWarning() << "System exclude list file could not be read:" << absolutePath; } } diff --git a/src/csync/csync_exclude.h b/src/csync/csync_exclude.h index cc4de9923..856ac67ef 100644 --- a/src/csync/csync_exclude.h +++ b/src/csync/csync_exclude.h @@ -48,6 +48,7 @@ enum CSYNC_EXCLUDE_TYPE { }; class ExcludedFilesTest; +class QFile; /** * Manages file/directory exclusion. @@ -77,7 +78,6 @@ public: * Does not load the file. Use reloadExcludeFiles() afterwards. */ void addExcludeFilePath(const QString &path); - void addInTreeExcludeFilePath(const QString &path); /** * Whether conflict files shall be excluded. @@ -148,7 +148,7 @@ public slots: /** * Loads the exclude patterns from file the registered base paths. */ - bool loadExcludeFile(const QString &basePath, const QString &file); + void loadExcludeFilePatterns(const QString &basePath, QFile &file); private: /** |