mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 11:36:03 +01:00
NullFileSystemObjectSink: Skip over file contents
This commit is contained in:
parent
daa7e0d2e9
commit
67bffa19a5
3 changed files with 16 additions and 1 deletions
|
|
@ -132,6 +132,11 @@ static void parseContents(CreateRegularFileSink & sink, Source & source)
|
|||
|
||||
sink.preallocateContents(size);
|
||||
|
||||
if (sink.skipContents) {
|
||||
source.skip(size + (size % 8 ? 8 - (size % 8) : 0));
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t left = size;
|
||||
std::array<char, 65536> buf;
|
||||
|
||||
|
|
@ -166,7 +171,7 @@ static void parse(FileSystemObjectSink & sink, Source & source, const CanonPath
|
|||
auto expectTag = [&](std::string_view expected) {
|
||||
auto tag = getString();
|
||||
if (tag != expected)
|
||||
throw badArchive("expected tag '%s', got '%s'", expected, tag);
|
||||
throw badArchive("expected tag '%s', got '%s'", expected, tag.substr(0, 1024));
|
||||
};
|
||||
|
||||
expectTag("(");
|
||||
|
|
|
|||
|
|
@ -196,6 +196,8 @@ void NullFileSystemObjectSink::createRegularFile(
|
|||
void isExecutable() override {}
|
||||
} crf;
|
||||
|
||||
crf.skipContents = true;
|
||||
|
||||
// Even though `NullFileSystemObjectSink` doesn't do anything, it's important
|
||||
// that we call the function, to e.g. advance the parser using this
|
||||
// sink.
|
||||
|
|
|
|||
|
|
@ -14,6 +14,14 @@ namespace nix {
|
|||
*/
|
||||
struct CreateRegularFileSink : Sink
|
||||
{
|
||||
/**
|
||||
* If set to true, the sink will not be called with the contents
|
||||
* of the file. `preallocateContents()` will still be called to
|
||||
* convey the file size. Useful for sinks that want to efficiently
|
||||
* discard the contents of the file.
|
||||
*/
|
||||
bool skipContents = false;
|
||||
|
||||
virtual void isExecutable() = 0;
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue