summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_api/local/file_storage.hpp
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2022-03-09 18:11:20 +0100
committerOliver Reiche <oliver.reiche@huawei.com>2022-03-09 18:11:20 +0100
commitd6105778839cbdae5bfd234d54929b972328a6ee (patch)
treee037420649d3c9e01efb59e8f6594f1b19439242 /src/buildtool/execution_api/local/file_storage.hpp
parentf08ea2051eeff565d7d63d721371206133c48b63 (diff)
downloadjustbuild-d6105778839cbdae5bfd234d54929b972328a6ee.tar.gz
LocalCAS: Set epoch time for every entry
... and refactor static constant to proper format `kFdLess`.
Diffstat (limited to 'src/buildtool/execution_api/local/file_storage.hpp')
-rw-r--r--src/buildtool/execution_api/local/file_storage.hpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/buildtool/execution_api/local/file_storage.hpp b/src/buildtool/execution_api/local/file_storage.hpp
index ec7714f6..0af749ad 100644
--- a/src/buildtool/execution_api/local/file_storage.hpp
+++ b/src/buildtool/execution_api/local/file_storage.hpp
@@ -17,8 +17,7 @@ enum class StoreMode {
LastWins
};
-template <ObjectType kType = ObjectType::File,
- StoreMode kMode = StoreMode::FirstWins>
+template <ObjectType kType, StoreMode kMode, bool kSetEpochTime>
class FileStorage {
public:
explicit FileStorage(std::filesystem::path storage_root) noexcept
@@ -47,8 +46,8 @@ class FileStorage {
}
private:
+ static constexpr bool kFdLess{kType == ObjectType::Executable};
std::filesystem::path const storage_root_{};
- static constexpr bool fd_less_{kType == ObjectType::Executable};
/// \brief Add file to storage from file path via link or copy and rename.
/// If a race-condition occurs, the winning thread will be the one
@@ -68,7 +67,8 @@ class FileStorage {
// Entry does not exist and we are owner of the file (e.g., file
// generated in the execution directory). Try to hard link it
// directly or check its existence if it was created by now.
- return FileSystemManager::CreateFileHardlinkAs<kType>(
+ return FileSystemManager::CreateFileHardlinkAs<kType,
+ kSetEpochTime>(
path, file_path) or
FileSystemManager::IsFile(file_path);
};
@@ -124,10 +124,11 @@ class FileStorage {
// directory), prefer faster creation of hard links instead of a copy.
// Copy executables without opening any writeable file descriptors in
// this process to avoid those from being inherited by child processes.
- return (is_owner and FileSystemManager::CreateFileHardlinkAs<kType>(
- other_path, file_path)) or
- FileSystemManager::CopyFileAs<kType>(
- other_path, file_path, fd_less_);
+ return (is_owner and
+ FileSystemManager::CreateFileHardlinkAs<kType, kSetEpochTime>(
+ other_path, file_path)) or
+ FileSystemManager::CopyFileAs<kType, kSetEpochTime>(
+ other_path, file_path, kFdLess);
}
/// \brief Create file from bytes.
@@ -136,8 +137,8 @@ class FileStorage {
std::string const& bytes) noexcept -> bool {
// Write executables without opening any writeable file descriptors in
// this process to avoid those from being inherited by child processes.
- return FileSystemManager::WriteFileAs<kType>(
- bytes, file_path, fd_less_);
+ return FileSystemManager::WriteFileAs<kType, kSetEpochTime>(
+ bytes, file_path, kFdLess);
}
/// \brief Stage file from source path to target path.