diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/execution_api/bazel_msg/bazel_blob.hpp | 2 | ||||
-rw-r--r-- | src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp | 11 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/local_action.cpp | 36 | ||||
-rw-r--r-- | src/buildtool/file_system/file_root.hpp | 10 | ||||
-rw-r--r-- | src/buildtool/file_system/file_system_manager.hpp | 26 |
5 files changed, 43 insertions, 42 deletions
diff --git a/src/buildtool/execution_api/bazel_msg/bazel_blob.hpp b/src/buildtool/execution_api/bazel_msg/bazel_blob.hpp index ed82d92d..944bb2d8 100644 --- a/src/buildtool/execution_api/bazel_msg/bazel_blob.hpp +++ b/src/buildtool/execution_api/bazel_msg/bazel_blob.hpp @@ -39,7 +39,7 @@ struct BazelBlob { /// given path. [[nodiscard]] static inline auto CreateBlobFromPath( std::filesystem::path const& fpath) noexcept -> std::optional<BazelBlob> { - auto const type = FileSystemManager::Type(fpath); + auto const type = FileSystemManager::Type(fpath, /*allow_upwards=*/true); if (not type) { return std::nullopt; } diff --git a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp index 9104b94d..145b51cd 100644 --- a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp +++ b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp @@ -600,8 +600,7 @@ auto BazelMsgFactory::CreateDirectoryDigestFromLocalTree( if (IsSymlinkObject(type)) { // create and store symlink auto content = FileSystemManager::ReadSymlink(full_name); - if (content and PathIsNonUpwards(*content) and - store_symlink(*content)) { + if (content and store_symlink(*content)) { symlinks.emplace_back( CreateSymlinkNode(name.string(), *content, {})); return true; @@ -628,7 +627,8 @@ auto BazelMsgFactory::CreateDirectoryDigestFromLocalTree( return false; }; - if (FileSystemManager::ReadDirectory(root, dir_reader)) { + if (FileSystemManager::ReadDirectory( + root, dir_reader, /*allow_upwards=*/true)) { auto dir = CreateDirectory(files, dirs, symlinks, {}); if (auto bytes = SerializeMessage(dir)) { try { @@ -678,7 +678,7 @@ auto BazelMsgFactory::CreateGitTreeDigestFromLocalTree( try { if (IsSymlinkObject(type)) { auto content = FileSystemManager::ReadSymlink(full_name); - if (content and PathIsNonUpwards(*content)) { + if (content) { if (auto digest = store_symlink(*content)) { if (auto raw_id = FromHexString( NativeSupport::Unprefix(digest->hash()))) { @@ -716,7 +716,8 @@ auto BazelMsgFactory::CreateGitTreeDigestFromLocalTree( return false; }; - if (FileSystemManager::ReadDirectory(root, dir_reader)) { + if (FileSystemManager::ReadDirectory( + root, dir_reader, /*allow_upwards=*/true)) { if (auto tree = GitRepo::CreateShallowTree(entries)) { try { if (auto digest = store_tree(tree->second, entries)) { diff --git a/src/buildtool/execution_api/local/local_action.cpp b/src/buildtool/execution_api/local/local_action.cpp index d3ad7fd9..3fcd8fe7 100644 --- a/src/buildtool/execution_api/local/local_action.cpp +++ b/src/buildtool/execution_api/local/local_action.cpp @@ -268,15 +268,14 @@ auto LocalAction::CollectOutputFileOrSymlink( std::string const& local_path) const noexcept -> std::optional<OutputFileOrSymlink> { auto file_path = exec_path / local_path; - auto type = FileSystemManager::Type(file_path); + auto type = FileSystemManager::Type(file_path, /*allow_upwards=*/true); if (not type) { Logger::Log(LogLevel::Error, "expected known type at {}", local_path); return std::nullopt; } if (IsSymlinkObject(*type)) { auto content = FileSystemManager::ReadSymlink(file_path); - if (content and PathIsNonUpwards(*content) and - storage_->CAS().StoreBlob(*content)) { + if (content and storage_->CAS().StoreBlob(*content)) { auto out_symlink = bazel_re::OutputSymlink{}; out_symlink.set_path(local_path); out_symlink.set_target(*content); @@ -308,15 +307,14 @@ auto LocalAction::CollectOutputDirOrSymlink( std::string const& local_path) const noexcept -> std::optional<OutputDirOrSymlink> { auto dir_path = exec_path / local_path; - auto type = FileSystemManager::Type(dir_path); + auto type = FileSystemManager::Type(dir_path, /*allow_upwards=*/true); if (not type) { Logger::Log(LogLevel::Error, "expected known type at {}", local_path); return std::nullopt; } if (IsSymlinkObject(*type)) { auto content = FileSystemManager::ReadSymlink(dir_path); - if (content and PathIsNonUpwards(*content) and - storage_->CAS().StoreBlob(*content)) { + if (content and storage_->CAS().StoreBlob(*content)) { auto out_symlink = bazel_re::OutputSymlink{}; out_symlink.set_path(local_path); out_symlink.set_target(*content); @@ -354,15 +352,10 @@ auto LocalAction::CollectAndStoreOutputs( } if (std::holds_alternative<bazel_re::OutputSymlink>(*out)) { auto out_symlink = std::get<bazel_re::OutputSymlink>(*out); - auto const& target = out_symlink.target(); - if (not PathIsNonUpwards(target)) { - logger_.Emit(LogLevel::Error, - "collected upwards output symlink {}", - path); - return false; - } - logger_.Emit( - LogLevel::Trace, " - symlink {}: {}", path, target); + logger_.Emit(LogLevel::Trace, + " - symlink {}: {}", + path, + out_symlink.target()); result->mutable_output_file_symlinks()->Add( std::move(out_symlink)); } @@ -383,15 +376,10 @@ auto LocalAction::CollectAndStoreOutputs( } if (std::holds_alternative<bazel_re::OutputSymlink>(*out)) { auto out_symlink = std::get<bazel_re::OutputSymlink>(*out); - auto const& target = out_symlink.target(); - if (not PathIsNonUpwards(target)) { - logger_.Emit(LogLevel::Error, - "collected upwards output symlink {}", - path); - return false; - } - logger_.Emit( - LogLevel::Trace, " - symlink {}: {}", path, target); + logger_.Emit(LogLevel::Trace, + " - symlink {}: {}", + path, + out_symlink.target()); result->mutable_output_file_symlinks()->Add( std::move(out_symlink)); } diff --git a/src/buildtool/file_system/file_root.hpp b/src/buildtool/file_system/file_root.hpp index b332f9cd..feb5519a 100644 --- a/src/buildtool/file_system/file_root.hpp +++ b/src/buildtool/file_system/file_root.hpp @@ -362,7 +362,7 @@ class FileRoot { // std::holds_alternative<fs_root_t>(root_) == true auto root_path = std::get<fs_root_t>(root_) / path; auto exists = FileSystemManager::Exists(root_path); - auto type = FileSystemManager::Type(root_path); + auto type = FileSystemManager::Type(root_path, /*allow_upwards=*/true); return (ignore_special_ ? exists and type and IsNonSpecialObject(*type) : exists); } @@ -431,7 +431,8 @@ class FileRoot { return std::nullopt; } auto full_path = std::get<fs_root_t>(root_) / file_path; - if (auto type = FileSystemManager::Type(full_path)) { + if (auto type = + FileSystemManager::Type(full_path, /*allow_upwards=*/true)) { return IsSymlinkObject(*type) ? FileSystemManager::ReadSymlink(full_path) : FileSystemManager::ReadFile(full_path); @@ -461,6 +462,7 @@ class FileRoot { map.emplace(name.string(), type); return true; }, + /*allow_upwards=*/false, ignore_special_)) { return DirectoryEntries{std::move(map)}; } @@ -486,8 +488,8 @@ class FileRoot { } return std::nullopt; } - auto type = - FileSystemManager::Type(std::get<fs_root_t>(root_) / file_path); + auto type = FileSystemManager::Type( + std::get<fs_root_t>(root_) / file_path, /*allow_upwards=*/true); if (type and IsBlobObject(*type)) { return type; } diff --git a/src/buildtool/file_system/file_system_manager.hpp b/src/buildtool/file_system/file_system_manager.hpp index 04f84cf4..6b6b675f 100644 --- a/src/buildtool/file_system/file_system_manager.hpp +++ b/src/buildtool/file_system/file_system_manager.hpp @@ -588,7 +588,9 @@ class FileSystemManager { } /// \brief Gets type of object in path according to file system - [[nodiscard]] static auto Type(std::filesystem::path const& path) noexcept + /// \param allow_upwards Do not enforce non-upwardness in symlinks. + [[nodiscard]] static auto Type(std::filesystem::path const& path, + bool allow_upwards = false) noexcept -> std::optional<ObjectType> { try { auto const status = std::filesystem::symlink_status(path); @@ -602,7 +604,7 @@ class FileSystemManager { return ObjectType::Tree; } if (std::filesystem::is_symlink(status) and - IsNonUpwardsSymlink(path)) { + (allow_upwards or IsNonUpwardsSymlink(path))) { return ObjectType::Symlink; } if (std::filesystem::exists(status)) { @@ -680,9 +682,11 @@ class FileSystemManager { /// \brief Read a filesystem directory tree. /// \param ignore_special If true, do not error out when encountering /// symlinks. + /// \param allow_upwards If true, do not enforce non-upwardness of symlinks. [[nodiscard]] static auto ReadDirectory( std::filesystem::path const& dir, ReadDirEntryFunc const& read_entry, + bool allow_upwards = false, bool ignore_special = false) noexcept -> bool { try { for (auto const& entry : std::filesystem::directory_iterator{dir}) { @@ -707,14 +711,20 @@ class FileSystemManager { // if not already ignored, check symlinks and only add the // non-upwards ones else if (std::filesystem::is_symlink(status)) { - if (IsNonUpwardsSymlink(entry)) { - type = ObjectType::Symlink; + if (not allow_upwards) { + if (IsNonUpwardsSymlink(entry)) { + type = ObjectType::Symlink; + } + else { + Logger::Log( + LogLevel::Error, + "unsupported upwards symlink dir entry {}", + entry.path().string()); + return false; + } } else { - Logger::Log(LogLevel::Error, - "unsupported upwards symlink dir entry {}", - entry.path().string()); - return false; + type = ObjectType::Symlink; } } else { |