From 65569e5486cf2e366328b0bad909444653deb2b6 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 18 Aug 2023 18:35:04 +0800 Subject: [PATCH] Emit lock file target file paths in lock file discovery from folder watcher Signed-off-by: Claudio Cambra --- src/gui/folderwatcher.cpp | 18 +++++++++--------- src/gui/folderwatcher.h | 6 +++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/gui/folderwatcher.cpp b/src/gui/folderwatcher.cpp index f971b7139..c56d00441 100644 --- a/src/gui/folderwatcher.cpp +++ b/src/gui/folderwatcher.cpp @@ -197,7 +197,6 @@ void FolderWatcher::changeDetected(const QStringList &paths) QSet changedPaths; QSet unlockedFiles; QSet lockedFiles; - QSet lockFiles; for (const auto &path : paths) { if (!_testNotificationPath.isEmpty() @@ -206,12 +205,13 @@ void FolderWatcher::changeDetected(const QStringList &paths) } const auto lockFileNamePattern = filePathLockFilePatternMatch(path); - const auto checkResult = checkIfFileIsLockOrUnlock(path,lockFileNamePattern); + const auto checkResult = lockFileTargetFilePath(path,lockFileNamePattern); if (_shouldWatchForFileUnlocking) { - if (checkResult.type == FileLockingInfo::Type::Unlocked && !checkResult.path.isEmpty()) { + // Lock file has been deleted, file now unlocked + if (checkResult.type == FileLockingInfo::Type::Unlocked && !checkResult.path.isEmpty() && !QFile::exists(path)) { unlockedFiles.insert(checkResult.path); - } else if (!lockFileNamePattern.isEmpty()) { - lockFiles.insert(path); + } else if (!checkResult.path.isEmpty() && QFile::exists(path)) { // Lock file found + lockedFiles.insert(checkResult.path); } } @@ -230,7 +230,7 @@ void FolderWatcher::changeDetected(const QStringList &paths) } qCDebug(lcFolderWatcher) << "Unlocked files:" << unlockedFiles.values(); - qCDebug(lcFolderWatcher) << "Lock files:" << lockFiles; + qCDebug(lcFolderWatcher) << "Locked files:" << lockedFiles; if (!unlockedFiles.isEmpty()) { emit filesLockReleased(unlockedFiles); @@ -240,8 +240,8 @@ void FolderWatcher::changeDetected(const QStringList &paths) emit filesLockImposed(lockedFiles); } - if (!lockFiles.isEmpty()) { - emit lockFilesFound(lockFiles); + if (!lockedFiles.isEmpty()) { + emit lockedFilesFound(lockedFiles); } if (changedPaths.isEmpty()) { @@ -259,7 +259,7 @@ void FolderWatcher::folderAccountCapabilitiesChanged() _shouldWatchForFileUnlocking = _folder->accountState()->account()->capabilities().filesLockAvailable(); } -FolderWatcher::FileLockingInfo FolderWatcher::checkIfFileIsLockOrUnlock(const QString &path, const QString &lockFileNamePattern) const +FolderWatcher::FileLockingInfo FolderWatcher::lockFileTargetFilePath(const QString &path, const QString &lockFileNamePattern) const { FileLockingInfo result; diff --git a/src/gui/folderwatcher.h b/src/gui/folderwatcher.h index 0cfd0bd80..4e2c569b9 100644 --- a/src/gui/folderwatcher.h +++ b/src/gui/folderwatcher.h @@ -104,6 +104,8 @@ signals: void lockFilesFound(const QSet &files); + void lockedFilesFound(const QSet &files); + /** * Emitted if some notifications were lost. * @@ -143,9 +145,11 @@ private: void appendSubPaths(QDir dir, QStringList& subPaths); - [[nodiscard]] FileLockingInfo checkIfFileIsLockOrUnlock(const QString &path, const QString &lockFileNamePattern) const; + [[nodiscard]] FileLockingInfo lockFileTargetFilePath(const QString &path, const QString &lockFileNamePattern) const; [[nodiscard]] QString findMatchingUnlockedFileInDir(const QString &dirPath, const QString &lockFileName) const; + QString findMatchingUnlockedFileInDir(const QString &dirPath, const QString &lockFileName); + /* Check if the path should be igored by the FolderWatcher. */ [[nodiscard]] bool pathIsIgnored(const QString &path) const; -- 2.30.2