diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-08-08 15:25:45 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-08-08 16:47:57 +0200 |
commit | abdbeab309f5ae69a20cf2953c514a30450774ed (patch) | |
tree | 2440de2d511cef5cecfa3655b45636b590631112 | |
parent | 588b3d2e2828339f95cc332157dd35232da95ce9 (diff) | |
download | justbuild-abdbeab309f5ae69a20cf2953c514a30450774ed.tar.gz |
Unlink files before creation on install-cas
If install-cas finds a file in the target location, unlink it before
writing (in the same way as install does already). In this way, we
avoid changing other file locations in the presence of hard links.
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/buildtool/main/install_cas.cpp | 17 |
2 files changed, 17 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 97b2f730..17df375a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,8 @@ A feature release on top of `1.1.0`, backwards compatible. the local build root. - `just install-cas` now correctly handles `--raw-tree` also for remote-execution endpoints. +- `just install-cas` now, like `just install`, removes an existing + destination file before installing instead of overwriting. ## Release `1.1.0` (2023-05-19) diff --git a/src/buildtool/main/install_cas.cpp b/src/buildtool/main/install_cas.cpp index 1c0290df..99867de8 100644 --- a/src/buildtool/main/install_cas.cpp +++ b/src/buildtool/main/install_cas.cpp @@ -180,8 +180,21 @@ auto FetchAndInstallArtifacts( output_path /= object_info.digest.hash(); } - if (not FileSystemManager::CreateDirectory(output_path.parent_path()) or - not api->RetrieveToPaths( + if (not FileSystemManager::CreateDirectory(output_path.parent_path())) { + Logger::Log(LogLevel::Error, + "failed to create parent directory {}.", + output_path.parent_path().string()); + return false; + } + if (FileSystemManager::Exists(output_path)) { + if (not FileSystemManager::RemoveFile(output_path)) { + Logger::Log(LogLevel::Error, + "Failed to remote target location {}.", + output_path.string()); + return false; + } + } + if (not api->RetrieveToPaths( {object_info}, {output_path}, alternative_api)) { Logger::Log(LogLevel::Error, "failed to retrieve artifact."); return false; |