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