summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2022-03-07 13:23:13 +0100
committerOliver Reiche <oliver.reiche@huawei.com>2022-03-08 14:20:14 +0100
commit7ee82a31cb966a5e2350916f4b77d2d673810b00 (patch)
tree290b984b1c9d1fdf2a0efd48663fd85c99678e60 /src
parent5c60a0fab8fabcc828e2f6867e9eef3a211f9e4d (diff)
downloadjustbuild-7ee82a31cb966a5e2350916f4b77d2d673810b00.tar.gz
FileSystemManager: Implement hard link creation with perms
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/file_system/file_system_manager.hpp28
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 {