2018-03-29 22:56:13 +00:00
|
|
|
#include "command.hh"
|
|
|
|
#include "store-api.hh"
|
2022-03-22 20:14:58 +00:00
|
|
|
#include "make-content-addressed.hh"
|
2019-12-18 16:39:02 +00:00
|
|
|
#include "common-args.hh"
|
|
|
|
#include "json.hh"
|
2018-03-29 22:56:13 +00:00
|
|
|
|
|
|
|
using namespace nix;
|
|
|
|
|
2022-03-22 20:54:49 +00:00
|
|
|
struct CmdMakeContentAddressed : StorePathsCommand, MixJSON
|
2018-03-29 22:56:13 +00:00
|
|
|
{
|
2022-03-22 20:54:49 +00:00
|
|
|
CmdMakeContentAddressed()
|
2018-03-29 22:56:13 +00:00
|
|
|
{
|
2020-07-15 18:05:42 +00:00
|
|
|
realiseMode = Realise::Outputs;
|
2018-03-29 22:56:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string description() override
|
|
|
|
{
|
2020-12-10 16:36:59 +00:00
|
|
|
return "rewrite a path or closure to content-addressed form";
|
2018-03-29 22:56:13 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 16:36:59 +00:00
|
|
|
std::string doc() override
|
2019-10-21 15:58:17 +00:00
|
|
|
{
|
2020-12-10 16:36:59 +00:00
|
|
|
return
|
2022-03-22 20:54:49 +00:00
|
|
|
#include "make-content-addressed.md"
|
2020-12-10 16:36:59 +00:00
|
|
|
;
|
2019-10-21 15:58:17 +00:00
|
|
|
}
|
2020-05-05 13:18:23 +00:00
|
|
|
|
2021-09-27 08:53:09 +00:00
|
|
|
void run(ref<Store> store, StorePaths && storePaths) override
|
2018-03-29 22:56:13 +00:00
|
|
|
{
|
2022-03-22 20:14:58 +00:00
|
|
|
auto remappings = makeContentAddressed(*store, *store,
|
|
|
|
StorePathSet(storePaths.begin(), storePaths.end()));
|
|
|
|
|
|
|
|
if (json) {
|
|
|
|
JSONObject jsonRoot(std::cout);
|
|
|
|
JSONObject jsonRewrites(jsonRoot.object("rewrites"));
|
|
|
|
for (auto & path : storePaths) {
|
|
|
|
auto i = remappings.find(path);
|
|
|
|
assert(i != remappings.end());
|
|
|
|
jsonRewrites.attr(store->printStorePath(path), store->printStorePath(i->second));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (auto & path : storePaths) {
|
|
|
|
auto i = remappings.find(path);
|
|
|
|
assert(i != remappings.end());
|
|
|
|
notice("rewrote '%s' to '%s'",
|
|
|
|
store->printStorePath(path),
|
|
|
|
store->printStorePath(i->second));
|
2018-03-29 22:56:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-22 20:54:49 +00:00
|
|
|
static auto rCmdMakeContentAddressed = registerCommand2<CmdMakeContentAddressed>({"store", "make-content-addressed"});
|