summaryrefslogtreecommitdiff
path: root/src/other_tools/ops_maps/repo_fetch_map.cpp
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2023-01-16 16:55:41 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2023-01-16 17:47:29 +0100
commit24e7398e225fc288d0a299fc6cd77fcf1539835c (patch)
treed479ef9738b39163282f70234f7e396b7fae910e /src/other_tools/ops_maps/repo_fetch_map.cpp
parentddff40e1ad4869e21a35ff3e38fb23e06856b23f (diff)
downloadjustbuild-24e7398e225fc288d0a299fc6cd77fcf1539835c.tar.gz
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.
Diffstat (limited to 'src/other_tools/ops_maps/repo_fetch_map.cpp')
-rw-r--r--src/other_tools/ops_maps/repo_fetch_map.cpp30
1 files changed, 22 insertions, 8 deletions
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<ContentCASMap*> 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<ContentCASMap*> 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<ContentCASMap*> const& content_cas_map,
}
};
return AsyncMapConsumer<ArchiveRepoInfo, bool>(fetch_repo, jobs);
-} \ No newline at end of file
+}