aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-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;
}
};