diff options
Diffstat (limited to 'src/buildtool/file_system/file_system_manager.hpp')
-rw-r--r-- | src/buildtool/file_system/file_system_manager.hpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/buildtool/file_system/file_system_manager.hpp b/src/buildtool/file_system/file_system_manager.hpp index 1be50ac0..0bdfb8a6 100644 --- a/src/buildtool/file_system/file_system_manager.hpp +++ b/src/buildtool/file_system/file_system_manager.hpp @@ -118,6 +118,34 @@ class FileSystemManager { } } + template <ObjectType kType> + requires(IsFileObject(kType)) + [[nodiscard]] static auto CreateFileHardlinkAs( + std::filesystem::path const& file_path, + std::filesystem::path const& link_path) noexcept -> bool { + // Set permissions first (permissions are a property of the file) so + // that the created link has the correct permissions as soon as the link + // creation is finished. + return SetFilePermissions(file_path, IsExecutableObject(kType)) and + CreateFileHardlink(file_path, link_path); + } + + [[nodiscard]] static auto CreateFileHardlinkAs( + std::filesystem::path const& file_path, + std::filesystem::path const& link_path, + ObjectType output_type) noexcept -> bool { + switch (output_type) { + case ObjectType::File: + return CreateFileHardlinkAs<ObjectType::File>(file_path, + link_path); + case ObjectType::Executable: + return CreateFileHardlinkAs<ObjectType::Executable>(file_path, + link_path); + case ObjectType::Tree: + return false; + } + } + [[nodiscard]] static auto Rename(std::filesystem::path const& src, std::filesystem::path const& dst, bool no_clobber = false) noexcept -> bool { |