diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-08-21 16:36:46 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-08-26 12:12:02 +0200 |
commit | 34d055f69234475fa5e5eaaa9b4b0291f80a9913 (patch) | |
tree | a060373c9a9d80d57d3f878974f9bce7070e20b5 /src | |
parent | 9e93d20d40ee1501b23c42b945dbf7e10420ac43 (diff) | |
download | justbuild-34d055f69234475fa5e5eaaa9b4b0291f80a9913.tar.gz |
install-cas --archive: Fix empty directories not added to archive
Also add empty directory in test script to ensure we don't regress
in the future. While there, fix some typos.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/main/archive.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/buildtool/main/archive.cpp b/src/buildtool/main/archive.cpp index 92610397..08c6b9a9 100644 --- a/src/buildtool/main/archive.cpp +++ b/src/buildtool/main/archive.cpp @@ -52,8 +52,9 @@ auto add_to_archive(archive* archive, IExecutionApi const& api, const Artifact::ObjectInfo& artifact, const std::filesystem::path& location) -> bool { - auto constexpr kExecutable = 0555; - auto constexpr kFile = 0444; + auto constexpr kExecutablePerm = 0555; + auto constexpr kFilePerm = 0444; + auto constexpr kDefaultPerm = 07777; auto payload = api.RetrieveToMemory(artifact); if (not payload) { @@ -70,9 +71,10 @@ auto add_to_archive(archive* archive, archive_entry_set_pathname(entry.get(), location.string().c_str()); archive_entry_set_size(entry.get(), payload->size()); archive_entry_set_filetype(entry.get(), AE_IFREG); - archive_entry_set_perm( - entry.get(), - artifact.type == ObjectType::Executable ? kExecutable : kFile); + archive_entry_set_perm(entry.get(), + artifact.type == ObjectType::Executable + ? kExecutablePerm + : kFilePerm); archive_write_header(archive, entry.get()); auto data = *payload; archive_write_data(archive, data.c_str(), data.size()); @@ -81,11 +83,26 @@ auto add_to_archive(archive* archive, std::unique_ptr<archive_entry, decltype(&archive_entry_cleanup)> entry{archive_entry_new(), archive_entry_cleanup}; archive_entry_set_pathname(entry.get(), location.string().c_str()); + archive_entry_set_size(entry.get(), payload->size()); archive_entry_set_filetype(entry.get(), AE_IFLNK); archive_entry_set_symlink(entry.get(), payload->c_str()); + archive_entry_set_perm(entry.get(), kDefaultPerm); archive_write_header(archive, entry.get()); + auto data = *payload; + archive_write_data(archive, data.c_str(), data.size()); } break; case ObjectType::Tree: { + // avoid creating empty unnamed folder for the initial call + if (not location.empty()) { + std::unique_ptr<archive_entry, decltype(&archive_entry_cleanup)> + entry{archive_entry_new(), archive_entry_cleanup}; + archive_entry_set_pathname(entry.get(), + location.string().c_str()); + archive_entry_set_size(entry.get(), 0U); + archive_entry_set_filetype(entry.get(), AE_IFDIR); + archive_entry_set_perm(entry.get(), kDefaultPerm); + archive_write_header(archive, entry.get()); + } auto git_tree = GitRepo::ReadTreeData( *payload, artifact.digest.hash(), |