Notify when new lock files are found in folderwatcher
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Fri, 18 Aug 2023 09:04:11 +0000 (17:04 +0800)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 1 Sep 2023 15:15:44 +0000 (17:15 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/folderwatcher.cpp
src/gui/folderwatcher.h

index 3e93fa674153c8ffa0f133708e0a633aed1d4c31..f971b7139a78014d530726deea0cc6f80d5ddcb6 100644 (file)
@@ -197,6 +197,7 @@ void FolderWatcher::changeDetected(const QStringList &paths)
     QSet<QString> changedPaths;
     QSet<QString> unlockedFiles;
     QSet<QString> lockedFiles;
+    QSet<QString> lockFiles;
 
     for (const auto &path : paths) {
         if (!_testNotificationPath.isEmpty()
@@ -207,14 +208,11 @@ void FolderWatcher::changeDetected(const QStringList &paths)
         const auto lockFileNamePattern = filePathLockFilePatternMatch(path);
         const auto checkResult = checkIfFileIsLockOrUnlock(path,lockFileNamePattern);
         if (_shouldWatchForFileUnlocking) {
-            const auto lockFileNamePattern = filePathLockFilePatternMatch(path);
-            const auto unlockedFilePath = checkIfFileIsLockOrUnlock(path, lockFileNamePattern);
-
             if (checkResult.type == FileLockingInfo::Type::Unlocked && !checkResult.path.isEmpty()) {
                 unlockedFiles.insert(checkResult.path);
+            } else if (!lockFileNamePattern.isEmpty()) {
+                lockFiles.insert(path);
             }
-
-            qCDebug(lcFolderWatcher) << "Unlocked files:" << unlockedFiles.values();
         }
 
         if (checkResult.type == FileLockingInfo::Type::Locked && !checkResult.path.isEmpty()) {
@@ -231,6 +229,9 @@ void FolderWatcher::changeDetected(const QStringList &paths)
         changedPaths.insert(path);
     }
 
+    qCDebug(lcFolderWatcher) << "Unlocked files:" << unlockedFiles.values();
+    qCDebug(lcFolderWatcher) << "Lock files:" << lockFiles;
+
     if (!unlockedFiles.isEmpty()) {
         emit filesLockReleased(unlockedFiles);
     }
@@ -239,6 +240,10 @@ void FolderWatcher::changeDetected(const QStringList &paths)
         emit filesLockImposed(lockedFiles);
     }
 
+    if (!lockFiles.isEmpty()) {
+        emit lockFilesFound(lockFiles);
+    }
+
     if (changedPaths.isEmpty()) {
         return;
     }
index 41fd86ee1dbe64525d3dd7fb61e2eabe5fc775e5..0cfd0bd804a2bade72abc033fe12175b48b49c16 100644 (file)
@@ -102,6 +102,8 @@ signals:
      */
     void filesLockImposed(const QSet<QString> &files);
 
+    void lockFilesFound(const QSet<QString> &files);
+
     /**
      * Emitted if some notifications were lost.
      *