2016-04-22 15:16:48 +03:00
|
|
|
|
#include "command.hh"
|
|
|
|
|
#include "shared.hh"
|
|
|
|
|
#include "store-api.hh"
|
|
|
|
|
#include "sync.hh"
|
2016-04-22 19:19:48 +03:00
|
|
|
|
#include "thread-pool.hh"
|
2016-04-22 15:16:48 +03:00
|
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
|
|
|
|
|
using namespace nix;
|
|
|
|
|
|
|
|
|
|
struct CmdCopy : StorePathsCommand
|
|
|
|
|
{
|
|
|
|
|
std::string srcUri, dstUri;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)"
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-16 15:25:54 +02:00
|
|
|
|
ref<Store> createStore() override
|
|
|
|
|
{
|
|
|
|
|
return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void run(ref<Store> srcStore, Paths storePaths) override
|
2016-04-22 15:16:48 +03:00
|
|
|
|
{
|
|
|
|
|
if (srcUri.empty() && dstUri.empty())
|
|
|
|
|
throw UsageError("you must pass ‘--from’ and/or ‘--to’");
|
|
|
|
|
|
2017-03-16 15:25:54 +02:00
|
|
|
|
ref<Store> dstStore = dstUri.empty() ? openStore() : openStore(dstUri);
|
2016-04-22 15:16:48 +03:00
|
|
|
|
|
2017-03-16 14:50:01 +02:00
|
|
|
|
copyPaths(srcStore, dstStore, PathSet(storePaths.begin(), storePaths.end()));
|
2016-04-22 15:16:48 +03:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static RegisterCommand r1(make_ref<CmdCopy>());
|