summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildtool/execution_api')
-rw-r--r--src/buildtool/execution_api/local/file_storage.hpp21
-rw-r--r--src/buildtool/execution_api/local/local_ac.hpp3
-rw-r--r--src/buildtool/execution_api/local/local_cas.hpp4
3 files changed, 15 insertions, 13 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.
diff --git a/src/buildtool/execution_api/local/local_ac.hpp b/src/buildtool/execution_api/local/local_ac.hpp
index f319940a..f8cc3b7a 100644
--- a/src/buildtool/execution_api/local/local_ac.hpp
+++ b/src/buildtool/execution_api/local/local_ac.hpp
@@ -76,7 +76,8 @@ class LocalAC {
gsl::not_null<LocalCAS<ObjectType::File>*> cas_;
std::filesystem::path const cache_root_{
LocalExecutionConfig::GetCacheDir()};
- FileStorage<ObjectType::File, kStoreMode> file_store_{cache_root_ / "ac"};
+ FileStorage<ObjectType::File, kStoreMode, /*kSetEpochTime=*/false>
+ file_store_{cache_root_ / "ac"};
};
#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_LOCAL_LOCAL_AC_HPP
diff --git a/src/buildtool/execution_api/local/local_cas.hpp b/src/buildtool/execution_api/local/local_cas.hpp
index 470c38b9..f5158662 100644
--- a/src/buildtool/execution_api/local/local_cas.hpp
+++ b/src/buildtool/execution_api/local/local_cas.hpp
@@ -52,8 +52,8 @@ class LocalCAS {
Logger logger_{std::string{"LocalCAS"} + kSuffix};
std::filesystem::path const cache_root_{
LocalExecutionConfig::GetCacheDir()};
- FileStorage<kType> file_store_{cache_root_ /
- (std::string{"cas"} + kSuffix)};
+ FileStorage<kType, StoreMode::FirstWins, /*kSetEpochTime=*/true>
+ file_store_{cache_root_ / (std::string{"cas"} + kSuffix)};
[[nodiscard]] static auto CreateDigest(std::string const& bytes) noexcept
-> std::optional<bazel_re::Digest> {