From b29b6feaba715432490e275a025b3361a021a99b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 14 Aug 2017 19:00:03 +0200 Subject: nix copy: Improve progress indicator It now shows the amount of data copied: [8/1038 copied, 160.4/1590.9 MiB copied] copying path '...' --- src/libstore/store-api.cc | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src/libstore/store-api.cc') diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 88f27e806d..2b99a07e2a 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -569,9 +569,26 @@ void copyStorePath(ref srcStore, ref dstStore, auto info = srcStore->queryPathInfo(storePath); - //act->progress(0, info->size()); + uint64_t total = 0; - StringSink sink; + auto progress = [&](size_t len) { + total += len; + act.progress(total, info->narSize); + }; + + struct MyStringSink : StringSink + { + typedef std::function Callback; + Callback callback; + MyStringSink(Callback callback) : callback(callback) { } + void operator () (const unsigned char * data, size_t len) override + { + StringSink::operator ()(data, len); + callback(len); + }; + }; + + MyStringSink sink(progress); srcStore->narFromPath({storePath}, sink); if (!info->narHash && !checkSigs) { @@ -604,12 +621,13 @@ void copyPaths(ref srcStore, ref dstStore, const PathSet & storePa for (auto & path : storePaths) if (!valid.count(path)) missing.insert(path); - Activity act; + Activity act(actUnknown); logger->event(evCopyStarted, act); std::atomic nrCopied{0}; std::atomic nrDone{storePaths.size() - missing.size()}; + std::atomic bytesExpected{0}; auto showProgress = [&]() { logger->event(evCopyProgress, act, storePaths.size(), nrCopied, nrDone); @@ -626,7 +644,13 @@ void copyPaths(ref srcStore, ref dstStore, const PathSet & storePa showProgress(); return PathSet(); } - return srcStore->queryPathInfo(storePath)->references; + + auto info = srcStore->queryPathInfo(storePath); + + bytesExpected += info->narSize; + logger->event(evSetExpected, act, actCopyPath, bytesExpected); + + return info->references; }, [&](const Path & storePath) { -- cgit 1.4.1