lix-releng-staging/src/nix/copy.cc

66 lines
1.6 KiB
C++
Raw Normal View History

#include "command.hh"
#include "shared.hh"
#include "store-api.hh"
#include "sync.hh"
2016-04-22 16:19:48 +00:00
#include "thread-pool.hh"
#include <atomic>
using namespace nix;
struct CmdCopy : StorePathsCommand
{
std::string srcUri, dstUri;
2017-08-14 13:24:04 +00:00
CheckSigsFlag checkSigs = CheckSigs;
CmdCopy()
{
mkFlag(0, "from", "store-uri", "URI of the source Nix store", &srcUri);
mkFlag(0, "to", "store-uri", "URI of the destination Nix store", &dstUri);
2017-08-14 13:24:04 +00:00
mkFlag()
.longName("no-check-sigs")
.description("do not require that paths are signed by trusted keys")
.handler([&](Strings ss) { checkSigs = NoCheckSigs; });
}
std::string name() override
{
return "copy";
}
std::string description() override
{
return "copy paths between Nix stores";
}
Examples examples() override
{
return {
Example{
"To copy Firefox to the local store to a binary cache in file:///tmp/cache:",
"nix copy --to file:///tmp/cache -r $(type -p firefox)"
},
};
}
ref<Store> createStore() override
{
return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri);
}
void run(ref<Store> srcStore, Paths storePaths) override
{
if (srcUri.empty() && dstUri.empty())
throw UsageError("you must pass '--from' and/or '--to'");
ref<Store> dstStore = dstUri.empty() ? openStore() : openStore(dstUri);
2017-08-14 13:24:04 +00:00
copyPaths(srcStore, dstStore, PathSet(storePaths.begin(), storePaths.end()),
NoRepair, checkSigs);
}
};
static RegisterCommand r1(make_ref<CmdCopy>());