summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2023-06-02 16:16:12 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2023-07-13 16:41:37 +0200
commit799a6dfcd9e39deee905a77267a3e635d97bedd8 (patch)
tree51fa25dc236d5e7920ca08a7c97bc9e9c14a3963 /src
parenta5c8d0fdecf52e94a7b6be44a0356272f133b557 (diff)
downloadjustbuild-799a6dfcd9e39deee905a77267a3e635d97bedd8.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. (cherry picked from 0039bf3dabf0068870e59acfa49683007d378c53)
Diffstat (limited to 'src')
-rw-r--r--src/utils/cpp/file_locking.cpp21
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,