mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-25 22:46:04 +03:00
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>
This commit is contained in:
parent
5d08936e37
commit
5788f35e82
3 changed files with 29 additions and 29 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
/**
|
||||
|
|
|
@ -265,7 +265,7 @@ private slots:
|
|||
QCOMPARE(excludeList.write("bar"), 3);
|
||||
excludeList.close();
|
||||
|
||||
excludedFiles->addInTreeExcludeFilePath(fooExcludeList);
|
||||
excludedFiles->addExcludeFilePath(fooExcludeList);
|
||||
excludedFiles->reloadExcludeFiles();
|
||||
QCOMPARE(check_file_full(QByteArray(fooDir.toUtf8() + "/bar")), CSYNC_FILE_EXCLUDE_LIST);
|
||||
QCOMPARE(check_file_full(QByteArray(fooDir.toUtf8() + "/baz")), CSYNC_NOT_EXCLUDED);
|
||||
|
|
Loading…
Reference in a new issue