File watcher: Pin state attribute changes are valid notifications
authorChristian Kamm <mail@ckamm.de>
Tue, 29 Jan 2019 10:41:03 +0000 (11:41 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:39 +0000 (10:58 +0100)
Previously they would be discarded since the file's mtime or size hadn't
changed.

src/common/syncjournalfilerecord.h
src/gui/folder.cpp

index 064334928b0638a11de9db34dd1ece41b2004a87..3a8643fe845af145b66ace83249bd63c4bc085fc 100644 (file)
@@ -53,6 +53,7 @@ public:
     QDateTime modDateTime() const { return Utility::qDateTimeFromTime_t(_modtime); }
 
     bool isDirectory() const { return _type == ItemTypeDirectory; }
+    bool isFile() const { return _type == ItemTypeFile || _type == ItemTypeVirtualFileDehydration; }
     bool isVirtualFile() const { return _type == ItemTypeVirtualFile || _type == ItemTypeVirtualFileDownload; }
 
     QByteArray _path;
index 916241778d40f2945cb58bc6272d03669fba8db8..c5bcbcd16be280f7878fac41d9aa004404ce0b9f 100644 (file)
@@ -560,11 +560,23 @@ void Folder::slotWatchedPathChanged(const QString &path)
     }
 #endif
 
-    // Check that the mtime actually changed.
+    // 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;
+        }
+    }
+    if (spurious) {
         qCInfo(lcFolder) << "Ignoring spurious notification for file" << relativePath;
         return; // probably a spurious notification
     }