diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-06-14 16:40:48 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-06-26 17:57:29 +0200 |
commit | 3865c8556bde5e614dc1e8c72f83fa1ed65abcd9 (patch) | |
tree | 7c4f118c07fe35a89deadbc9f4aa09b2f5f64e87 /src/buildtool/file_system/file_system_manager.hpp | |
parent | db961e1e9fba6e0c439f69ac8342ef887d9d19a6 (diff) | |
download | justbuild-3865c8556bde5e614dc1e8c72f83fa1ed65abcd9.tar.gz |
bazel_msg_factory: Allow non-upwards symlinks in uploaded trees
Diffstat (limited to 'src/buildtool/file_system/file_system_manager.hpp')
-rw-r--r-- | src/buildtool/file_system/file_system_manager.hpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/buildtool/file_system/file_system_manager.hpp b/src/buildtool/file_system/file_system_manager.hpp index 30a469af..a319cc0e 100644 --- a/src/buildtool/file_system/file_system_manager.hpp +++ b/src/buildtool/file_system/file_system_manager.hpp @@ -695,6 +695,31 @@ class FileSystemManager { return std::nullopt; } + /// \brief Read the content of given file or symlink. + [[nodiscard]] static auto ReadContentAtPath( + std::filesystem::path const& fpath, + ObjectType type) -> std::optional<std::string> { + try { + if (IsSymlinkObject(type)) { + return ReadSymlink(fpath); + } + if (IsFileObject(type)) { + return ReadFile(fpath, type); + } + Logger::Log( + LogLevel::Debug, + "{} can not be read because it is neither a file nor symlink.", + fpath.string()); + } catch (std::exception const& ex) { + Logger::Log(LogLevel::Error, + "reading content at path {} failed:\n{}", + fpath.string(), + ex.what()); + } + + return std::nullopt; + } + /// \brief Write file /// If argument fd_less is given, the write will be performed in a child /// process to prevent polluting the parent with open writable file |