diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-06-13 17:35:05 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-06-26 17:57:29 +0200 |
commit | c11e9142d2a1b04004dcbed282dc1e04d116e03f (patch) | |
tree | b1c72fa8f9491f35b3c631ce98acbf00e627a59d /src/buildtool/file_system/git_repo.hpp | |
parent | d2e3ad946b35a72a94b2d125550daf5d5e4c9904 (diff) | |
download | justbuild-c11e9142d2a1b04004dcbed282dc1e04d116e03f.tar.gz |
ReadTree: Add check for non-upwards symlinks...
...as early as possible. This ensures that callers always receive
only the tree entries for the supported object types.
For the symlinks non-upwardness check we pass a lambda capturing
the real backend of the tree entries, such that the symlinks can
be read.
Updates git_tree tests accordingly.
Diffstat (limited to 'src/buildtool/file_system/git_repo.hpp')
-rw-r--r-- | src/buildtool/file_system/git_repo.hpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/buildtool/file_system/git_repo.hpp b/src/buildtool/file_system/git_repo.hpp index 43c5fa22..e96f401b 100644 --- a/src/buildtool/file_system/git_repo.hpp +++ b/src/buildtool/file_system/git_repo.hpp @@ -17,6 +17,7 @@ #include <functional> +#include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/file_system/git_cas.hpp" extern "C" { @@ -48,6 +49,11 @@ class GitRepo { using tree_entries_t = std::unordered_map<std::string, std::vector<tree_entry_t>>; + // Checks whether a list of symlinks given by their hashes are non-upwards, + // based on content read from an actual backend. + using SymlinksCheckFunc = + std::function<bool(std::vector<bazel_re::Digest> const&)>; + GitRepo() = delete; // no default ctor ~GitRepo() noexcept = default; @@ -80,9 +86,11 @@ class GitRepo { /// 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. [[nodiscard]] auto ReadTree(std::string const& id, + SymlinksCheckFunc const& check_symlinks, bool is_hex_id = false, bool ignore_special = false) const noexcept -> std::optional<tree_entries_t>; @@ -100,12 +108,14 @@ class GitRepo { /// \brief Read entries from tree data (without object db). /// \param data The tree object as plain data. /// \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. /// \returns The tree entries. - [[nodiscard]] static auto ReadTreeData(std::string const& data, - std::string const& id, - bool is_hex_id = false) noexcept - -> std::optional<tree_entries_t>; + [[nodiscard]] static auto ReadTreeData( + std::string const& data, + std::string const& id, + SymlinksCheckFunc const& check_symlinks, + bool is_hex_id = false) noexcept -> std::optional<tree_entries_t>; /// \brief Create a flat shallow (without objects in db) tree and return it. /// Creates a tree object from the entries without access to the actual |