1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 16:51:15 +02:00

nix copy: Revive progress bar

This commit is contained in:
Eelco Dolstra 2017-08-14 15:28:16 +02:00
parent dffc3fe43b
commit c5e4404580
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
6 changed files with 99 additions and 2 deletions

View file

@ -135,7 +135,6 @@ struct LegacySSHStore : public Store
if (readInt(conn->from) != 1)
throw Error("failed to add path '%s' to remote host '%s', info.path, host");
}
void narFromPath(const Path & path, Sink & sink) override

View file

@ -565,8 +565,12 @@ void Store::buildPaths(const PathSet & paths, BuildMode buildMode)
void copyStorePath(ref<Store> srcStore, ref<Store> dstStore,
const Path & storePath, RepairFlag repair, CheckSigsFlag checkSigs)
{
Activity act(actCopyPath, fmt("copying path '%s'", storePath));
auto info = srcStore->queryPathInfo(storePath);
//act->progress(0, info->size());
StringSink sink;
srcStore->narFromPath({storePath}, sink);
@ -600,13 +604,28 @@ void copyPaths(ref<Store> srcStore, ref<Store> dstStore, const PathSet & storePa
for (auto & path : storePaths)
if (!valid.count(path)) missing.insert(path);
Activity act;
logger->event(evCopyStarted, act);
std::atomic<size_t> nrCopied{0};
std::atomic<size_t> nrDone{storePaths.size() - missing.size()};
auto showProgress = [&]() {
logger->event(evCopyProgress, act, storePaths.size(), nrCopied, nrDone);
};
ThreadPool pool;
processGraph<Path>(pool,
PathSet(missing.begin(), missing.end()),
[&](const Path & storePath) {
if (dstStore->isValidPath(storePath)) return PathSet();
if (dstStore->isValidPath(storePath)) {
nrDone++;
showProgress();
return PathSet();
}
return srcStore->queryPathInfo(storePath)->references;
},
@ -616,7 +635,12 @@ void copyPaths(ref<Store> srcStore, ref<Store> dstStore, const PathSet & storePa
if (!dstStore->isValidPath(storePath)) {
printInfo("copying '%s'...", storePath);
copyStorePath(srcStore, dstStore, storePath, repair, checkSigs);
nrCopied++;
}
nrDone++;
showProgress();
});
}