From 583b54c367342ecb2fa92873b3565623df660433 Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Mon, 16 Dec 2019 16:33:41 +0100 Subject: [PATCH] Don't ignore file sync notification after an unlock For a usual file sync event we check for actual changes in the local file, after an unlock the local file might be unchanged so we need to sync it anyhow. Fixes: owncloud/enterprise#3609 --- src/gui/folder.cpp | 42 ++++++++++++++++++++++-------------------- src/gui/folder.h | 8 +++++++- src/gui/folderman.cpp | 2 +- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index afd6f6a339..f432ee5fd2 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -523,7 +523,7 @@ int Folder::slotWipeErrorBlacklist() return _journal.wipeErrorBlacklist(); } -void Folder::slotWatchedPathChanged(const QString &path) +void Folder::slotWatchedPathChanged(const QString &path, ChangeReason reason) { if (!path.startsWith(this->path())) { qCDebug(lcFolder) << "Changed path is not contained in folder, ignoring:" << path; @@ -554,27 +554,29 @@ void Folder::slotWatchedPathChanged(const QString &path) } #endif - // Check that the mtime/size actually changed or there was - // an attribute change (pin state) that caused the notification - bool spurious = false; - SyncJournalFileRecord record; - if (_journal.getFileRecord(relativePathBytes, &record) - && record.isValid() - && !FileSystem::fileChanged(path, record._fileSize, record._modtime)) { - spurious = true; - if (auto pinState = _vfs->pinState(relativePath.toString())) { - if (*pinState == PinState::AlwaysLocal && record.isVirtualFile()) - spurious = false; - if (*pinState == PinState::OnlineOnly && record.isFile()) - spurious = false; + SyncJournalFileRecord record; + _journal.getFileRecord(relativePathBytes, &record); + if (reason != ChangeReason::UnLock) { + // Check that the mtime/size actually changed or there was + // an attribute change (pin state) that caused the notification + bool spurious = false; + if (record.isValid() + && !FileSystem::fileChanged(path, record._fileSize, record._modtime)) { + spurious = true; + + if (auto pinState = _vfs->pinState(relativePath.toString())) { + if (*pinState == PinState::AlwaysLocal && record.isVirtualFile()) + spurious = false; + if (*pinState == PinState::OnlineOnly && record.isFile()) + spurious = false; + } + } + if (spurious) { + qCInfo(lcFolder) << "Ignoring spurious notification for file" << relativePath; + return; // probably a spurious notification } } - if (spurious) { - qCInfo(lcFolder) << "Ignoring spurious notification for file" << relativePath; - return; // probably a spurious notification - } - warnOnNewExcludedItem(record, relativePath); emit watchedFileChangedExternally(path); @@ -1184,7 +1186,7 @@ void Folder::registerFolderWatcher() _folderWatcher.reset(new FolderWatcher(this)); connect(_folderWatcher.data(), &FolderWatcher::pathChanged, - this, &Folder::slotWatchedPathChanged); + this, [this](const QString &path) { slotWatchedPathChanged(path, Folder::ChangeReason::Other); }); connect(_folderWatcher.data(), &FolderWatcher::lostChanges, this, &Folder::slotNextSyncFullLocalDiscovery); connect(_folderWatcher.data(), &FolderWatcher::becameUnreliable, diff --git a/src/gui/folder.h b/src/gui/folder.h index a29eddd5f8..a5adfe00ab 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -113,6 +113,12 @@ class Folder : public QObject Q_OBJECT public: + enum class ChangeReason { + Other, + UnLock + }; + Q_ENUM(ChangeReason) + /** Create a new Folder */ Folder(const FolderDefinition &definition, AccountState *accountState, std::unique_ptr vfs, QObject *parent = 0L); @@ -336,7 +342,7 @@ public slots: * changes. Needs to check whether this change should trigger a new * sync run to be scheduled. */ - void slotWatchedPathChanged(const QString &path); + void slotWatchedPathChanged(const QString &path, ChangeReason reason); /** * Mark a virtual file as being requested for download, and start a sync. diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index b9fc76629c..27f96eac79 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -864,7 +864,7 @@ void FolderMan::slotWatchedFileUnlocked(const QString &path) { if (Folder *f = folderForPath(path)) { // Treat this equivalently to the file being reported by the file watcher - f->slotWatchedPathChanged(path); + f->slotWatchedPathChanged(path, Folder::ChangeReason::UnLock); } }