Skip to content

Commit

Permalink
Fix locking not working caused by changes required for unit tests.
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <[email protected]>
  • Loading branch information
allexzander committed Apr 13, 2024
1 parent c2fab31 commit 686e6d8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/libsync/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ namespace
constexpr std::array<const char *, 2> lockFilePatterns = {{".~lock.", "~$"}};
constexpr std::array<std::string_view, 8> 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)

Check warning on line 41 in src/libsync/filesystem.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/filesystem.cpp:41:9 [modernize-use-trailing-return-type]

use a trailing return type for this function

Check warning on line 41 in src/libsync/filesystem.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/filesystem.cpp:41:39 [bugprone-easily-swappable-parameters]

2 adjacent parameters of 'findMatchingUnlockedFileInDir' of similar type ('const int &') are easily swapped by mistake
{
QString foundFilePath;

Check warning on line 43 in src/libsync/filesystem.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/filesystem.cpp:43:13 [cppcoreguidelines-init-variables]

variable 'foundFilePath' is not initialized
const QDir dir(dirPath);

Check warning on line 44 in src/libsync/filesystem.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/filesystem.cpp:44:16 [cppcoreguidelines-init-variables]

variable 'dir' is not initialized
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;
}
Expand Down

0 comments on commit 686e6d8

Please sign in to comment.