diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-03-22 21:54:49 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2022-03-24 21:33:33 +0100 |
commit | 5acaf13d3564f689e5461f29a9cc5958809d5e93 (patch) | |
tree | 89c5ba12c665b9f3a68b1c17653d3532267b0125 /src/nix/make-content-addressed.cc | |
parent | f18607549ce38545b1d754ed93f3b7c5417970d8 (diff) |
Rename 'nix store make-content-addressable' to 'nix store make-content-addressed'
Diffstat (limited to 'src/nix/make-content-addressed.cc')
-rw-r--r-- | src/nix/make-content-addressed.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/nix/make-content-addressed.cc b/src/nix/make-content-addressed.cc new file mode 100644 index 000000000..dc0447cb8 --- /dev/null +++ b/src/nix/make-content-addressed.cc @@ -0,0 +1,53 @@ +#include "command.hh" +#include "store-api.hh" +#include "make-content-addressed.hh" +#include "common-args.hh" +#include "json.hh" + +using namespace nix; + +struct CmdMakeContentAddressed : StorePathsCommand, MixJSON +{ + CmdMakeContentAddressed() + { + realiseMode = Realise::Outputs; + } + + std::string description() override + { + return "rewrite a path or closure to content-addressed form"; + } + + std::string doc() override + { + return + #include "make-content-addressed.md" + ; + } + + void run(ref<Store> store, StorePaths && storePaths) override + { + 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)); + } + } + } +}; + +static auto rCmdMakeContentAddressed = registerCommand2<CmdMakeContentAddressed>({"store", "make-content-addressed"}); |