aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/local-store.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-07-16 13:39:03 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-07-16 13:39:27 +0000
commit3dcca18c30cbc09652f5ac644a9f8750f9ced0c9 (patch)
tree4f3d1493b13f44f62740a7b22b7a4fdc2c114c2e /src/libstore/local-store.cc
parent5602637d9ea195784368e99a226718fc95e6b978 (diff)
Fix bug in TeeSource
We use this to simplify `LocalStore::addToStoreFromDump`. Also, hope I fixed build error with old clang (used in Darwin CI).
Diffstat (limited to 'src/libstore/local-store.cc')
-rw-r--r--src/libstore/local-store.cc14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index b2b5afadd..96d10d9ba 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -1047,11 +1047,12 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath,
}
-StorePath LocalStore::addToStoreFromDump(Source & source, const string & name,
+StorePath LocalStore::addToStoreFromDump(Source & source0, const string & name,
FileIngestionMethod method, HashType hashAlgo, RepairFlag repair)
{
/* For computing the store path. */
auto hashSink = std::make_unique<HashSink>(hashAlgo);
+ TeeSource source { source0, *hashSink };
/* Read the source path into memory, but only if it's up to
narBufferSize bytes. If it's larger, write it to a temporary
@@ -1078,8 +1079,6 @@ StorePath LocalStore::addToStoreFromDump(Source & source, const string & name,
inMemory = true;
break;
}
- /* Start hashing as we get data */
- (*hashSink)((const uint8_t *) dump.data() + oldSize, got);
dump.resize(oldSize + got);
}
@@ -1087,14 +1086,9 @@ StorePath LocalStore::addToStoreFromDump(Source & source, const string & name,
Path tempPath;
if (!inMemory) {
+ /* Drain what we pulled so far, and then keep on pulling */
StringSource dumpSource { dump };
- TeeSource rest { source, *hashSink };
- ChainSource bothSource {
- .source1 = dumpSource,
- /* Continue hashing what's left, but don't rehash what we
- already did. */
- .source2 = rest,
- };
+ ChainSource bothSource { dumpSource, source };
auto tempDir = createTempDir(realStoreDir, "add");
delTempDir = std::make_unique<AutoDelete>(tempDir);