diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2022-09-06 12:58:31 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2022-12-21 14:59:04 +0100 |
commit | 407cb8df0374511d4146922d7932ddd71066e8da (patch) | |
tree | a4824ff79bcf8bd4b4d4c9c10a4f3efdea52c290 /src/other_tools/just_mr/utils.cpp | |
parent | b17cd0c090d09405ca5107b3a0f9604f6d043e4d (diff) | |
download | justbuild-407cb8df0374511d4146922d7932ddd71066e8da.tar.gz |
Just-MR: Add archive content-in-CAS map
Calls libcurl to fetch the archives from the internet.
Diffstat (limited to 'src/other_tools/just_mr/utils.cpp')
-rw-r--r-- | src/other_tools/just_mr/utils.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/other_tools/just_mr/utils.cpp b/src/other_tools/just_mr/utils.cpp index 3470b7db..4d668bc6 100644 --- a/src/other_tools/just_mr/utils.cpp +++ b/src/other_tools/just_mr/utils.cpp @@ -14,6 +14,8 @@ #include "src/other_tools/just_mr/utils.hpp" +#include "src/buildtool/execution_api/local/file_storage.hpp" +#include "src/buildtool/execution_api/local/local_cas.hpp" #include "src/utils/cpp/path.hpp" namespace JustMR::Utils { @@ -74,4 +76,28 @@ auto WriteTreeIDFile(std::filesystem::path const& tree_id_file, return FileSystemManager::Rename(tmp_file.string(), tree_id_file); } +auto AddToCAS(std::string const& data) noexcept + -> std::optional<std::filesystem::path> { + // get file CAS instance + auto const& casf = LocalCAS<ObjectType::File>::Instance(); + // write to casf + auto digest = casf.StoreBlobFromBytes(data); + if (digest) { + return casf.BlobPath(*digest); + } + return std::nullopt; +} + +void AddDistfileToCAS(std::filesystem::path const& distfile, + JustMR::PathsPtr const& just_mr_paths) noexcept { + auto const& casf = LocalCAS<ObjectType::File>::Instance(); + for (auto const& dirpath : just_mr_paths->distdirs) { + auto candidate = dirpath / distfile; + if (FileSystemManager::Exists(candidate)) { + // try to add to CAS + [[maybe_unused]] auto digest = casf.StoreBlobFromFile(candidate); + } + } +} + } // namespace JustMR::Utils |