mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 11:36:03 +01:00
Merge pull request #14323 from NixOS/skip-nar-parse
addToStore(): Don't parse the NAR * StringSource: Implement skip() This is slightly faster than doing a read() into a buffer just to discard the data. * LocalStore::addToStore(): Skip unnecessary NARs rather than parsing them Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
parent
0a74b4905c
commit
d6f1e2de21
3 changed files with 14 additions and 4 deletions
|
|
@ -1048,15 +1048,13 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, RepairF
|
|||
/* In case we are not interested in reading the NAR: discard it. */
|
||||
bool narRead = false;
|
||||
Finally cleanup = [&]() {
|
||||
if (!narRead) {
|
||||
NullFileSystemObjectSink sink;
|
||||
if (!narRead)
|
||||
try {
|
||||
parseDump(sink, source);
|
||||
source.skip(info.narSize);
|
||||
} catch (...) {
|
||||
// TODO: should Interrupted be handled here?
|
||||
ignoreExceptionInDestructor();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
addTempRoot(info.path);
|
||||
|
|
|
|||
|
|
@ -255,6 +255,8 @@ struct StringSource : Source
|
|||
}
|
||||
|
||||
size_t read(char * data, size_t len) override;
|
||||
|
||||
void skip(size_t len) override;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -242,6 +242,16 @@ size_t StringSource::read(char * data, size_t len)
|
|||
return n;
|
||||
}
|
||||
|
||||
void StringSource::skip(size_t len)
|
||||
{
|
||||
const size_t remain = s.size() - pos;
|
||||
if (len > remain) {
|
||||
pos = s.size();
|
||||
throw EndOfFile("end of string reached");
|
||||
}
|
||||
pos += len;
|
||||
}
|
||||
|
||||
std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun)
|
||||
{
|
||||
struct SourceToSink : FinishSink
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue