X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/f5ec3b68c582138acce7c5a93e473dde50ab8354..6ea086805714e0dbeecfb5e3e26d3489a624bcd4:/apt-pkg/tagfile.cc diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index d58409bfb..8fcbeb23b 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: tagfile.cc,v 1.33 2002/05/30 04:19:48 jgg Exp $ +// $Id: tagfile.cc,v 1.37.2.2 2003/12/31 16:02:30 mdz Exp $ /* ###################################################################### Fast scanner for RFC-822 type header information @@ -31,22 +31,35 @@ using std::string; // TagFile::pkgTagFile - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long Size) : Fd(*pFd), Size(Size) +pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long Size) : + Fd(*pFd), + Size(Size), + Map(NULL), + Buffer(0) { if (Fd.IsOpen() == false) { - Buffer = 0; Start = End = Buffer = 0; Done = true; iOffset = 0; + Map = NULL; return; } - Buffer = new char[Size]; - Start = End = Buffer; - Done = false; + // check if we can MMap it + if(Fd.Size() == 0) + { + Buffer = new char[Size]; + Start = End = Buffer; + Done = false; + Fill(); + } else { + Map = new MMap (Fd, MMap::Public | MMap::ReadOnly); + Buffer = (char *) Map->Data (); + Start = Buffer; + End = Buffer + Map->Size (); + } iOffset = 0; - Fill(); } /*}}}*/ // TagFile::~pkgTagFile - Destructor /*{{{*/ @@ -54,7 +67,8 @@ pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long Size) : Fd(*pFd), Size(Size) /* */ pkgTagFile::~pkgTagFile() { - delete [] Buffer; + if(!Map) delete [] Buffer; + delete Map; } /*}}}*/ // TagFile::Step - Advance to the next section /*{{{*/ @@ -62,15 +76,22 @@ pkgTagFile::~pkgTagFile() /* If the Section Scanner fails we refill the buffer and try again. */ bool pkgTagFile::Step(pkgTagSection &Tag) { + if ((Map != NULL) && (Start == End)) + return false; + if (Tag.Scan(Start,End - Start) == false) { + if (Map != NULL) + return _error->Error(_("Unable to parse package file %s (1)"), + Fd.Name().c_str()); + if (Fill() == false) return false; if (Tag.Scan(Start,End - Start) == false) return _error->Error(_("Unable to parse package file %s (1)"), Fd.Name().c_str()); - } + } Start += Tag.size(); iOffset += Tag.size(); @@ -85,7 +106,7 @@ bool pkgTagFile::Step(pkgTagSection &Tag) bool pkgTagFile::Fill() { unsigned long EndSize = End - Start; - unsigned long Actual; + unsigned long Actual = 0; memmove(Buffer,Start,EndSize); Start = Buffer; @@ -137,23 +158,30 @@ bool pkgTagFile::Jump(pkgTagSection &Tag,unsigned long Offset) return Step(Tag); } - // Reposition and reload.. iOffset = Offset; - Done = false; - if (Fd.Seek(Offset) == false) - return false; - End = Start = Buffer; + if (Map != NULL) + { + Start = Buffer + iOffset; + } + else + { + // Reposition and reload.. + Done = false; + if (Fd.Seek(Offset) == false) + return false; + End = Start = Buffer; - if (Fill() == false) - return false; + if (Fill() == false) + return false; - if (Tag.Scan(Start,End - Start) == true) - return true; - - // This appends a double new line (for the real eof handling) - if (Fill() == false) - return false; + if (Tag.Scan(Start,End - Start) == true) + return true; + // This appends a double new line (for the real eof handling) + if (Fill() == false) + return false; + } + if (Tag.Scan(Start,End - Start) == false) return _error->Error(_("Unable to parse package file %s (2)"),Fd.Name().c_str()); @@ -179,7 +207,7 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength) Stop = Section = Start; memset(AlphaIndexes,0,sizeof(AlphaIndexes)); - if (Stop == 0) + if (Stop == 0 || MaxLength == 0) return false; TagCount = 0; @@ -197,7 +225,7 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength) if (Stop == 0) return false; - for (; Stop+1 < End && Stop[1] == '\r'; Stop++); + for (; Stop+1 < End && Stop[1] == '\r'; Stop++); // Double newline marks the end of the record if (Stop+1 < End && Stop[1] == '\n') @@ -210,6 +238,12 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength) Stop++; } + if ((Stop+1 >= End) && (End[-1] == '\n' || End[-1] == '\r')) + { + Indexes[TagCount] = (End - 1) - Section; + return true; + } + return false; } /*}}}*/ @@ -392,7 +426,8 @@ static const char *iTFRewritePackageOrder[] = { "Filename", "Size", "MD5Sum", - "SHA1Sum", + "SHA1", + "SHA256", "MSDOS-Filename", // Obsolete "Description", 0};