aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-07-10 15:56:24 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-07-10 15:56:24 +0200
commit8efa23bb996161af74f89401902450e51e9d4b54 (patch)
tree50e82f794cc429419e6068057f226610d02cfe98
parent5dff49f661cd221fc457d1a4660cd36f28266dc5 (diff)
Avoid a redundant hash
-rw-r--r--src/libstore/store-api.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 46587a49a..8d46bb436 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -229,14 +229,17 @@ ValidPathInfo Store::addToStoreSlow(std::string_view name, const Path & srcPath,
/* FIXME: inefficient: we're reading/hashing 'tmpFile' three
times. */
+ auto [narHash, narSize] = hashPath(htSHA256, srcPath);
+
auto hash = method == FileIngestionMethod::Recursive
- ? hashPath(hashAlgo, srcPath).first
+ ? hashAlgo == htSHA256
+ ? narHash
+ : hashPath(hashAlgo, srcPath).first
: hashFile(hashAlgo, srcPath);
if (expectedCAHash && expectedCAHash != hash)
throw Error("hash mismatch for '%s'", srcPath);
- auto [narHash, narSize] = hashPath(htSHA256, srcPath);
ValidPathInfo info(makeFixedOutputPath(method, hash, name));
info.narHash = narHash;
info.narSize = narSize;