diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-08-14T17·00+0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-08-16T18·56+0200 |
commit | b29b6feaba715432490e275a025b3361a021a99b (patch) | |
tree | 5b7092b0183a135f807fa85539bbf5ea42acf615 /src/libstore/store-api.cc | |
parent | c5e4404580164d3edd043e79cf72bac5bdaecb42 (diff) |
nix copy: Improve progress indicator
It now shows the amount of data copied: [8/1038 copied, 160.4/1590.9 MiB copied] copying path '...'
Diffstat (limited to 'src/libstore/store-api.cc')
-rw-r--r-- | src/libstore/store-api.cc | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 88f27e806dce..2b99a07e2af3 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -569,9 +569,26 @@ void copyStorePath(ref<Store> srcStore, ref<Store> 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<void(size_t)> 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<Store> srcStore, ref<Store> 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<size_t> nrCopied{0}; std::atomic<size_t> nrDone{storePaths.size() - missing.size()}; + std::atomic<uint64_t> bytesExpected{0}; auto showProgress = [&]() { logger->event(evCopyProgress, act, storePaths.size(), nrCopied, nrDone); @@ -626,7 +644,13 @@ void copyPaths(ref<Store> srcStore, ref<Store> 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) { |