nix verify: Restore the progress indicator

This commit is contained in:
Eelco Dolstra 2017-08-16 19:23:46 +02:00
parent b4ed97e3a3
commit c2cab20732
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
3 changed files with 43 additions and 14 deletions

View file

@ -22,11 +22,14 @@ typedef enum {
actBuilds = 104, actBuilds = 104,
actBuild = 105, actBuild = 105,
actOptimiseStore = 106, actOptimiseStore = 106,
actVerifyPaths = 107,
} ActivityType; } ActivityType;
typedef enum { typedef enum {
resFileLinked = 100, resFileLinked = 100,
resBuildLogLine = 101, resBuildLogLine = 101,
resUntrustedPath = 102,
resCorruptedPath = 103,
} ResultType; } ResultType;
typedef uint64_t ActivityId; typedef uint64_t ActivityId;

View file

@ -57,6 +57,8 @@ private:
std::map<ActivityType, ActivitiesByType> activitiesByType; std::map<ActivityType, ActivitiesByType> activitiesByType;
uint64_t filesLinked = 0, bytesLinked = 0; uint64_t filesLinked = 0, bytesLinked = 0;
uint64_t corruptedPaths = 0, untrustedPaths = 0;
}; };
Sync<State> state_; Sync<State> state_;
@ -179,6 +181,16 @@ public:
update(*state); update(*state);
} }
} }
else if (type == resUntrustedPath) {
state->untrustedPaths++;
update(*state);
}
else if (type == resCorruptedPath) {
state->corruptedPaths++;
update(*state);
}
} }
void update() void update()
@ -285,6 +297,19 @@ public:
} }
} }
// FIXME: don't show "done" paths in green.
showActivity(actVerifyPaths, "%s paths verified");
if (state.corruptedPaths) {
if (!res.empty()) res += ", ";
res += fmt(ANSI_RED "%d corrupted" ANSI_NORMAL, state.corruptedPaths);
}
if (state.untrustedPaths) {
if (!res.empty()) res += ", ";
res += fmt(ANSI_RED "%d untrusted" ANSI_NORMAL, state.untrustedPaths);
}
return res; return res;
} }
}; };

View file

@ -61,16 +61,17 @@ struct CmdVerify : StorePathsCommand
auto publicKeys = getDefaultPublicKeys(); auto publicKeys = getDefaultPublicKeys();
Activity act(*logger, actVerifyPaths);
std::atomic<size_t> done{0}; std::atomic<size_t> done{0};
std::atomic<size_t> untrusted{0}; std::atomic<size_t> untrusted{0};
std::atomic<size_t> corrupted{0}; std::atomic<size_t> corrupted{0};
std::atomic<size_t> failed{0}; std::atomic<size_t> failed{0};
std::atomic<size_t> active{0};
std::string doneLabel("paths checked"); auto update = [&]() {
std::string untrustedLabel("untrusted"); act.progress(done, storePaths.size(), active, failed);
std::string corruptedLabel("corrupted"); };
std::string failedLabel("failed");
//logger->setExpected(doneLabel, storePaths.size());
ThreadPool pool; ThreadPool pool;
@ -78,7 +79,10 @@ struct CmdVerify : StorePathsCommand
try { try {
checkInterrupt(); checkInterrupt();
//Activity act(*logger, lvlInfo, format("checking '%s'") % storePath); Activity act2(*logger, actUnknown, fmt("checking '%s'", storePath));
MaintainCount<std::atomic<size_t>> mcActive(active);
update();
auto info = store->queryPathInfo(storePath); auto info = store->queryPathInfo(storePath);
@ -90,8 +94,8 @@ struct CmdVerify : StorePathsCommand
auto hash = sink.finish(); auto hash = sink.finish();
if (hash.first != info->narHash) { if (hash.first != info->narHash) {
//logger->incProgress(corruptedLabel); corrupted++;
corrupted = 1; act2.result(resCorruptedPath, info->path);
printError( printError(
format("path '%s' was modified! expected hash '%s', got '%s'") format("path '%s' was modified! expected hash '%s', got '%s'")
% info->path % info->narHash.to_string() % hash.first.to_string()); % info->path % info->narHash.to_string() % hash.first.to_string());
@ -142,21 +146,21 @@ struct CmdVerify : StorePathsCommand
} }
if (!good) { if (!good) {
//logger->incProgress(untrustedLabel);
untrusted++; untrusted++;
act2.result(resUntrustedPath, info->path);
printError(format("path '%s' is untrusted") % info->path); printError(format("path '%s' is untrusted") % info->path);
} }
} }
//logger->incProgress(doneLabel);
done++; done++;
} catch (Error & e) { } catch (Error & e) {
printError(format(ANSI_RED "error:" ANSI_NORMAL " %s") % e.what()); printError(format(ANSI_RED "error:" ANSI_NORMAL " %s") % e.what());
//logger->incProgress(failedLabel);
failed++; failed++;
} }
update();
}; };
for (auto & storePath : storePaths) for (auto & storePath : storePaths)
@ -164,9 +168,6 @@ struct CmdVerify : StorePathsCommand
pool.process(); pool.process();
printInfo(format("%d paths checked, %d untrusted, %d corrupted, %d failed")
% done % untrusted % corrupted % failed);
throw Exit( throw Exit(
(corrupted ? 1 : 0) | (corrupted ? 1 : 0) |
(untrusted ? 2 : 0) | (untrusted ? 2 : 0) |