From abdbeab309f5ae69a20cf2953c514a30450774ed Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 8 Aug 2023 15:25:45 +0200 Subject: 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. --- src/buildtool/main/install_cas.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') 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; -- cgit v1.2.3