Skip to content

Commit 67bffa1

Browse files
committed
NullFileSystemObjectSink: Skip over file contents
1 parent daa7e0d commit 67bffa1

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/libutil/archive.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ static void parseContents(CreateRegularFileSink & sink, Source & source)
132132

133133
sink.preallocateContents(size);
134134

135+
if (sink.skipContents) {
136+
source.skip(size + (size % 8 ? 8 - (size % 8) : 0));
137+
return;
138+
}
139+
135140
uint64_t left = size;
136141
std::array<char, 65536> buf;
137142

@@ -166,7 +171,7 @@ static void parse(FileSystemObjectSink & sink, Source & source, const CanonPath
166171
auto expectTag = [&](std::string_view expected) {
167172
auto tag = getString();
168173
if (tag != expected)
169-
throw badArchive("expected tag '%s', got '%s'", expected, tag);
174+
throw badArchive("expected tag '%s', got '%s'", expected, tag.substr(0, 1024));
170175
};
171176

172177
expectTag("(");

src/libutil/fs-sink.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ void NullFileSystemObjectSink::createRegularFile(
196196
void isExecutable() override {}
197197
} crf;
198198

199+
crf.skipContents = true;
200+
199201
// Even though `NullFileSystemObjectSink` doesn't do anything, it's important
200202
// that we call the function, to e.g. advance the parser using this
201203
// sink.

src/libutil/include/nix/util/fs-sink.hh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ namespace nix {
1414
*/
1515
struct CreateRegularFileSink : Sink
1616
{
17+
/**
18+
* If set to true, the sink will not be called with the contents
19+
* of the file. `preallocateContents()` will still be called to
20+
* convey the file size. Useful for sinks that want to efficiently
21+
* discard the contents of the file.
22+
*/
23+
bool skipContents = false;
24+
1725
virtual void isExecutable() = 0;
1826

1927
/**

0 commit comments

Comments
 (0)