diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2022-03-07 13:23:13 +0100 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2022-03-08 14:20:14 +0100 |
commit | 7ee82a31cb966a5e2350916f4b77d2d673810b00 (patch) | |
tree | 290b984b1c9d1fdf2a0efd48663fd85c99678e60 /src/buildtool/file_system/file_system_manager.hpp | |
parent | 5c60a0fab8fabcc828e2f6867e9eef3a211f9e4d (diff) | |
download | justbuild-7ee82a31cb966a5e2350916f4b77d2d673810b00.tar.gz |
FileSystemManager: Implement hard link creation with perms
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 { |