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/file_system_manager.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/file_system_manager.hpp')
-rw-r--r-- | src/buildtool/file_system/file_system_manager.hpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/buildtool/file_system/file_system_manager.hpp b/src/buildtool/file_system/file_system_manager.hpp index 8555e8dc..30a469af 100644 --- a/src/buildtool/file_system/file_system_manager.hpp +++ b/src/buildtool/file_system/file_system_manager.hpp @@ -675,6 +675,26 @@ class FileSystemManager { return true; } + /// \brief Read the content of a symlink. + [[nodiscard]] static auto ReadSymlink(std::filesystem::path const& link) + -> std::optional<std::string> { + try { + if (std::filesystem::is_symlink(link)) { + return std::filesystem::read_symlink(link).string(); + } + Logger::Log(LogLevel::Debug, + "{} can not be read because it is not a symlink.", + link.string()); + } catch (std::exception const& ex) { + Logger::Log(LogLevel::Error, + "reading symlink {} failed:\n{}", + link.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 |