Don't ignore file sync notification after an unlock
authorHannah von Reth <hannah.vonreth@owncloud.com>
Mon, 16 Dec 2019 15:33:41 +0000 (16:33 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:05 +0000 (10:59 +0100)
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
src/gui/folder.h
src/gui/folderman.cpp

index b77abe387cf6b798faf7da129c158aff5f88de50..e513bce40bb81a46586485ec912e8d36cbfe5c9c 100644 (file)
@@ -536,7 +536,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;
@@ -567,27 +567,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;
+    _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);
@@ -1219,7 +1221,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,
index 92ad664ccb497f7c843dd5a6f9917d97fbcd0e40..0686b119b8ecf938df61572342e975ef9e7639fa 100644 (file)
@@ -107,6 +107,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> vfs, QObject *parent = nullptr);
@@ -330,7 +336,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.
index 0427fa99504dbb39810a365c0ac5daf191ab4ce0..081e6724c03d85527aaaca5abd0ab662b09c7406 100644 (file)
@@ -894,7 +894,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);
     }
 }