From 24e7398e225fc288d0a299fc6cd77fcf1539835c Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Mon, 16 Jan 2023 16:55:41 +0100 Subject: just-mr fetch: fix overwriting distfiles Both, the python script as well as the compiled variant of just-mr fetch try to overwrite already existing distfiles in the distdir. While it is unclear if overwriting existing distfiles or not copying to distdir if a file with that name already exists is the better behaviour, we at least should not error out, as the compiled just-mr currently does as it sets permission to 444 and hence cannot overwrite later; fix this by addwing owner write permissions before overwriting. --- src/other_tools/ops_maps/repo_fetch_map.cpp | 30 +++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/other_tools/ops_maps/repo_fetch_map.cpp') diff --git a/src/other_tools/ops_maps/repo_fetch_map.cpp b/src/other_tools/ops_maps/repo_fetch_map.cpp index 274124a1..e0ff438e 100644 --- a/src/other_tools/ops_maps/repo_fetch_map.cpp +++ b/src/other_tools/ops_maps/repo_fetch_map.cpp @@ -51,13 +51,20 @@ auto CreateRepoFetchMap(gsl::not_null const& content_cas_map, auto content_path = casf.BlobPath(ArtifactDigest(content, 0, false)); if (content_path) { - if (not FileSystemManager::CopyFile( - *content_path, fetch_dir / distfile)) { + auto target_name = fetch_dir / distfile; + if (FileSystemManager::Exists(target_name)) { + std::filesystem::permissions( + target_name, + std::filesystem::perms::owner_write, + std::filesystem::perm_options::add); + } + if (not FileSystemManager::CopyFile(*content_path, + target_name)) { (*logger)(fmt::format( "Failed to copy content {} from CAS " - "into fetch directory {}", + "to {}", content, - fetch_dir.string()), + target_name.string()), /*fatal=*/true); return; } @@ -87,12 +94,19 @@ auto CreateRepoFetchMap(gsl::not_null const& content_cas_map, auto content_path = casf.BlobPath(ArtifactDigest(key.archive.content, 0, false)); if (content_path) { + auto target_name = fetch_dir / distfile; + if (FileSystemManager::Exists(target_name)) { + std::filesystem::permissions( + target_name, + std::filesystem::perms::owner_write, + std::filesystem::perm_options::add); + } if (not FileSystemManager::CopyFile(*content_path, - fetch_dir / distfile)) { + target_name)) { (*logger)(fmt::format("Failed to copy content {} from CAS " - "into fetch directory {}", + "to {}", key.archive.content, - fetch_dir.string()), + target_name.string()), /*fatal=*/true); return; } @@ -108,4 +122,4 @@ auto CreateRepoFetchMap(gsl::not_null const& content_cas_map, } }; return AsyncMapConsumer(fetch_repo, jobs); -} \ No newline at end of file +} -- cgit v1.2.3