From 558eda01154d47b3c88983576eedb582185b2201 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 16 Mar 2017 14:25:54 +0100 Subject: nix copy: Make -r option use the "from" store Previously, we tried to compute the closure in the local store, which obviously doesn't work. --- src/nix/command.cc | 7 ++++++- src/nix/command.hh | 1 + src/nix/copy.cc | 10 +++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/nix/command.cc b/src/nix/command.cc index 5a8288da912f..a1b2c120a5d9 100644 --- a/src/nix/command.cc +++ b/src/nix/command.cc @@ -79,9 +79,14 @@ StoreCommand::StoreCommand() mkFlag(0, "store", "store-uri", "URI of the Nix store to use", &storeUri); } +ref StoreCommand::createStore() +{ + return openStore(storeUri); +} + void StoreCommand::run() { - run(openStore(storeUri)); + run(createStore()); } StorePathsCommand::StorePathsCommand() diff --git a/src/nix/command.hh b/src/nix/command.hh index a29cdcf7f50f..fa6c21abf8ad 100644 --- a/src/nix/command.hh +++ b/src/nix/command.hh @@ -33,6 +33,7 @@ struct StoreCommand : virtual Command std::string storeUri; StoreCommand(); void run() override; + virtual ref createStore(); virtual void run(ref) = 0; }; diff --git a/src/nix/copy.cc b/src/nix/copy.cc index 083dc3506863..b2165cb8f85c 100644 --- a/src/nix/copy.cc +++ b/src/nix/copy.cc @@ -38,13 +38,17 @@ struct CmdCopy : StorePathsCommand }; } - void run(ref store, Paths storePaths) override + ref createStore() override + { + return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri); + } + + void run(ref srcStore, Paths storePaths) override { if (srcUri.empty() && dstUri.empty()) throw UsageError("you must pass ‘--from’ and/or ‘--to’"); - ref srcStore = srcUri.empty() ? store : openStore(srcUri); - ref dstStore = dstUri.empty() ? store : openStore(dstUri); + ref dstStore = dstUri.empty() ? openStore() : openStore(dstUri); copyPaths(srcStore, dstStore, PathSet(storePaths.begin(), storePaths.end())); } -- cgit 1.4.1