diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-11 12:19:15 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-11 14:52:07 +0200 |
commit | 09a400e7a6ae4882ef770bf7eba3887050601ee8 (patch) | |
tree | 2d54d6ff3985619d47ce8ae423853afc51f4ca3f /src | |
parent | c34e0b72616c99a4704efc3950351c84487903ca (diff) | |
download | justbuild-09a400e7a6ae4882ef770bf7eba3887050601ee8.tar.gz |
Store HashInfo in just-mr's ArchiveContent as content hash
...and use it to create ArtifactDigests.
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/ops_maps/TARGETS | 2 | ||||
-rw-r--r-- | src/other_tools/ops_maps/archive_fetch_map.cpp | 31 | ||||
-rw-r--r-- | src/other_tools/ops_maps/archive_fetch_map.hpp | 6 | ||||
-rw-r--r-- | src/other_tools/ops_maps/content_cas_map.cpp | 27 | ||||
-rw-r--r-- | src/other_tools/ops_maps/content_cas_map.hpp | 7 | ||||
-rw-r--r-- | src/other_tools/repo_map/TARGETS | 1 | ||||
-rw-r--r-- | src/other_tools/repo_map/repos_to_setup_map.cpp | 7 | ||||
-rw-r--r-- | src/other_tools/root_maps/TARGETS | 2 | ||||
-rw-r--r-- | src/other_tools/root_maps/content_git_map.cpp | 88 | ||||
-rw-r--r-- | src/other_tools/root_maps/foreign_file_git_map.cpp | 35 | ||||
-rw-r--r-- | src/other_tools/utils/TARGETS | 3 | ||||
-rw-r--r-- | src/other_tools/utils/parse_archive.cpp | 15 |
12 files changed, 133 insertions, 91 deletions
diff --git a/src/other_tools/ops_maps/TARGETS b/src/other_tools/ops_maps/TARGETS index 548db656..0b7ac74f 100644 --- a/src/other_tools/ops_maps/TARGETS +++ b/src/other_tools/ops_maps/TARGETS @@ -72,6 +72,7 @@ , ["src/buildtool/serve_api/remote", "serve_api"] , ["src/buildtool/storage", "config"] , ["src/buildtool/storage", "storage"] + , ["src/buildtool/crypto", "hash_info"] ] , "stage": ["src", "other_tools", "ops_maps"] , "private-deps": @@ -93,6 +94,7 @@ , ["src/buildtool/execution_api/common", "common"] , ["src/buildtool/storage", "storage"] , ["src/other_tools/just_mr/progress_reporting", "statistics"] + , ["src/buildtool/crypto", "hash_info"] ] , "stage": ["src", "other_tools", "ops_maps"] , "private-deps": diff --git a/src/other_tools/ops_maps/archive_fetch_map.cpp b/src/other_tools/ops_maps/archive_fetch_map.cpp index 17b33092..91d71ce6 100644 --- a/src/other_tools/ops_maps/archive_fetch_map.cpp +++ b/src/other_tools/ops_maps/archive_fetch_map.cpp @@ -27,21 +27,20 @@ void ProcessContent(std::filesystem::path const& content_path, std::filesystem::path const& target_name, gsl::not_null<IExecutionApi const*> const& local_api, IExecutionApi const* remote_api, - std::string const& content, + ArtifactDigest const& content_digest, gsl::not_null<JustMRStatistics*> const& stats, ArchiveFetchMap::SetterPtr const& setter, ArchiveFetchMap::LoggerPtr const& logger) { // try to back up to remote CAS if (remote_api != nullptr) { if (not local_api->RetrieveToCas( - {Artifact::ObjectInfo{ - .digest = ArtifactDigest{content, 0, /*is_tree=*/false}, - .type = ObjectType::File}}, + {Artifact::ObjectInfo{.digest = content_digest, + .type = ObjectType::File}}, *remote_api)) { // give a warning (*logger)(fmt::format("Failed to back up content {} from local CAS " "to remote", - content), + content_digest.hash()), /*fatal=*/false); } } @@ -53,7 +52,7 @@ void ProcessContent(std::filesystem::path const& content_path, } if (not FileSystemManager::CopyFile(content_path, target_name)) { (*logger)(fmt::format("Failed to copy content {} from CAS to {}", - content, + content_digest.hash(), target_name.string()), /*fatal=*/true); return; @@ -96,30 +95,30 @@ auto CreateArchiveFetchMap(gsl::not_null<ContentCASMap*> const& content_cas_map, storage, local_api, remote_api, - content = key.content, + hash_info = key.content_hash, stats, setter, logger]([[maybe_unused]] auto const& values) { // content is in local CAS now auto const& cas = storage->CAS(); - auto content_path = - cas.BlobPath(ArtifactDigest{content, 0, /*is_tree=*/false}, - /*is_executable=*/false) - .value(); + ArtifactDigest const digest{hash_info, 0}; + auto content_path = cas.BlobPath(digest, + /*is_executable=*/false) + .value(); ProcessContent(content_path, target_name, local_api, remote_api, - content, + digest, stats, setter, logger); }, - [logger, content = key.content](auto const& msg, bool fatal) { + [logger, hash = key.content_hash.Hash()](auto const& msg, + bool fatal) { (*logger)( - fmt::format("While ensuring content {} is in CAS:\n{}", - content, - msg), + fmt::format( + "While ensuring content {} is in CAS:\n{}", hash, msg), fatal); }); }; diff --git a/src/other_tools/ops_maps/archive_fetch_map.hpp b/src/other_tools/ops_maps/archive_fetch_map.hpp index 3c4ed82c..e1c26b45 100644 --- a/src/other_tools/ops_maps/archive_fetch_map.hpp +++ b/src/other_tools/ops_maps/archive_fetch_map.hpp @@ -22,6 +22,7 @@ #include <string> #include "gsl/gsl" +#include "src/buildtool/crypto/hash_info.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/storage/storage.hpp" #include "src/other_tools/just_mr/progress_reporting/statistics.hpp" @@ -41,7 +42,8 @@ using ArchiveFetchMap = AsyncMapConsumer<ArchiveContent, bool>; // use explicit cast to std::function to allow template deduction when used static const std::function<std::string(ArchiveContent const&)> - kArchiveContentPrinter = - [](ArchiveContent const& x) -> std::string { return x.content; }; + kArchiveContentPrinter = [](ArchiveContent const& x) -> std::string { + return x.content_hash.Hash(); +}; #endif // INCLUDED_SRC_OTHER_TOOLS_OPS_MAPS_ARCHIVE_FETCH_MAP_HPP diff --git a/src/other_tools/ops_maps/content_cas_map.cpp b/src/other_tools/ops_maps/content_cas_map.cpp index 95518326..0e13cd8e 100644 --- a/src/other_tools/ops_maps/content_cas_map.cpp +++ b/src/other_tools/ops_maps/content_cas_map.cpp @@ -44,7 +44,7 @@ void FetchFromNetwork(ArchiveContent const& key, if (not data) { (*logger)(fmt::format("Failed to fetch a file with id {} from provided " "remotes:{}", - key.content, + key.content_hash.Hash(), data.error()), /*fatal=*/true); return; @@ -83,11 +83,11 @@ void FetchFromNetwork(ArchiveContent const& key, } // check that the data we stored actually produces the requested digest auto const& cas = storage.CAS(); - if (not cas.BlobPath(ArtifactDigest{key.content, 0, /*is_tree=*/false}, + if (not cas.BlobPath(ArtifactDigest{key.content_hash, 0}, /*is_executable=*/false)) { (*logger)( fmt::format("Content {} was not found at given fetch location {}", - key.content, + key.content_hash.Hash(), key.fetch_url), /*fatal=*/true); return; @@ -125,7 +125,7 @@ auto CreateContentCASMap( auto logger, auto /*unused*/, auto const& key) { - auto digest = ArtifactDigest(key.content, 0, false); + auto const digest = ArtifactDigest{key.content_hash, 0}; // check local CAS if (local_api->IsAvailable(digest)) { (*setter)(nullptr); @@ -175,15 +175,16 @@ auto CreateContentCASMap( } // verify if local Git knows content blob auto wrapped_logger = std::make_shared<AsyncMapConsumerLogger>( - [&logger, blob = key.content](auto const& msg, bool fatal) { + [&logger, hash = key.content_hash.Hash()](auto const& msg, + bool fatal) { (*logger)(fmt::format("While verifying presence of " "blob {}:\n{}", - blob, + hash, msg), fatal); }); - auto res = - just_git_repo->TryReadBlob(key.content, wrapped_logger); + auto res = just_git_repo->TryReadBlob(key.content_hash.Hash(), + wrapped_logger); if (not res.first) { // blob check failed return; @@ -195,7 +196,7 @@ auto CreateContentCASMap( /*is_executable=*/false)) { (*logger)(fmt::format("Failed to store content {} " "to local CAS", - key.content), + key.content_hash.Hash()), /*fatal=*/true); return; } @@ -214,8 +215,8 @@ auto CreateContentCASMap( std::make_shared<AsyncMapConsumerLogger>( [](auto /*unused*/, auto /*unused*/) {}); if (old_repo) { - auto res = - old_repo->TryReadBlob(key.content, no_logging); + auto res = old_repo->TryReadBlob( + key.content_hash.Hash(), no_logging); if (res.first and res.second) { // read blob from older generation auto const& cas = storage->CAS(); @@ -224,7 +225,7 @@ auto CreateContentCASMap( (*logger)(fmt::format( "Failed to store content {} " "to local CAS", - key.content), + key.content_hash.Hash()), /*fatal=*/true); } // content stored in CAS @@ -253,7 +254,7 @@ auto CreateContentCASMap( } // check if content is known to remote serve service if (serve != nullptr and remote_api != nullptr and - serve->ContentInRemoteCAS(key.content)) { + serve->ContentInRemoteCAS(key.content_hash.Hash())) { // try to get content from remote CAS if (remote_api->RetrieveToCas( {Artifact::ObjectInfo{.digest = digest, diff --git a/src/other_tools/ops_maps/content_cas_map.hpp b/src/other_tools/ops_maps/content_cas_map.hpp index ccfb6dad..69f10dbc 100644 --- a/src/other_tools/ops_maps/content_cas_map.hpp +++ b/src/other_tools/ops_maps/content_cas_map.hpp @@ -22,6 +22,7 @@ #include "gsl/gsl" #include "src/buildtool/common/user_structs.hpp" +#include "src/buildtool/crypto/hash_info.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/file_system/symlinks_map/pragma_special.hpp" #include "src/buildtool/multithreading/async_map_consumer.hpp" @@ -34,7 +35,7 @@ #include "src/utils/cpp/hash_combine.hpp" struct ArchiveContent { - std::string content{}; /* key */ + HashInfo content_hash{}; /* key */ std::optional<std::string> distfile{std::nullopt}; std::string fetch_url{}; std::vector<std::string> mirrors{}; @@ -44,7 +45,7 @@ struct ArchiveContent { std::string origin{}; [[nodiscard]] auto operator==(const ArchiveContent& other) const -> bool { - return content == other.content; + return content_hash.Hash() == other.content_hash.Hash(); } }; @@ -100,7 +101,7 @@ template <> struct hash<ArchiveContent> { [[nodiscard]] auto operator()(const ArchiveContent& ct) const noexcept -> std::size_t { - return std::hash<std::string>{}(ct.content); + return std::hash<std::string>{}(ct.content_hash.Hash()); } }; diff --git a/src/other_tools/repo_map/TARGETS b/src/other_tools/repo_map/TARGETS index dd938a5b..9f75dc93 100644 --- a/src/other_tools/repo_map/TARGETS +++ b/src/other_tools/repo_map/TARGETS @@ -27,6 +27,7 @@ , ["src/other_tools/utils", "parse_archive"] , ["src/other_tools/utils", "parse_git_tree"] , ["src/buildtool/crypto", "hash_function"] + , ["src/buildtool/crypto", "hash_info"] ] } } diff --git a/src/other_tools/repo_map/repos_to_setup_map.cpp b/src/other_tools/repo_map/repos_to_setup_map.cpp index 02ee6311..cd0849fb 100644 --- a/src/other_tools/repo_map/repos_to_setup_map.cpp +++ b/src/other_tools/repo_map/repos_to_setup_map.cpp @@ -19,6 +19,7 @@ #include "fmt/core.h" #include "src/buildtool/crypto/hash_function.hpp" +#include "src/buildtool/crypto/hash_info.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/file_system/symlinks_map/pragma_special.hpp" #include "src/buildtool/logging/log_level.hpp" @@ -514,8 +515,10 @@ void DistdirCheckout(ExpressionPtr const& repo_desc, .filename() .string()); distdir_content_for_id->insert_or_assign( - repo_distfile, std::make_pair(archive->content, false)); - distdir_content->insert_or_assign(repo_distfile, archive->content); + repo_distfile, + std::make_pair(archive->content_hash.Hash(), false)); + distdir_content->insert_or_assign(repo_distfile, + archive->content_hash.Hash()); // add to fetch list dist_repos_to_fetch->emplace_back(*std::move(archive)); } diff --git a/src/other_tools/root_maps/TARGETS b/src/other_tools/root_maps/TARGETS index 49e1ee60..92c606e7 100644 --- a/src/other_tools/root_maps/TARGETS +++ b/src/other_tools/root_maps/TARGETS @@ -126,6 +126,7 @@ , ["src/other_tools/git_operations", "git_repo_remote"] , ["src/other_tools/utils", "content"] , ["src/utils/archive", "archive_ops"] + , ["src/buildtool/crypto", "hash_info"] ] } , "foreign_file_git_map": @@ -149,6 +150,7 @@ , ["src/buildtool/storage", "fs_utils"] , ["src/utils/cpp", "tmp_dir"] , "root_utils" + , ["src/buildtool/crypto", "hash_info"] ] , "stage": ["src", "other_tools", "root_maps"] } diff --git a/src/other_tools/root_maps/content_git_map.cpp b/src/other_tools/root_maps/content_git_map.cpp index d39a70e5..43222763 100644 --- a/src/other_tools/root_maps/content_git_map.cpp +++ b/src/other_tools/root_maps/content_git_map.cpp @@ -15,6 +15,7 @@ #include "src/other_tools/root_maps/content_git_map.hpp" #include "fmt/core.h" +#include "src/buildtool/crypto/hash_info.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/file_system/file_storage.hpp" #include "src/buildtool/file_system/symlinks_map/pragma_special.hpp" @@ -67,12 +68,12 @@ void EnsureRootAsAbsent( // try to see if serve endpoint has the information to prepare the // root itself; this is redundant if root is not already cached if (is_cache_hit) { - auto serve_result = - serve->RetrieveTreeFromArchive(key.archive.content, - key.repo_type, - key.subdir, - key.pragma_special, - /*sync_tree=*/false); + auto serve_result = serve->RetrieveTreeFromArchive( + key.archive.content_hash.Hash(), + key.repo_type, + key.subdir, + key.pragma_special, + /*sync_tree=*/false); if (serve_result) { // if serve has set up the tree, it must match what we // expect @@ -93,7 +94,7 @@ void EnsureRootAsAbsent( (*logger)( fmt::format("Serve endpoint failed to set up " "root from known archive content {}", - key.archive.content), + key.archive.content_hash.Hash()), /*fatal=*/true); return; } @@ -303,11 +304,11 @@ void ResolveContentTree( fatal); }); }, - [logger, content = key.archive.content](auto const& msg, - bool fatal) { + [logger, hash = key.archive.content_hash.Hash()]( + auto const& msg, bool fatal) { (*logger)(fmt::format("While resolving symlinks for " "content {}:\n{}", - content, + hash, msg), fatal); }); @@ -421,7 +422,7 @@ void ExtractAndImportToGit( if (not tmp_dir) { (*logger)(fmt::format("Failed to create tmp path for {} target {}", key.repo_type, - key.archive.content), + key.archive.content_hash.Hash()), /*fatal=*/true); return; } @@ -436,7 +437,8 @@ void ExtractAndImportToGit( return; } // import to git - CommitInfo c_info{tmp_dir->GetPath(), key.repo_type, key.archive.content}; + CommitInfo c_info{ + tmp_dir->GetPath(), key.repo_type, key.archive.content_hash.Hash()}; import_to_git_map->ConsumeAfterKeysReady( ts, {std::move(c_info)}, @@ -490,8 +492,11 @@ auto IdFileExistsInOlderGeneration( for (std::size_t generation = 1; generation < storage_config->num_generations; generation++) { - auto archive_tree_id_file = StorageUtils::GetArchiveTreeIDFile( - *storage_config, key.repo_type, key.archive.content, generation); + auto archive_tree_id_file = + StorageUtils::GetArchiveTreeIDFile(*storage_config, + key.repo_type, + key.archive.content_hash.Hash(), + generation); if (FileSystemManager::Exists(archive_tree_id_file)) { return generation; } @@ -614,7 +619,7 @@ void HandleKnownInOlderGenerationAfterImport( // Now that we have the tree persisted in the git repository of the youngest // generation; hence we can write the map-entry. auto archive_tree_id_file = StorageUtils::GetArchiveTreeIDFile( - *storage_config, key.repo_type, key.archive.content); + *storage_config, key.repo_type, key.archive.content_hash.Hash()); if (not StorageUtils::WriteTreeIDFile(archive_tree_id_file, tree_id)) { (*logger)(fmt::format("Failed to write tree id to file {}", archive_tree_id_file.string()), @@ -807,8 +812,11 @@ void HandleKnownInOlderGeneration( gsl::not_null<TaskSystem*> const& ts, ContentGitMap::SetterPtr const& setter, ContentGitMap::LoggerPtr const& logger) { - auto archive_tree_id_file = StorageUtils::GetArchiveTreeIDFile( - *storage_config, key.repo_type, key.archive.content, generation); + auto archive_tree_id_file = + StorageUtils::GetArchiveTreeIDFile(*storage_config, + key.repo_type, + key.archive.content_hash.Hash(), + generation); auto archive_tree_id = FileSystemManager::ReadFile(archive_tree_id_file); if (not archive_tree_id) { (*logger)(fmt::format("Failed to read tree id from file {}", @@ -907,7 +915,7 @@ auto CreateContentGitMap( auto /* unused */, auto const& key) { auto archive_tree_id_file = StorageUtils::GetArchiveTreeIDFile( - *storage_config, key.repo_type, key.archive.content); + *storage_config, key.repo_type, key.archive.content_hash.Hash()); if (FileSystemManager::Exists(archive_tree_id_file)) { HandleLocallyKnownTree(key, archive_tree_id_file, @@ -942,12 +950,12 @@ auto CreateContentGitMap( // request the resolved subdir tree from the serve endpoint, if // given if (serve != nullptr) { - auto serve_result = - serve->RetrieveTreeFromArchive(key.archive.content, - key.repo_type, - key.subdir, - key.pragma_special, - /*sync_tree = */ false); + auto serve_result = serve->RetrieveTreeFromArchive( + key.archive.content_hash.Hash(), + key.repo_type, + key.subdir, + key.pragma_special, + /*sync_tree = */ false); if (serve_result) { // set the workspace root as absent progress->TaskTracker().Stop(key.archive.origin); @@ -963,7 +971,7 @@ auto CreateContentGitMap( (*logger)( fmt::format("Serve endpoint failed to set up root " "from known archive content {}", - key.archive.content), + key.archive.content_hash.Hash()), /*fatal=*/true); return; } @@ -974,7 +982,7 @@ auto CreateContentGitMap( // check if content already in CAS auto const& cas = storage->CAS(); - auto digest = ArtifactDigest(key.archive.content, 0, false); + auto const digest = ArtifactDigest{key.archive.content_hash, 0}; if (auto content_cas_path = cas.BlobPath(digest, /*is_executable=*/false)) { ExtractAndImportToGit(key, @@ -1044,17 +1052,18 @@ auto CreateContentGitMap( // verify if local Git knows content blob auto wrapped_logger = std::make_shared<AsyncMapConsumerLogger>( - [&logger, blob = key.archive.content]( + [&logger, + hash = key.archive.content_hash.Hash()]( auto const& msg, bool fatal) { (*logger)( fmt::format("While verifying presence " "of blob {}:\n{}", - blob, + hash, msg), fatal); }); auto res = just_git_repo->TryReadBlob( - key.archive.content, wrapped_logger); + key.archive.content_hash.Hash(), wrapped_logger); if (not res.first) { // blob check failed return; @@ -1064,9 +1073,10 @@ auto CreateContentGitMap( // blob found; add it to CAS if (not cas.StoreBlob(*res.second, /*is_executable=*/false)) { - (*logger)(fmt::format("Failed to store content " - "{} to local CAS", - key.archive.content), + (*logger)(fmt::format( + "Failed to store content " + "{} to local CAS", + key.archive.content_hash.Hash()), /*fatal=*/true); return; } @@ -1129,7 +1139,7 @@ auto CreateContentGitMap( // report not being able to set up this root as absent (*logger)(fmt::format("Cannot create workspace root as " "absent for content {}.", - key.archive.content), + key.archive.content_hash.Hash()), /*fatal=*/true); }, [logger, target_path = storage_config->GitRoot()]( @@ -1159,9 +1169,9 @@ auto CreateContentGitMap( // content is in local CAS now auto const& cas = storage->CAS(); auto content_cas_path = - cas.BlobPath(ArtifactDigest( - key.archive.content, 0, false), - /*is_executable=*/false) + cas.BlobPath( + ArtifactDigest{key.archive.content_hash, 0}, + /*is_executable=*/false) .value(); // root can only be present, so default all arguments // that refer to a serve endpoint @@ -1179,11 +1189,11 @@ auto CreateContentGitMap( setter, logger); }, - [logger, content = key.archive.content](auto const& msg, - bool fatal) { + [logger, hash = key.archive.content_hash.Hash()]( + auto const& msg, bool fatal) { (*logger)(fmt::format("While ensuring content {} is in " "CAS:\n{}", - content, + hash, msg), fatal); }); diff --git a/src/other_tools/root_maps/foreign_file_git_map.cpp b/src/other_tools/root_maps/foreign_file_git_map.cpp index 37ab10e1..8bc09b86 100644 --- a/src/other_tools/root_maps/foreign_file_git_map.cpp +++ b/src/other_tools/root_maps/foreign_file_git_map.cpp @@ -15,6 +15,7 @@ #include "src/other_tools/root_maps/foreign_file_git_map.hpp" #include "fmt/core.h" +#include "src/buildtool/crypto/hash_info.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/logging/log_level.hpp" @@ -33,8 +34,11 @@ void WithRootImportedToGit(ForeignFileInfo const& key, (*logger)("Importing to git failed", /*fatal=*/true); return; } - auto tree_id_file = StorageUtils::GetForeignFileTreeIDFile( - storage_config, key.archive.content, key.name, key.executable); + auto tree_id_file = + StorageUtils::GetForeignFileTreeIDFile(storage_config, + key.archive.content_hash.Hash(), + key.name, + key.executable); auto cache_written = StorageUtils::WriteTreeIDFile(tree_id_file, result.first); if (not cache_written) { @@ -58,12 +62,12 @@ void WithFetchedFile(ForeignFileInfo const& key, ForeignFileGitMap::LoggerPtr const& logger) { auto tmp_dir = storage_config->CreateTypedTmpDir("foreign-file"); auto const& cas = storage.CAS(); - auto digest = ArtifactDigest(key.archive.content, 0, key.executable); + auto digest = ArtifactDigest{key.archive.content_hash, 0}; auto content_cas_path = cas.BlobPath(digest, key.executable); if (not content_cas_path) { (*logger)( fmt::format("Failed to locally find {} after fetching for repo {}", - key.archive.content, + key.archive.content_hash.Hash(), nlohmann::json(key.archive.origin).dump()), true); return; @@ -82,7 +86,7 @@ void WithFetchedFile(ForeignFileInfo const& key, CommitInfo c_info{ tmp_dir->GetPath(), fmt::format("foreign file at {}", nlohmann::json(key.name).dump()), - key.archive.content}; + key.archive.content_hash.Hash()}; import_to_git_map->ConsumeAfterKeysReady( ts, {std::move(c_info)}, @@ -122,10 +126,10 @@ void HandleAbsentForeignFile(ForeignFileInfo const& key, ForeignFileGitMap::LoggerPtr const& logger) { // Compute tree in memory GitRepo::tree_entries_t entries{}; - auto raw_id = FromHexString(key.archive.content); + auto raw_id = FromHexString(key.archive.content_hash.Hash()); if (not raw_id) { (*logger)(fmt::format("Failure converting {} to raw id.", - key.archive.content), + key.archive.content_hash.Hash()), true); return; } @@ -135,7 +139,7 @@ void HandleAbsentForeignFile(ForeignFileInfo const& key, if (not tree) { (*logger)(fmt::format("Failure to construct in-memory tree with entry " "{} at place {}", - key.archive.content, + key.archive.content_hash.Hash(), nlohmann::json(key.name).dump()), true); return; @@ -153,7 +157,7 @@ void HandleAbsentForeignFile(ForeignFileInfo const& key, return; } auto serve_result = serve->RetrieveTreeFromForeignFile( - key.archive.content, key.name, key.executable); + key.archive.content_hash.Hash(), key.name, key.executable); if (serve_result) { // if serve has set up the tree, it must match what we // expect @@ -175,7 +179,7 @@ void HandleAbsentForeignFile(ForeignFileInfo const& key, if (serve_result.error() == GitLookupError::Fatal) { (*logger)(fmt::format("Serve endpoint failed to set up root " "from known foreign-file content {}", - key.archive.content), + key.archive.content_hash.Hash()), /*fatal=*/true); return; } @@ -218,7 +222,10 @@ void HandleAbsentForeignFile(ForeignFileInfo const& key, return; } auto tree_id_file = StorageUtils::GetForeignFileTreeIDFile( - *storage_config, key.archive.content, key.name, key.executable); + *storage_config, + key.archive.content_hash.Hash(), + key.name, + key.executable); if (FileSystemManager::Exists(tree_id_file)) { auto tree_id = FileSystemManager::ReadFile(tree_id_file); if (not tree_id) { @@ -248,11 +255,11 @@ void HandleAbsentForeignFile(ForeignFileInfo const& key, setter, logger); }, - [logger, content = key.archive.content](auto const& msg, - bool fatal) { + [logger, hash = key.archive.content_hash.Hash()](auto const& msg, + bool fatal) { (*logger)(fmt::format("While ensuring content {} is in " "CAS:\n{}", - content, + hash, msg), fatal); }); diff --git a/src/other_tools/utils/TARGETS b/src/other_tools/utils/TARGETS index 0987e6e5..accde39f 100644 --- a/src/other_tools/utils/TARGETS +++ b/src/other_tools/utils/TARGETS @@ -62,7 +62,8 @@ , ["src/other_tools/ops_maps", "content_cas_map"] , ["src/utils/cpp", "expected"] ] - , "private-deps": [["@", "fmt", "", "fmt"]] + , "private-deps": + [["@", "fmt", "", "fmt"], ["src/buildtool/crypto", "hash_info"]] , "stage": ["src", "other_tools", "utils"] } , "parse_git_tree": diff --git a/src/other_tools/utils/parse_archive.cpp b/src/other_tools/utils/parse_archive.cpp index a8fc1830..fb03309a 100644 --- a/src/other_tools/utils/parse_archive.cpp +++ b/src/other_tools/utils/parse_archive.cpp @@ -17,6 +17,7 @@ #include <utility> // std::move #include "fmt/core.h" +#include "src/buildtool/crypto/hash_info.hpp" auto ParseArchiveContent(ExpressionPtr const& repo_desc, std::string const& origin) @@ -32,6 +33,18 @@ auto ParseArchiveContent(ExpressionPtr const& repo_desc, fmt::format("Unsupported value {} for mandatory field \"content\"", repo_desc_content->get()->ToString())}; } + + auto const repo_desc_hash_info = + HashInfo::Create(HashFunction::Type::GitSHA1, + repo_desc_content->get()->String(), + /*is_tree=*/false); + if (not repo_desc_hash_info) { + return unexpected{fmt::format( + "Unsupported value {} for mandatory field \"content\"\n{}", + repo_desc_content->get()->ToString(), + repo_desc_hash_info.error())}; + } + auto repo_desc_fetch = repo_desc->At("fetch"); if (not repo_desc_fetch) { return unexpected<std::string>{"Mandatory field \"fetch\" is missing"}; @@ -66,7 +79,7 @@ auto ParseArchiveContent(ExpressionPtr const& repo_desc, } return ArchiveContent{ - .content = repo_desc_content->get()->String(), + .content_hash = *repo_desc_hash_info, .distfile = repo_desc_distfile->IsString() ? std::make_optional(repo_desc_distfile->String()) : std::nullopt, |