about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libstore/local-store.cc5
-rw-r--r--tests/binary-cache.sh2
2 files changed, 6 insertions, 1 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index acd02eb48adc..8608b39ec5bd 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -904,6 +904,11 @@ void LocalStore::invalidatePath(State & state, const Path & path)
 
 void LocalStore::addToStore(const ValidPathInfo & info, const std::string & nar, bool repair)
 {
+    Hash h = hashString(htSHA256, nar);
+    if (h != info.narHash)
+        throw Error(format("hash mismatch importing path ‘%s’; expected hash ‘%s’, got ‘%s’") %
+            info.path % info.narHash.to_string() % h.to_string());
+
     addTempRoot(info.path);
 
     if (repair || !isValidPath(info.path)) {
diff --git a/tests/binary-cache.sh b/tests/binary-cache.sh
index 5f88c595fdfb..cadd634a2a32 100644
--- a/tests/binary-cache.sh
+++ b/tests/binary-cache.sh
@@ -48,7 +48,7 @@ mkdir -p $TEST_ROOT/empty
 nix-store --dump $TEST_ROOT/empty | xz > $nar
 
 nix-build --option binary-caches "file://$cacheDir" dependencies.nix -o $TEST_ROOT/result 2>&1 | tee $TEST_ROOT/log
-grep -q "hash mismatch in downloaded path" $TEST_ROOT/log
+grep -q "hash mismatch" $TEST_ROOT/log
 
 mv $nar.good $nar