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. */ /* Wake up the worker loop when we're done. */
Finally updateStats([this]() { outPipe.writeSide.close(); }); Finally updateStats([this]() { outPipe.writeSide.close(); });
StringSink sink; copyStorePath(ref<Store>(sub), ref<Store>(worker.store.shared_from_this()), storePath);
sub->exportPaths({storePath}, false, sink);
StringSource source(*sink.s);
worker.store.importPaths(false, source, 0);
promise.set_value(); promise.set_value();
} catch (...) { } 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 decodeValidPathInfo(std::istream & str, bool hashGiven)
{ {
ValidPathInfo info; ValidPathInfo info;

View file

@ -502,6 +502,11 @@ Path computeStorePathForText(const string & name, const string & s,
const PathSet & references); 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 /* Remove the temporary roots file for this process. Any temporary
root becomes garbage after this point unless it has been registered root becomes garbage after this point unless it has been registered
as a (permanent) root. */ as a (permanent) root. */

View file

@ -28,6 +28,13 @@ public:
throw std::invalid_argument("null pointer cast to ref"); 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 T* operator ->() const
{ {
return &*p; return &*p;

View file

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