diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-01-16 16:55:41 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-01-16 17:47:29 +0100 |
commit | 24e7398e225fc288d0a299fc6cd77fcf1539835c (patch) | |
tree | d479ef9738b39163282f70234f7e396b7fae910e /src | |
parent | ddff40e1ad4869e21a35ff3e38fb23e06856b23f (diff) | |
download | justbuild-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')
-rw-r--r-- | src/other_tools/ops_maps/repo_fetch_map.cpp | 30 |
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 +} |