aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libstore/local-store.cc14
-rw-r--r--src/libutil/serialise.hh2
2 files changed, 5 insertions, 11 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);
diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh
index aa6b42597..5d9acf887 100644
--- a/src/libutil/serialise.hh
+++ b/src/libutil/serialise.hh
@@ -189,7 +189,7 @@ struct TeeSource : Source
size_t read(unsigned char * data, size_t len)
{
size_t n = orig.read(data, len);
- sink(data, len);
+ sink(data, n);
return n;
}
};