diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2025-05-22 17:22:25 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2025-06-04 14:34:44 +0200 |
commit | bed4f4d7c81420832b05acaf9259b50458792b74 (patch) | |
tree | 55b93430c508428a9b8287905c14bb7bd647376f /src/buildtool | |
parent | 42e82b0f737de367de38567cbe6ee5f158618a2d (diff) | |
download | justbuild-bed4f4d7c81420832b05acaf9259b50458792b74.tar.gz |
GitRepo: Add tree reader without symlink checker
Diffstat (limited to 'src/buildtool')
-rw-r--r-- | src/buildtool/file_system/git_repo.cpp | 49 | ||||
-rw-r--r-- | src/buildtool/file_system/git_repo.hpp | 13 |
2 files changed, 49 insertions, 13 deletions
diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp index d63626a2..4a6e8ad2 100644 --- a/src/buildtool/file_system/git_repo.cpp +++ b/src/buildtool/file_system/git_repo.cpp @@ -1784,10 +1784,9 @@ auto GitRepo::IsRepoFake() const noexcept -> bool { return is_repo_fake_; } -auto GitRepo::ReadTree(std::string const& id, - gsl::not_null<SymlinksCheckFunc> const& check_symlinks, - bool is_hex_id, - bool ignore_special) const noexcept +auto GitRepo::ReadDirectTree(std::string const& id, + bool is_hex_id, + bool ignore_special) const noexcept -> std::optional<tree_entries_t> { #ifndef BOOTSTRAP_BUILD_TOOL try { @@ -1822,6 +1821,34 @@ auto GitRepo::ReadTree(std::string const& id, is_hex_id ? std::string{id} : ToHexString(id)); return std::nullopt; } +#ifndef NDEBUG + // Debug-only consistency check for read entries to avoid downstream + // failures due to programmatic errors. Expected to always pass. + // No need to check if entries exist, so do not pass the Git CAS. + EnsuresAudit(ValidateEntries(entries)); +#endif + + return entries; + } catch (std::exception const& ex) { + Logger::Log( + LogLevel::Debug, "reading direct tree failed with:\n{}", ex.what()); + } +#endif + + return std::nullopt; +} + +auto GitRepo::ReadTree(std::string const& id, + gsl::not_null<SymlinksCheckFunc> const& check_symlinks, + bool is_hex_id, + bool ignore_special) const noexcept + -> std::optional<tree_entries_t> { +#ifndef BOOTSTRAP_BUILD_TOOL + try { + auto entries = ReadDirectTree(id, is_hex_id, ignore_special); + if (not entries) { + return std::nullopt; + } // checking non-upwardness of symlinks can not be easily or safely done // during the tree walk, so it is done here. This is only needed for @@ -1830,8 +1857,8 @@ auto GitRepo::ReadTree(std::string const& id, // we first gather all symlink candidates // to check symlinks in bulk, optimized for network-backed repos std::vector<ArtifactDigest> symlinks{}; - symlinks.reserve(entries.size()); // at most one symlink per entry - for (auto const& entry : entries) { + symlinks.reserve(entries->size()); // at most one symlink per entry + for (auto const& entry : *entries) { if (std::any_of(entry.second.begin(), entry.second.end(), [](TreeEntry const& item) { @@ -1861,15 +1888,11 @@ auto GitRepo::ReadTree(std::string const& id, } } -#ifndef NDEBUG - // Check consistency of entries. No need to check if entries exist. - EnsuresAudit(ValidateEntries(entries)); -#endif - return entries; } catch (std::exception const& ex) { - Logger::Log( - LogLevel::Error, "reading tree failed with:\n{}", ex.what()); + Logger::Log(LogLevel::Error, + "reading tree with checker failed with:\n{}", + ex.what()); } #endif diff --git a/src/buildtool/file_system/git_repo.hpp b/src/buildtool/file_system/git_repo.hpp index f8591d75..c559cbba 100644 --- a/src/buildtool/file_system/git_repo.hpp +++ b/src/buildtool/file_system/git_repo.hpp @@ -109,6 +109,19 @@ class GitRepo { /// Reading a tree must be backed by an object database. Therefore, a real /// repository is required. /// \param id The object id. + /// \param is_hex_id Specify whether `id` is hex string or raw. + /// \param ignore_special If set, treat symlinks as absent. + /// \note This method does not perform any content-based validity checks on + /// the read entries. For reading with symlinks validation use ReadTree(). + [[nodiscard]] auto ReadDirectTree(std::string const& id, + bool is_hex_id = false, + bool ignore_special = false) + const noexcept -> std::optional<tree_entries_t>; + + /// \brief Read entries from tree in CAS. + /// Reading a tree must be backed by an object database. Therefore, a real + /// repository is required. + /// \param id The object id. /// \param check_symlinks Function to check non-upwardness condition. /// \param is_hex_id Specify whether `id` is hex string or raw. /// \param ignore_special If set, treat symlinks as absent. |