diff options
Diffstat (limited to 'src/buildtool/execution_api/local/local_storage.cpp')
-rw-r--r-- | src/buildtool/execution_api/local/local_storage.cpp | 96 |
1 files changed, 52 insertions, 44 deletions
diff --git a/src/buildtool/execution_api/local/local_storage.cpp b/src/buildtool/execution_api/local/local_storage.cpp index e6d9571c..483f664f 100644 --- a/src/buildtool/execution_api/local/local_storage.cpp +++ b/src/buildtool/execution_api/local/local_storage.cpp @@ -114,69 +114,77 @@ auto LocalStorage::ReadObjectInfosRecursively( std::filesystem::path const& parent, bazel_re::Digest const& digest) const noexcept -> bool { // read from in-memory tree map - if (tree_map_) { - auto const* tree = tree_map_->GetTree(digest); - if (tree != nullptr) { - return std::all_of( - tree->begin(), - tree->end(), - // NOLINTNEXTLINE(misc-no-recursion) - [this, &store_info, &parent](auto const& entry) { - try { - auto const& [path, info] = entry; - return IsTreeObject(info->type) - ? ReadObjectInfosRecursively(store_info, - parent / path, - info->digest) - : store_info(parent / path, *info); - } catch (...) { // satisfy clang-tidy, store_info() could - return false; - } - }); - } - Logger::Log( - LogLevel::Debug, "tree {} not found in tree map", digest.hash()); + auto const* tree = tree_map_.GetTree(digest); + if (tree != nullptr) { + return std::all_of( + tree->begin(), + tree->end(), + [&store_info, &parent](auto const& entry) { + try { + // LocalTree (from tree_map_) is flat, no recursion needed + auto const& [path, info] = entry; + return store_info(parent / path, *info); + } catch (...) { // satisfy clang-tidy, store_info() could + return false; + } + }); } + Logger::Log( + LogLevel::Debug, "tree {} not found in tree map", digest.hash()); // fallback read from CAS and cache it in in-memory tree map if (Compatibility::IsCompatible()) { if (auto dir = ReadDirectory(this, digest)) { - auto tree = tree_map_ ? std::make_optional(tree_map_->CreateTree()) - : std::nullopt; + auto tree = tree_map_.CreateTree(); return BazelMsgFactory::ReadObjectInfosFromDirectory( *dir, [this, &store_info, &parent, &tree](auto path, auto info) { - return (not tree or tree->AddInfo(path, info)) and - (IsTreeObject(info.type) - ? ReadObjectInfosRecursively( - store_info, - parent / path, - info.digest) - : store_info(parent / path, info)); + if (IsTreeObject(info.type)) { + // LocalTree (from tree_map_) is flat, so + // recursively traverse subtrees and add blobs. + auto tree_store_info = + [&store_info, &tree, &parent](auto path, + auto info) { + auto tree_path = + path.lexically_relative(parent); + return tree.AddInfo(tree_path, info) and + store_info(path, info); + }; + return ReadObjectInfosRecursively( + tree_store_info, parent / path, info.digest); + } + return tree.AddInfo(path, info) and + store_info(parent / path, info); }) and - (not tree_map_ or - tree_map_->AddTree(digest, std::move(*tree))); + tree_map_.AddTree(digest, std::move(tree)); } } else { if (auto entries = ReadGitTree(this, digest)) { - auto tree = tree_map_ ? std::make_optional(tree_map_->CreateTree()) - : std::nullopt; + auto tree = tree_map_.CreateTree(); return BazelMsgFactory::ReadObjectInfosFromGitTree( *entries, [this, &store_info, &parent, &tree](auto path, auto info) { - return (not tree or tree->AddInfo(path, info)) and - (IsTreeObject(info.type) - ? ReadObjectInfosRecursively( - store_info, - parent / path, - info.digest) - : store_info(parent / path, info)); + if (IsTreeObject(info.type)) { + // LocalTree (from tree_map_) is flat, so + // recursively traverse subtrees and add blobs. + auto tree_store_info = + [&store_info, &tree, &parent](auto path, + auto info) { + auto tree_path = + path.lexically_relative(parent); + return tree.AddInfo(tree_path, info) and + store_info(path, info); + }; + return ReadObjectInfosRecursively( + tree_store_info, parent / path, info.digest); + } + return tree.AddInfo(path, info) and + store_info(parent / path, info); }) and - (not tree_map_ or - tree_map_->AddTree(digest, std::move(*tree))); + tree_map_.AddTree(digest, std::move(tree)); } } return false; |