diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-06-02 16:16:12 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-06-05 12:40:49 +0200 |
commit | 0039bf3dabf0068870e59acfa49683007d378c53 (patch) | |
tree | 724510e8f3db9206782b11358e53b41389a31784 /src/utils/cpp/file_locking.cpp | |
parent | 3a5da87b7185c49567da97cd829733f9bb653b44 (diff) | |
download | justbuild-0039bf3dabf0068870e59acfa49683007d378c53.tar.gz |
File Locking: only compute absolute path, if not absolute already
... and in this way, ensure we can lock files given by absolute
path even if we don't have a working directory. While there, drop
uncessary split just to combine of the file name.
Diffstat (limited to 'src/utils/cpp/file_locking.cpp')
-rw-r--r-- | src/utils/cpp/file_locking.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/utils/cpp/file_locking.cpp b/src/utils/cpp/file_locking.cpp index 3868af1b..c633b32b 100644 --- a/src/utils/cpp/file_locking.cpp +++ b/src/utils/cpp/file_locking.cpp @@ -80,15 +80,26 @@ auto LockFile::GetLockFilePath(std::filesystem::path const& fspath) noexcept -> std::optional<std::filesystem::path> { try { // bring to normal form - auto abs_fspath = ToNormalPath(std::filesystem::absolute(fspath)); - auto filename = abs_fspath.filename(); - auto parent = abs_fspath.parent_path(); + auto filename = ToNormalPath(fspath); + if (not filename.is_absolute()) { + try { + filename = std::filesystem::absolute(fspath); + } catch (std::exception const& e) { + Logger::Log(LogLevel::Error, + "Failed to determine absolute path for lock file " + "name {}: {}", + fspath.string(), + e.what()); + return std::nullopt; + } + } + auto parent = filename.parent_path(); // create parent folder if (not FileSystemManager::CreateDirectory(parent)) { return std::nullopt; } - // get lock file name - return parent / filename; + // return lock file name + return filename; } catch (std::exception const& ex) { Logger::Log( LogLevel::Error, |