diff options
-rw-r--r-- | src/buildtool/storage/large_object_cas.tpp | 15 | ||||
-rw-r--r-- | src/buildtool/storage/local_cas.hpp | 20 | ||||
-rw-r--r-- | test/buildtool/storage/large_object_cas.test.cpp | 15 |
3 files changed, 24 insertions, 26 deletions
diff --git a/src/buildtool/storage/large_object_cas.tpp b/src/buildtool/storage/large_object_cas.tpp index ef720822..db2f46a9 100644 --- a/src/buildtool/storage/large_object_cas.tpp +++ b/src/buildtool/storage/large_object_cas.tpp @@ -125,9 +125,18 @@ auto LargeObjectCAS<kDoGlobalUplink, kType>::Split( } // Get path to the file: - auto file_path = IsTreeObject(kType) - ? local_cas_.TreePath(digest) - : local_cas_.BlobPath(digest, /*is_executable=*/false); + std::optional<std::filesystem::path> file_path; + if constexpr (IsTreeObject(kType)) { + file_path = local_cas_.TreePath(digest); + } + else { + // Avoid synchronization between file/executable storages: + static constexpr bool kIsExec = IsExecutableObject(kType); + file_path = local_cas_.BlobPathNoSync(digest, kIsExec); + file_path = file_path ? file_path + : local_cas_.BlobPathNoSync(digest, not kIsExec); + } + if (not file_path) { return LargeObjectError{ LargeObjectErrorCode::FileNotFound, diff --git a/src/buildtool/storage/local_cas.hpp b/src/buildtool/storage/local_cas.hpp index 64dc5082..892946de 100644 --- a/src/buildtool/storage/local_cas.hpp +++ b/src/buildtool/storage/local_cas.hpp @@ -108,6 +108,18 @@ class LocalCAS { return path ? path : TrySyncBlob(digest, is_executable); } + /// \brief Obtain blob path from digest with x-bit. + /// Synchronization between file/executable CAS is skipped. + /// \param digest Digest of the blob to lookup. + /// \param is_executable Lookup blob with executable permissions. + /// \returns Path to the blob if found or nullopt otherwise. + [[nodiscard]] auto BlobPathNoSync(bazel_re::Digest const& digest, + bool is_executable) const noexcept + -> std::optional<std::filesystem::path> { + return is_executable ? cas_exec_.BlobPath(digest) + : cas_file_.BlobPath(digest); + } + /// \brief Split a blob into chunks. /// \param digest The digest of a blob to be split. /// \returns Digests of the parts of the large object or an @@ -280,14 +292,6 @@ class LocalCAS { return ObjectCAS<kType>::kDefaultExists; } - /// \brief Get blob path without sync between file/executable CAS. - [[nodiscard]] auto BlobPathNoSync(bazel_re::Digest const& digest, - bool is_executable) const noexcept - -> std::optional<std::filesystem::path> { - return is_executable ? cas_exec_.BlobPath(digest) - : cas_file_.BlobPath(digest); - } - /// \brief Try to sync blob between file CAS and executable CAS. /// \param digest Blob digest. /// \param to_executable Sync direction. diff --git a/test/buildtool/storage/large_object_cas.test.cpp b/test/buildtool/storage/large_object_cas.test.cpp index 9b0fc90b..7f45c7b8 100644 --- a/test/buildtool/storage/large_object_cas.test.cpp +++ b/test/buildtool/storage/large_object_cas.test.cpp @@ -153,13 +153,6 @@ static void TestLarge() noexcept { CHECK(FileSystemManager::RemoveFile(path)); CHECK_FALSE(FileSystemManager::IsFile(path)); - // For executables the non-executable entry must be also deleted. - if constexpr (kIsExec) { - auto blob_path = cas.BlobPath(digest, /*is_executable=*/false); - REQUIRE(blob_path); - CHECK(FileSystemManager::RemoveFile(*blob_path)); - CHECK_FALSE(FileSystemManager::IsFile(*blob_path)); - } SECTION("Split short-circuting") { // Check the second call loads the entry from the large CAS: @@ -311,14 +304,6 @@ static void TestEmpty() noexcept { CHECK(FileSystemManager::RemoveFile(path)); CHECK_FALSE(FileSystemManager::IsFile(path)); - // For executables the non-executable entry must be also deleted. - if constexpr (kIsExec) { - auto blob_path = cas.BlobPath(digest, /*is_executable=*/false); - REQUIRE(blob_path); - CHECK(FileSystemManager::RemoveFile(*blob_path)); - CHECK_FALSE(FileSystemManager::IsFile(*blob_path)); - } - // Split must not find the large entry: auto pack_2 = kIsTree ? cas.SplitTree(digest) : cas.SplitBlob(digest); auto* error_2 = std::get_if<LargeObjectError>(&pack_2); |