Merge pull request #13577 from NixOS/mergify/bp/2.28-maintenance/pr-13175

libutil/tarfile: Create the scratch `std::vector` only once (backport #13175)
This commit is contained in:
mergify[bot]
2025-07-30 13:26:14 +00:00
committed by GitHub

View File

@@ -182,6 +182,10 @@ time_t unpackTarfileToSink(TarArchive & archive, ExtendedFileSystemObjectSink &
{
time_t lastModified = 0;
/* Only allocate the buffer once. Use the heap because 131 KiB is a bit too
much for the stack. */
std::vector<unsigned char> buf(128 * 1024);
for (;;) {
// FIXME: merge with extract_archive
struct archive_entry * entry;
@@ -216,7 +220,6 @@ time_t unpackTarfileToSink(TarArchive & archive, ExtendedFileSystemObjectSink &
crf.isExecutable();
while (true) {
std::vector<unsigned char> buf(128 * 1024);
auto n = archive_read_data(archive.archive, buf.data(), buf.size());
if (n < 0)
throw Error("cannot read file '%s' from tarball", path);