[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/03: SQUASHME build trace for hash mismatches
From: |
Ludovic Courtès |
Subject: |
01/03: SQUASHME build trace for hash mismatches |
Date: |
Thu, 27 Sep 2018 12:33:37 -0400 (EDT) |
civodul pushed a commit to branch wip-ui
in repository guix.
commit c838b8d309255e0691f846f1b4a19081927b7cf5
Author: Ludovic Courtès <address@hidden>
Date: Thu Sep 27 18:07:29 2018 +0200
SQUASHME build trace for hash mismatches
* nix/libstore/build.cc (DerivationGoal::registerOutputs)
(SubstitutionGoal::finished): Print a "@ hash-mismatch" trace before
throwing.
---
guix/status.scm | 9 +++++++++
nix/libstore/build.cc | 27 +++++++++++++++------------
2 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/guix/status.scm b/guix/status.scm
index 96abc8f..8cec042 100644
--- a/guix/status.scm
+++ b/guix/status.scm
@@ -365,6 +365,15 @@ addition to build events."
(('substituter-failed item _ ...)
(format port (failure (G_ "substitution of ~a failed")) item)
(newline port))
+ (('hash-mismatch item algo expected actual _ ...)
+ ;; TRANSLATORS: The final string looks like "sha256 hash mismatch for
+ ;; /gnu/store/…-sth:", where "sha256" is the hash algorithm.
+ (format port (failure (G_ "~a hash mismatch for ~a:")) algo item)
+ (newline port)
+ (format port (info (G_ "\
+ expected hash: ~a
+ actual hash: ~a~%"))
+ expected actual))
(('build-log line)
;; The daemon prefixes early messages coming with 'guix substitute' with
;; "substitute:". These are useful ("updating substitutes from URL"), so
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index c7f3249..b2c319f 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -2466,13 +2466,13 @@ void DerivationGoal::registerOutputs()
/* Check the hash. */
Hash h2 = recursive ? hashPath(ht, actualPath).first :
hashFile(ht, actualPath);
- if (h != h2)
- throw BuildError(
- format("%1% hash mismatch for output path `%2%'\n"
- " expected: %3%\n"
- " actual: %4%")
- % i->second.hashAlgo % path
- % printHash16or32(h) % printHash16or32(h2));
+ if (h != h2) {
+ if (settings.printBuildTrace)
+ printMsg(lvlError, format("@ hash-mismatch %1% %2% %3% %4%")
+ % path % i->second.hashAlgo
+ % printHash16or32(h) % printHash16or32(h2));
+ throw BuildError(format("hash mismatch for store item '%1%'")
% path);
+ }
}
/* Get rid of all weird permissions. This also checks that
@@ -3157,11 +3157,14 @@ void SubstitutionGoal::finished()
throw Error(format("unknown hash algorithm in `%1%'") %
expectedHashStr);
Hash expectedHash = parseHash16or32(hashType,
string(expectedHashStr, n + 1));
Hash actualHash = hashType == htSHA256 ? hash.first :
hashPath(hashType, destPath).first;
- if (expectedHash != actualHash)
- throw SubstError(format("hash mismatch in downloaded path
`%1%'\n"
- " expected: %2%\n"
- " actual: %3%")
- % storePath % printHash(expectedHash) %
printHash(actualHash));
+ if (expectedHash != actualHash) {
+ if (settings.printBuildTrace)
+ printMsg(lvlError, format("@ hash-mismatch %1% %2% %3% %4%")
+ % storePath % "sha256"
+ % printHash16or32(expectedHash)
+ % printHash16or32(actualHash));
+ throw SubstError(format("hash mismatch for substituted item
`%1%'") % storePath);
+ }
}
} catch (SubstError & e) {