Do not search for matching file pattern in possiblyAddUnlockedFilePath
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Fri, 18 Aug 2023 09:02:16 +0000 (17:02 +0800)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 1 Sep 2023 15:15:43 +0000 (17:15 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/folderwatcher.cpp
src/gui/folderwatcher.h

index 74f716a7cf01145733f69ea85f7cf13265542987..3e93fa674153c8ffa0f133708e0a633aed1d4c31 100644 (file)
@@ -203,9 +203,13 @@ void FolderWatcher::changeDetected(const QStringList &paths)
             && Utility::fileNamesEqual(path, _testNotificationPath)) {
             _testNotificationPath.clear();
         }
-        
-        const auto checkResult = checkIfFileIsLockOrUnlock(path);
+
+        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);
             }
@@ -250,16 +254,15 @@ void FolderWatcher::folderAccountCapabilitiesChanged()
     _shouldWatchForFileUnlocking = _folder->accountState()->account()->capabilities().filesLockAvailable();
 }
 
-FolderWatcher::FileLockingInfo FolderWatcher::checkIfFileIsLockOrUnlock(const QString &path) const
+FolderWatcher::FileLockingInfo FolderWatcher::checkIfFileIsLockOrUnlock(const QString &path, const QString &lockFileNamePattern) const
 {
     FileLockingInfo result;
-    const auto lockFilePatternFound = filePathLockFilePatternMatch(path);
 
-    if (lockFilePatternFound.isEmpty()) {
+    if (lockFileNamePattern.isEmpty()) {
         return result;
     }
 
-    const auto lockFilePathWithoutPrefix = QString(path).replace(lockFilePatternFound, QStringLiteral(""));
+    const auto lockFilePathWithoutPrefix = QString(path).replace(lockFileNamePattern, QStringLiteral(""));
     auto lockFilePathWithoutPrefixSplit = lockFilePathWithoutPrefix.split(QLatin1Char('.'));
 
     if (lockFilePathWithoutPrefixSplit.size() < 2) {
index f2d59f703d6dd074c5b0e0f0b3669253da662b3e..41fd86ee1dbe64525d3dd7fb61e2eabe5fc775e5 100644 (file)
@@ -141,7 +141,7 @@ private:
 
     void appendSubPaths(QDir dir, QStringList& subPaths);
 
-    [[nodiscard]] FileLockingInfo checkIfFileIsLockOrUnlock(const QString &path) const;
+    [[nodiscard]] FileLockingInfo checkIfFileIsLockOrUnlock(const QString &path, const QString &lockFileNamePattern) const;
     [[nodiscard]] QString findMatchingUnlockedFileInDir(const QString &dirPath, const QString &lockFileName) const;
 
     /* Check if the path should be igored by the FolderWatcher. */