nix store make-content-addressed: Support --from / --to

This commit is contained in:
Eelco Dolstra 2022-03-22 23:40:04 +01:00
parent 98658ae9d2
commit e5f7029ba4
2 changed files with 9 additions and 7 deletions

View file

@ -133,7 +133,7 @@ static RegisterPrimOp primop_fetchClosure({
you can use `nix store make-content-addressed`: you can use `nix store make-content-addressed`:
```console ```console
# nix store make-content-addressed /nix/store/r2jd6ygnmirm2g803mksqqjm4y39yi6i-git-2.33.1 # nix store make-content-addressed --from https://cache.nixos.org /nix/store/r2jd6ygnmirm2g803mksqqjm4y39yi6i-git-2.33.1
rewrote '/nix/store/r2jd6ygnmirm2g803mksqqjm4y39yi6i-git-2.33.1' to '/nix/store/ldbhlwhh39wha58rm61bkiiwm6j7211j-git-2.33.1' rewrote '/nix/store/r2jd6ygnmirm2g803mksqqjm4y39yi6i-git-2.33.1' to '/nix/store/ldbhlwhh39wha58rm61bkiiwm6j7211j-git-2.33.1'
``` ```

View file

@ -6,7 +6,7 @@
using namespace nix; using namespace nix;
struct CmdMakeContentAddressed : StorePathsCommand, MixJSON struct CmdMakeContentAddressed : virtual CopyCommand, virtual StorePathsCommand, MixJSON
{ {
CmdMakeContentAddressed() CmdMakeContentAddressed()
{ {
@ -25,9 +25,11 @@ struct CmdMakeContentAddressed : StorePathsCommand, MixJSON
; ;
} }
void run(ref<Store> store, StorePaths && storePaths) override void run(ref<Store> srcStore, StorePaths && storePaths) override
{ {
auto remappings = makeContentAddressed(*store, *store, auto dstStore = dstUri.empty() ? openStore() : openStore(dstUri);
auto remappings = makeContentAddressed(*srcStore, *dstStore,
StorePathSet(storePaths.begin(), storePaths.end())); StorePathSet(storePaths.begin(), storePaths.end()));
if (json) { if (json) {
@ -36,15 +38,15 @@ struct CmdMakeContentAddressed : StorePathsCommand, MixJSON
for (auto & path : storePaths) { for (auto & path : storePaths) {
auto i = remappings.find(path); auto i = remappings.find(path);
assert(i != remappings.end()); assert(i != remappings.end());
jsonRewrites.attr(store->printStorePath(path), store->printStorePath(i->second)); jsonRewrites.attr(srcStore->printStorePath(path), srcStore->printStorePath(i->second));
} }
} else { } else {
for (auto & path : storePaths) { for (auto & path : storePaths) {
auto i = remappings.find(path); auto i = remappings.find(path);
assert(i != remappings.end()); assert(i != remappings.end());
notice("rewrote '%s' to '%s'", notice("rewrote '%s' to '%s'",
store->printStorePath(path), srcStore->printStorePath(path),
store->printStorePath(i->second)); srcStore->printStorePath(i->second));
} }
} }
} }