diff options
author | David Kalnischkies <david@kalnischkies.de> | 2020-05-15 13:29:36 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2020-05-18 15:55:36 +0200 |
commit | 19790db8900bc9baac29cf58600152997a8ecef8 (patch) | |
tree | e225c11fed3c02e0f6682001d83247081b4bbd69 | |
parent | 5534bb3ad346ef4435e6fd0fe326771a4bde16a1 (diff) |
Skip reading data from tar members if nobody will look at it
The variable this is read to is named Junk and that it is for usecases
like apt-ftparchive which just looks at the items metadata, so instead
of performing this hunked read for data nobody will process we just tell
our FileFd to skip ahead (Internally it might still loop over the data
depending on which compressor is involved).
-rw-r--r-- | apt-pkg/contrib/extracttar.cc | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/apt-pkg/contrib/extracttar.cc b/apt-pkg/contrib/extracttar.cc index 923c26d6c..1616c9f12 100644 --- a/apt-pkg/contrib/extracttar.cc +++ b/apt-pkg/contrib/extracttar.cc @@ -257,50 +257,50 @@ bool ExtractTar::Go(pkgDirStream &Stream) _error->Warning(_("Unknown TAR header type %u"), (unsigned)Tar->LinkFlag); break; } - + int Fd = -1; - if (BadRecord == false) - if (Stream.DoItem(Itm,Fd) == false) + if (not BadRecord && not Stream.DoItem(Itm, Fd)) + return false; + + if (Fd == -1 || Fd < -2 || BadRecord) + { + if (Itm.Size > 0 && not InFd.Skip(((Itm.Size + (sizeof(Block) - 1)) / sizeof(Block)) * sizeof(Block))) return false; - - // Copy the file over the FD - unsigned long long Size = Itm.Size; - while (Size != 0) + } + else if (Itm.Size != 0) { + // Copy the file over the FD + auto Size = Itm.Size; unsigned char Junk[32*1024]; - unsigned long Read = min(Size, (unsigned long long)sizeof(Junk)); - if (InFd.Read(Junk,((Read+511)/512)*512) == false) - return false; - - if (BadRecord == false) + do { + auto const Read = std::min<unsigned long long>(Size, sizeof(Junk)); + if (not InFd.Read(Junk, ((Read + (sizeof(Block) - 1)) / sizeof(Block)) * sizeof(Block))) + return false; + if (Fd > 0) { if (not FileFd::Write(Fd, Junk, Read)) - return Stream.Fail(Itm,Fd); + return Stream.Fail(Itm, Fd); } - else + // An Fd of -2 means to send to a special processing function + else if (Fd == -2) { - /* An Fd of -2 means to send to a special processing - function */ - if (Fd == -2) - if (Stream.Process(Itm,Junk,Read,Itm.Size - Size) == false) - return Stream.Fail(Itm,Fd); + if (not Stream.Process(Itm, Junk, Read, Itm.Size - Size)) + return Stream.Fail(Itm, Fd); } - } - - Size -= Read; + + Size -= Read; + } while (Size != 0); } - + // And finish up - if (BadRecord == false) - if (Stream.FinishedFile(Itm,Fd) == false) - return false; - + if (not BadRecord && not Stream.FinishedFile(Itm, Fd)) + return false; LastLongName.erase(); LastLongLink.erase(); } - + return Done(); } /*}}}*/ |