From 686e6d869c936eace9b6983e7f61604dc9ab3acc Mon Sep 17 00:00:00 2001 From: alex-z Date: Fri, 12 Apr 2024 00:42:25 +0200 Subject: [PATCH] Fix locking not working caused by changes required for unit tests. Signed-off-by: alex-z --- src/libsync/filesystem.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp index cc3f59e47c2e5..ab48734a5423b 100644 --- a/src/libsync/filesystem.cpp +++ b/src/libsync/filesystem.cpp @@ -38,13 +38,20 @@ namespace constexpr std::array lockFilePatterns = {{".~lock.", "~$"}}; constexpr std::array officeFileExtensions = {"doc", "docx", "xls", "xlsx", "ppt", "pptx", "odt", "odp"}; // iterates through the dirPath to find the matching fileName -QString findMatchingUnlockedFileInDir(const QString &dirPath, const QString &fileName) +QString findMatchingUnlockedFileInDir(const QString &dirPath, const QString &lockFileName) { QString foundFilePath; const QDir dir(dirPath); const auto entryList = dir.entryInfoList(QDir::Files); for (const auto &candidateUnlockedFileInfo : entryList) { - if (candidateUnlockedFileInfo.fileName() == fileName) { + const auto candidateUnlockFileName = candidateUnlockedFileInfo.fileName(); + const auto lockFilePatternFoundIt = std::find_if(std::cbegin(lockFilePatterns), std::cend(lockFilePatterns), [&candidateUnlockFileName](std::string_view pattern) { + return candidateUnlockFileName.contains(QString::fromStdString(std::string(pattern))); + }); + if (lockFilePatternFoundIt != std::cend(lockFilePatterns)) { + continue; + } + if (candidateUnlockFileName.contains(lockFileName)) { foundFilePath = candidateUnlockedFileInfo.absoluteFilePath(); break; }