summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/buildtool/storage/TARGETS3
-rw-r--r--src/buildtool/storage/fs_utils.cpp17
-rw-r--r--src/buildtool/storage/fs_utils.hpp7
3 files changed, 26 insertions, 1 deletions
diff --git a/src/buildtool/storage/TARGETS b/src/buildtool/storage/TARGETS
index 38a118cf..9bde508c 100644
--- a/src/buildtool/storage/TARGETS
+++ b/src/buildtool/storage/TARGETS
@@ -70,7 +70,8 @@
]
, "stage": ["src", "buildtool", "storage"]
, "private-deps":
- [ ["src/buildtool/file_system", "file_system_manager"]
+ [ ["@", "json", "", "json"]
+ , ["src/buildtool/file_system", "file_system_manager"]
, ["src/utils/cpp", "path"]
, "config"
, "storage"
diff --git a/src/buildtool/storage/fs_utils.cpp b/src/buildtool/storage/fs_utils.cpp
index f6055579..83167181 100644
--- a/src/buildtool/storage/fs_utils.cpp
+++ b/src/buildtool/storage/fs_utils.cpp
@@ -14,6 +14,10 @@
#include "src/buildtool/storage/fs_utils.hpp"
+#include <unordered_map>
+#include <utility>
+
+#include "nlohmann/json.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/storage.hpp"
@@ -63,6 +67,19 @@ auto GetArchiveTreeIDFile(std::string const& repo_type,
return StorageConfig::BuildRoot() / "tree-map" / repo_type / content;
}
+auto GetForeignFileTreeIDFile(std::string const& content,
+ std::string const& name,
+ bool executable) noexcept
+ -> std::filesystem::path {
+ return GetDistdirTreeIDFile(
+ HashFunction::ComputeBlobHash(
+ nlohmann::json(
+ std::unordered_map<std::string, std::pair<std::string, bool>>{
+ {name, {content, executable}}})
+ .dump())
+ .HexString());
+}
+
auto GetDistdirTreeIDFile(std::string const& content) noexcept
-> std::filesystem::path {
return StorageConfig::BuildRoot() / "distfiles-tree-map" / content;
diff --git a/src/buildtool/storage/fs_utils.hpp b/src/buildtool/storage/fs_utils.hpp
index ba66dac5..6e8f640b 100644
--- a/src/buildtool/storage/fs_utils.hpp
+++ b/src/buildtool/storage/fs_utils.hpp
@@ -49,6 +49,13 @@ namespace StorageUtils {
std::string const& content) noexcept
-> std::filesystem::path;
+/// \brief Get the path to the file storing the tree id of an archive
+/// content.
+[[nodiscard]] auto GetForeignFileTreeIDFile(std::string const& content,
+ std::string const& name,
+ bool executable) noexcept
+ -> std::filesystem::path;
+
/// \brief Get the path to the file storing the tree id of a distdir list
/// content.
[[nodiscard]] auto GetDistdirTreeIDFile(std::string const& content) noexcept