Return LockResult::ErrorWrite in LockDirectory

This allows the caller to remove a call to DirIsWritable(), which did a
similar check. Users should not notice any different behavior.
This commit is contained in:
MarcoFalke
2023-07-14 12:24:16 +02:00
parent fa0afe7408
commit fad3a9793b
4 changed files with 17 additions and 7 deletions

View File

@@ -65,8 +65,11 @@ LockResult LockDirectory(const fs::path& directory, const fs::path& lockfile_nam
}
// Create empty lock file if it doesn't exist.
FILE* file = fsbridge::fopen(pathLockFile, "a");
if (file) fclose(file);
if (auto created{fsbridge::fopen(pathLockFile, "a")}) {
std::fclose(created);
} else {
return LockResult::ErrorWrite;
}
auto lock = std::make_unique<fsbridge::FileLock>(pathLockFile);
if (!lock->TryLock()) {
error("Error while attempting to lock directory %s: %s", fs::PathToString(directory), lock->GetReason());