Add a copyStorePath() utility function

This commit is contained in:
Eelco Dolstra 2016-05-03 14:45:50 +02:00
parent 80f739b571
commit dfebfc835f
5 changed files with 27 additions and 10 deletions

View file

@ -3222,11 +3222,7 @@ void SubstitutionGoal::tryToRun()
/* Wake up the worker loop when we're done. */
Finally updateStats([this]() { outPipe.writeSide.close(); });
StringSink sink;
sub->exportPaths({storePath}, false, sink);
StringSource source(*sink.s);
worker.store.importPaths(false, source, 0);
copyStorePath(ref<Store>(sub), ref<Store>(worker.store.shared_from_this()), storePath);
promise.set_value();
} catch (...) {

View file

@ -357,6 +357,19 @@ const Store::Stats & Store::getStats()
}
void copyStorePath(ref<Store> srcStore, ref<Store> dstStore,
const Path & storePath)
{
auto info = srcStore->queryPathInfo(storePath);
StringSink sink;
srcStore->exportPaths({storePath}, false, sink);
StringSource source(*sink.s);
dstStore->importPaths(false, source, 0);
}
ValidPathInfo decodeValidPathInfo(std::istream & str, bool hashGiven)
{
ValidPathInfo info;

View file

@ -502,6 +502,11 @@ Path computeStorePathForText(const string & name, const string & s,
const PathSet & references);
/* Copy a path from one store to another. */
void copyStorePath(ref<Store> srcStore, ref<Store> dstStore,
const Path & storePath);
/* Remove the temporary roots file for this process. Any temporary
root becomes garbage after this point unless it has been registered
as a (permanent) root. */

View file

@ -28,6 +28,13 @@ public:
throw std::invalid_argument("null pointer cast to ref");
}
explicit ref<T>(T * p)
: p(p)
{
if (!p)
throw std::invalid_argument("null pointer cast to ref");
}
T* operator ->() const
{
return &*p;

View file

@ -65,11 +65,7 @@ struct CmdCopy : StorePathsCommand
if (!dstStore->isValidPath(storePath)) {
Activity act(*logger, lvlInfo, format("copying %s...") % storePath);
StringSink sink;
srcStore->exportPaths({storePath}, false, sink);
StringSource source(*sink.s);
dstStore->importPaths(false, source, 0);
copyStorePath(srcStore, dstStore, storePath);
logger->incProgress(copiedLabel);
} else