2018-03-30 01:56:13 +03:00
|
|
|
#include "command.hh"
|
|
|
|
#include "store-api.hh"
|
2022-03-22 22:14:58 +02:00
|
|
|
#include "make-content-addressed.hh"
|
2019-12-18 18:39:02 +02:00
|
|
|
#include "common-args.hh"
|
|
|
|
#include "json.hh"
|
2018-03-30 01:56:13 +03:00
|
|
|
|
|
|
|
using namespace nix;
|
|
|
|
|
2019-12-18 18:39:02 +02:00
|
|
|
struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
|
2018-03-30 01:56:13 +03:00
|
|
|
{
|
|
|
|
CmdMakeContentAddressable()
|
|
|
|
{
|
2020-07-15 21:05:42 +03:00
|
|
|
realiseMode = Realise::Outputs;
|
2018-03-30 01:56:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string description() override
|
|
|
|
{
|
2020-12-10 18:36:59 +02:00
|
|
|
return "rewrite a path or closure to content-addressed form";
|
2018-03-30 01:56:13 +03:00
|
|
|
}
|
|
|
|
|
2020-12-10 18:36:59 +02:00
|
|
|
std::string doc() override
|
2019-10-21 18:58:17 +03:00
|
|
|
{
|
2020-12-10 18:36:59 +02:00
|
|
|
return
|
|
|
|
#include "make-content-addressable.md"
|
|
|
|
;
|
2019-10-21 18:58:17 +03:00
|
|
|
}
|
2020-05-05 16:18:23 +03:00
|
|
|
|
2021-09-27 11:53:09 +03:00
|
|
|
void run(ref<Store> store, StorePaths && storePaths) override
|
2018-03-30 01:56:13 +03:00
|
|
|
{
|
2022-03-22 22:14:58 +02: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-30 01:56:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-24 21:38:56 +03:00
|
|
|
static auto rCmdMakeContentAddressable = registerCommand2<CmdMakeContentAddressable>({"store", "make-content-addressable"});
|