summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2023-08-08 15:25:45 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2023-08-08 16:47:57 +0200
commitabdbeab309f5ae69a20cf2953c514a30450774ed (patch)
tree2440de2d511cef5cecfa3655b45636b590631112 /src
parent588b3d2e2828339f95cc332157dd35232da95ce9 (diff)
downloadjustbuild-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.
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/main/install_cas.cpp17
1 files changed, 15 insertions, 2 deletions
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;