daemon: Let 'guix substitute' perform hash checks.
authorLudovic Courtès <ludo@gnu.org>
Sun, 13 Dec 2020 21:46:03 +0000 (22:46 +0100)
committerLudovic Courtès <ludo@gnu.org>
Sat, 19 Dec 2020 22:25:00 +0000 (23:25 +0100)
commit9dfa20a22ae0be3d3b01a7b3d422af97428c627e
tree2ea3e2af7685f0f0b496434841dffba3368d69c7
parent6d955f1731dc593a51625b455882102a67d95e1a
daemon: Let 'guix substitute' perform hash checks.

This way, the hash of the store item can be computed as it is restored,
thereby avoiding an additional file tree traversal ('hashPath' call)
later on in the daemon.  Consequently, it should reduce latency between
subsequent substitute downloads.

This is a followup to 5ff521452b9ec2aae9ed8e4bb7bdc250a581f203.

* guix/scripts/substitute.scm (narinfo-hash-algorithm+value): New
procedure.
(process-substitution): Wrap INPUT into a hash input port, 'hashed', and
read from it.  Compare the actual and expected hashes, and print a
"hash-mismatch" status line when they differ.  When they match, print
not just "success" but also the nar hash and size.
* nix/libstore/build.cc (class SubstitutionGoal)[expectedHashStr]:
Remove.
(SubstitutionGoal::finished): Tokenize 'status'.  Parse it and handle
"success" and "hash-mismatch" accordingly.  Call 'hashPath' only when
the returned hash is not SHA256.
(SubstitutionGoal::handleChildOutput): Remove 'expectedHashStr'
handling.
* tests/substitute.scm ("substitute, invalid hash"): Rename to...
("substitute, invalid narinfo hash"): ... this.
("substitute, invalid hash"): New test.
guix/scripts/substitute.scm
nix/libstore/build.cc
tests/substitute.scm