diff options
-rw-r--r-- | src/buildtool/file_system/file_storage.hpp | 10 | ||||
-rw-r--r-- | src/buildtool/storage/compactifier.cpp | 8 |
2 files changed, 14 insertions, 4 deletions
diff --git a/src/buildtool/file_system/file_storage.hpp b/src/buildtool/file_system/file_storage.hpp index 178fa7da..fefd22a7 100644 --- a/src/buildtool/file_system/file_storage.hpp +++ b/src/buildtool/file_system/file_storage.hpp @@ -35,6 +35,11 @@ enum class StoreMode { LastWins }; +struct FileStorageData final { + /// Length of a subdirectory name. + static constexpr size_t kDirectoryNameLength = 2; +}; + template <ObjectType kType, StoreMode kMode, bool kSetEpochTime, @@ -71,7 +76,10 @@ class FileStorage { /// \returns The sharded file path. [[nodiscard]] auto GetPath(std::string const& id) const noexcept -> std::filesystem::path { - return storage_root_ / id.substr(0, 2) / id.substr(2, id.size() - 2); + return storage_root_ / + id.substr(0, FileStorageData::kDirectoryNameLength) / + id.substr(FileStorageData::kDirectoryNameLength, + id.size() - FileStorageData::kDirectoryNameLength); } [[nodiscard]] auto StorageRoot() const noexcept diff --git a/src/buildtool/storage/compactifier.cpp b/src/buildtool/storage/compactifier.cpp index fe3d0fbc..c8d65e8e 100644 --- a/src/buildtool/storage/compactifier.cpp +++ b/src/buildtool/storage/compactifier.cpp @@ -25,6 +25,7 @@ #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/crypto/hasher.hpp" +#include "src/buildtool/file_system/file_storage.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/object_cas.hpp" #include "src/buildtool/file_system/object_type.hpp" @@ -157,12 +158,13 @@ template <ObjectType kType> // Calculate reference hash size: auto const kHashSize = HashFunction::Hasher().GetHashLength(); - static constexpr size_t kDirNameSize = 2; - auto const kFileNameSize = kHashSize - kDirNameSize; + auto const kFileNameSize = + kHashSize - FileStorageData::kDirectoryNameLength; // Check the directory itself is valid: std::string const d_name = directory.filename(); - if (d_name.size() != kDirNameSize or not FromHexString(d_name)) { + if (d_name.size() != FileStorageData::kDirectoryNameLength or + not FromHexString(d_name)) { static constexpr bool kRecursively = true; if (FileSystemManager::RemoveDirectory(directory, kRecursively)) { return true; |