From 7ee82a31cb966a5e2350916f4b77d2d673810b00 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Mon, 7 Mar 2022 13:23:13 +0100 Subject: FileSystemManager: Implement hard link creation with perms --- src/buildtool/file_system/file_system_manager.hpp | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/buildtool/file_system/file_system_manager.hpp') 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 + 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(file_path, + link_path); + case ObjectType::Executable: + return CreateFileHardlinkAs(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 { -- cgit v1.2.3