aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/local-store.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2021-11-30 21:48:43 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2021-11-30 22:11:46 +0000
commit2f5c913d4a21c60799290d6efe769d188c57b906 (patch)
treeff1b7046ef4c1ccb19e151560d96b69b1515261e /src/libstore/local-store.cc
parent95157b4e664dc6f4dece15beac6fa1143086323e (diff)
Fix #5299
No matter what, we need to resize the buffer to not have any scratch space after we do the `read`. In the end of file case, `got` will be 0 from it's initial value. Before, we forgot to resize in the EOF case with the break. Yes, we know we didn't recieve any data in that case, but we still have the scatch space to undo. Co-Authored-By: Will Fancher <Will.Fancher@Obsidian.Systems>
Diffstat (limited to 'src/libstore/local-store.cc')
-rw-r--r--src/libstore/local-store.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 64019314f..3a1688272 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -8,6 +8,7 @@
#include "references.hh"
#include "callback.hh"
#include "topo-sort.hh"
+#include "finally.hh"
#include <iostream>
#include <algorithm>
@@ -1333,13 +1334,15 @@ StorePath LocalStore::addToStoreFromDump(Source & source0, const string & name,
auto want = std::min(chunkSize, settings.narBufferSize - oldSize);
dump.resize(oldSize + want);
auto got = 0;
+ Finally cleanup([&]() {
+ dump.resize(oldSize + got);
+ });
try {
got = source.read(dump.data() + oldSize, want);
} catch (EndOfFile &) {
inMemory = true;
break;
}
- dump.resize(oldSize + got);
}
std::unique_ptr<AutoDelete> delTempDir;