diff options
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 |