From a3a03f5d7436c870edac9c0eb92e85e1fcaf6bca Mon Sep 17 00:00:00 2001 From: "martin@piware.de" <> Date: Wed, 9 Jun 2010 14:08:20 +0200 Subject: * apt-pkg/contrib/fileutl.{h,cc}: - Add support for transparent reading of gzipped files. - Link against zlib (in apt-pkg/makefile) and add zlib build dependency. --- apt-pkg/contrib/fileutl.cc | 47 ++++++++++++++++++++++++++++++++++++++++------ apt-pkg/contrib/fileutl.h | 9 ++++++--- apt-pkg/makefile | 2 +- 3 files changed, 48 insertions(+), 10 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index da32983f1..11a9e7f7b 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -11,6 +11,7 @@ Most of this source is placed in the Public Domain, do with it what you will It was originally written by Jason Gunthorpe . + FileFd gzip support added by Martin Pitt The exception is RunScripts() it is under the GPLv2 @@ -603,6 +604,13 @@ bool FileFd::Open(string FileName,OpenMode Mode, unsigned long Perms) { case ReadOnly: iFd = open(FileName.c_str(),O_RDONLY); + if (iFd > 0 && FileName.compare(FileName.size()-3, 3, ".gz") == 0) { + gz = gzdopen (iFd, "r"); + if (gz == NULL) { + close (iFd); + iFd = -1; + } + } break; case WriteEmpty: @@ -658,7 +666,10 @@ bool FileFd::Read(void *To,unsigned long Size,unsigned long *Actual) do { - Res = read(iFd,To,Size); + if (gz != NULL) + Res = gzread(gz,To,Size); + else + Res = read(iFd,To,Size); if (Res < 0 && errno == EINTR) continue; if (Res < 0) @@ -697,7 +708,10 @@ bool FileFd::Write(const void *From,unsigned long Size) errno = 0; do { - Res = write(iFd,From,Size); + if (gz != NULL) + Res = gzwrite(gz,From,Size); + else + Res = write(iFd,From,Size); if (Res < 0 && errno == EINTR) continue; if (Res < 0) @@ -723,7 +737,12 @@ bool FileFd::Write(const void *From,unsigned long Size) /* */ bool FileFd::Seek(unsigned long To) { - if (lseek(iFd,To,SEEK_SET) != (signed)To) + int res; + if (gz) + res = gzseek(gz,To,SEEK_SET); + else + res = lseek(iFd,To,SEEK_SET); + if (res != (signed)To) { Flags |= Fail; return _error->Error("Unable to seek to %lu",To); @@ -737,7 +756,12 @@ bool FileFd::Seek(unsigned long To) /* */ bool FileFd::Skip(unsigned long Over) { - if (lseek(iFd,Over,SEEK_CUR) < 0) + int res; + if (gz) + res = gzseek(gz,Over,SEEK_CUR); + else + res = lseek(iFd,Over,SEEK_CUR); + if (res < 0) { Flags |= Fail; return _error->Error("Unable to seek ahead %lu",Over); @@ -751,6 +775,11 @@ bool FileFd::Skip(unsigned long Over) /* */ bool FileFd::Truncate(unsigned long To) { + if (gz) + { + Flags |= Fail; + return _error->Error("Truncating gzipped files is not implemented (%s)", FileName.c_str()); + } if (ftruncate(iFd,To) != 0) { Flags |= Fail; @@ -765,7 +794,11 @@ bool FileFd::Truncate(unsigned long To) /* */ unsigned long FileFd::Tell() { - off_t Res = lseek(iFd,0,SEEK_CUR); + off_t Res; + if (gz) + Res = gztell(gz); + else + Res = lseek(iFd,0,SEEK_CUR); if (Res == (off_t)-1) _error->Errno("lseek","Failed to determine the current file position"); return Res; @@ -776,6 +809,7 @@ unsigned long FileFd::Tell() /* */ unsigned long FileFd::Size() { + //TODO: For gz, do we need the actual file size here or the uncompressed length? struct stat Buf; if (fstat(iFd,&Buf) != 0) return _error->Errno("fstat","Unable to determine the file size"); @@ -789,9 +823,10 @@ bool FileFd::Close() { bool Res = true; if ((Flags & AutoClose) == AutoClose) - if (iFd >= 0 && close(iFd) != 0) + if ((gz != NULL && gzclose(gz) != 0) || (gz == NULL && iFd > 0 && close(iFd) != 0)) Res &= _error->Errno("close",_("Problem closing the file")); iFd = -1; + gz = NULL; if ((Flags & Fail) == Fail && (Flags & DelOnFail) == DelOnFail && FileName.empty() == false) diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 85a94898c..9925bbed4 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -25,6 +25,8 @@ #include #include +#include + using std::string; class FileFd @@ -36,6 +38,7 @@ class FileFd HitEof = (1<<3)}; unsigned long Flags; string FileName; + gzFile gz; public: enum OpenMode {ReadOnly,WriteEmpty,WriteExists,WriteAny,WriteTemp}; @@ -69,12 +72,12 @@ class FileFd inline string &Name() {return FileName;}; FileFd(string FileName,OpenMode Mode,unsigned long Perms = 0666) : iFd(-1), - Flags(0) + Flags(0), gz(NULL) { Open(FileName,Mode,Perms); }; - FileFd(int Fd = -1) : iFd(Fd), Flags(AutoClose) {}; - FileFd(int Fd,bool) : iFd(Fd), Flags(0) {}; + FileFd(int Fd = -1) : iFd(Fd), Flags(AutoClose), gz(NULL) {}; + FileFd(int Fd,bool) : iFd(Fd), Flags(0), gz(NULL) {}; virtual ~FileFd(); }; diff --git a/apt-pkg/makefile b/apt-pkg/makefile index bdd49c089..4cf07f3a8 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -14,7 +14,7 @@ include ../buildlib/libversion.mak LIBRARY=apt-pkg MAJOR=$(LIBAPTPKG_MAJOR) MINOR=$(LIBAPTPKG_RELEASE) -SLIBS=$(PTHREADLIB) $(INTLLIBS) -lutil -ldl +SLIBS=$(PTHREADLIB) $(INTLLIBS) -lutil -ldl -lz APT_DOMAIN:=libapt-pkg$(LIBAPTPKG_MAJOR) # Source code for the contributed non-core things -- cgit v1.2.3 From ec7a129eeb1611ec097bc99a148d6d3a3dccf044 Mon Sep 17 00:00:00 2001 From: "martin@piware.de" <> Date: Wed, 9 Jun 2010 14:09:42 +0200 Subject: * apt-pkg/deb/debindexfile.cc: - If we do not find uncompressed package/source/translation indexes, look for gzip compressed ones. --- apt-pkg/deb/debindexfile.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 7379ca997..e87c21f13 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -106,8 +106,14 @@ string debSourcesIndex::Info(const char *Type) const /* */ inline string debSourcesIndex::IndexFile(const char *Type) const { - return URItoFileName(IndexURI(Type)); + string s = URItoFileName(IndexURI(Type)); + string sgzip = s + ".gz"; + if (!FileExists(s) && FileExists(sgzip)) + return sgzip; + else + return s; } + string debSourcesIndex::IndexURI(const char *Type) const { string Res; @@ -213,7 +219,12 @@ string debPackagesIndex::Info(const char *Type) const /* */ inline string debPackagesIndex::IndexFile(const char *Type) const { - return _config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type)); + string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type)); + string sgzip = s + ".gz"; + if (!FileExists(s) && FileExists(sgzip)) + return sgzip; + else + return s; } string debPackagesIndex::IndexURI(const char *Type) const { @@ -340,7 +351,12 @@ debTranslationsIndex::debTranslationsIndex(string URI,string Dist,string Section /* */ inline string debTranslationsIndex::IndexFile(const char *Type) const { - return _config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type)); + string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type)); + string sgzip = s + ".gz"; + if (!FileExists(s) && FileExists(sgzip)) + return sgzip; + else + return s; } string debTranslationsIndex::IndexURI(const char *Type) const { -- cgit v1.2.3 From 01606def78105c9d64f12c89e387d37ed46925b6 Mon Sep 17 00:00:00 2001 From: "martin@piware.de" <> Date: Thu, 10 Jun 2010 13:20:27 +0200 Subject: * apt-pkg/acquire-item.cc: - If the Acquire::GzipIndexes option is true and we download a gzipped index file, keep it as it is (and rename to .gz) instead of uncompressing it. --- apt-pkg/acquire-item.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 6d4336425..eab34e26c 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -620,6 +620,8 @@ string pkgAcqIndex::Custom600Headers() { string Final = _config->FindDir("Dir::State::lists"); Final += URItoFileName(RealURI); + if (_config->FindB("Acquire::GzipIndexes",false)) + Final += ".gz"; struct stat Buf; if (stat(Final.c_str(),&Buf) != 0) @@ -714,6 +716,23 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string Hash, Erase = false; Complete = true; + string compExt = flExtension(flNotDir(URI(Desc.URI).Path)); + + // If we enable compressed indexes and already have gzip, keep it + if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz") { + string FinalFile = _config->FindDir("Dir::State::lists"); + FinalFile += URItoFileName(RealURI) + ".gz"; + //if(Debug) + // std::clog << "pkgAcqIndex: keeping gzipped " << FinalFile << endl; + Rename(DestFile,FinalFile); + chmod(FinalFile.c_str(),0644); + + // Update DestFile for .gz suffix so that the clean operation keeps it + DestFile = _config->FindDir("Dir::State::lists") + "partial/"; + DestFile += URItoFileName(RealURI) + ".gz"; + return; + } + // Handle the unzipd case string FileName = LookupTag(Message,"Alt-Filename"); if (FileName.empty() == false) @@ -746,7 +765,6 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string Hash, else Local = true; - string compExt = flExtension(flNotDir(URI(Desc.URI).Path)); string decompProg; // get the binary name for your used compression type -- cgit v1.2.3 From bb109d0b14218cde4fccc45856cf67e5513c0cc9 Mon Sep 17 00:00:00 2001 From: "martin@piware.de" <> Date: Fri, 11 Jun 2010 10:43:43 +0200 Subject: Fix compressed index retrieval for current timestamps Fix a thinko in r1973, which did the Acquire::GzipIndexes test ealier than the IMS-Hit test. This led to rename errors. --- apt-pkg/acquire-item.cc | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index eab34e26c..83fb5328b 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -716,23 +716,6 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string Hash, Erase = false; Complete = true; - string compExt = flExtension(flNotDir(URI(Desc.URI).Path)); - - // If we enable compressed indexes and already have gzip, keep it - if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz") { - string FinalFile = _config->FindDir("Dir::State::lists"); - FinalFile += URItoFileName(RealURI) + ".gz"; - //if(Debug) - // std::clog << "pkgAcqIndex: keeping gzipped " << FinalFile << endl; - Rename(DestFile,FinalFile); - chmod(FinalFile.c_str(),0644); - - // Update DestFile for .gz suffix so that the clean operation keeps it - DestFile = _config->FindDir("Dir::State::lists") + "partial/"; - DestFile += URItoFileName(RealURI) + ".gz"; - return; - } - // Handle the unzipd case string FileName = LookupTag(Message,"Alt-Filename"); if (FileName.empty() == false) @@ -765,8 +748,24 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string Hash, else Local = true; + string compExt = flExtension(flNotDir(URI(Desc.URI).Path)); string decompProg; + // If we enable compressed indexes and already have gzip, keep it + if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz") { + string FinalFile = _config->FindDir("Dir::State::lists"); + FinalFile += URItoFileName(RealURI) + ".gz"; + //if(Debug) + // std::clog << "pkgAcqIndex: keeping gzipped " << FinalFile << endl; + Rename(DestFile,FinalFile); + chmod(FinalFile.c_str(),0644); + + // Update DestFile for .gz suffix so that the clean operation keeps it + DestFile = _config->FindDir("Dir::State::lists") + "partial/"; + DestFile += URItoFileName(RealURI) + ".gz"; + return; + } + // get the binary name for your used compression type decompProg = _config->Find(string("Acquire::CompressionTypes::").append(compExt),""); if(decompProg.empty() == false); -- cgit v1.2.3 From b26e2415ee2d4f611966488954f8d4f30fcf827c Mon Sep 17 00:00:00 2001 From: "martin@piware.de" <> Date: Fri, 11 Jun 2010 18:59:06 +0200 Subject: * apt-pkg/acquire-item.cc: - Fix return value of pkgAcqFile::Custom600Headers() in the non-index case, to avoid returning NULL and causing crashers in callers. This also fixes a compiler warning. --- apt-pkg/acquire-item.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 83fb5328b..bcfe6a98a 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1688,5 +1688,7 @@ string pkgAcqFile::Custom600Headers() { if (IsIndexFile) return "\nIndex-File: true"; + else + return ""; } /*}}}*/ -- cgit v1.2.3 From 94e8c9d4df70d2532e1640dfe2700dd63a094a4f Mon Sep 17 00:00:00 2001 From: "martin@piware.de" <> Date: Fri, 11 Jun 2010 19:23:08 +0200 Subject: apt-pkg/deb/debindexfile.cc: Fix one more place to check for gzipped indexes, to work with apt-get source as well --- apt-pkg/deb/debindexfile.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index e87c21f13..9832329c0 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -63,9 +63,13 @@ string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record, /* */ pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const { - string SourcesURI = URItoFileName(IndexURI("Sources")); - return new debSrcRecordParser(_config->FindDir("Dir::State::lists") + - SourcesURI,this); + string SourcesURI = _config->FindDir("Dir::State::lists") + + URItoFileName(IndexURI("Sources")); + string SourcesURIgzip = SourcesURI + ".gz"; + if (!FileExists(SourcesURI) && FileExists(SourcesURIgzip)) + SourcesURI = SourcesURIgzip; + + return new debSrcRecordParser(SourcesURI,this); } /*}}}*/ // SourcesIndex::Describe - Give a descriptive path to the index /*{{{*/ -- cgit v1.2.3 From 0b9032b180763ec974cdc918f93910540f05293a Mon Sep 17 00:00:00 2001 From: "martin@piware.de" <> Date: Thu, 17 Jun 2010 13:36:52 +0200 Subject: pkgAcqIndex::Done(): If we have an IMS-Hit, also rename the destination file in GzipIndexes mode, to avoid it being cleaned --- apt-pkg/acquire-item.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index bcfe6a98a..fe81ee791 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -739,16 +739,21 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string Hash, ErrorText = "Method gave a blank filename"; } + string compExt = flExtension(flNotDir(URI(Desc.URI).Path)); + // The files timestamp matches - if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == true) + if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == true) { + if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz") + // Update DestFile for .gz suffix so that the clean operation keeps it + DestFile += ".gz"; return; + } if (FileName == DestFile) Erase = true; else Local = true; - string compExt = flExtension(flNotDir(URI(Desc.URI).Path)); string decompProg; // If we enable compressed indexes and already have gzip, keep it -- cgit v1.2.3 From c4fc2fd7fa0fc63fd8cd6bc9b73492e6baf0222a Mon Sep 17 00:00:00 2001 From: "martin@piware.de" <> Date: Thu, 24 Jun 2010 21:27:27 +0200 Subject: Switch FileFd to not transparently gunzip, since that breaks code which expects the compressed contents to stay (such as the copy backend, or when using file:// repositories. Instead, introduce a new ReadOnlyGzip mode and use that where needed --- apt-pkg/acquire-item.cc | 4 ++-- apt-pkg/contrib/fileutl.cc | 14 +++++++++----- apt-pkg/contrib/fileutl.h | 2 +- apt-pkg/deb/debindexfile.cc | 6 +++--- apt-pkg/deb/debrecords.cc | 2 +- apt-pkg/deb/debsrcrecords.h | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index fe81ee791..9abdb0ad0 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -228,7 +228,7 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile) /*{{{*/ ss >> ServerSha1 >> size; unsigned long const ServerSize = atol(size.c_str()); - FileFd fd(CurrentPackagesFile, FileFd::ReadOnly); + FileFd fd(CurrentPackagesFile, FileFd::ReadOnlyGzip); SHA1Summation SHA1; SHA1.AddFD(fd.Fd(), fd.Size()); string const local_sha1 = SHA1.Result(); @@ -459,7 +459,7 @@ bool pkgAcqIndexDiffs::QueueNextDiff() /*{{{*/ string FinalFile = _config->FindDir("Dir::State::lists"); FinalFile += URItoFileName(RealURI); - FileFd fd(FinalFile, FileFd::ReadOnly); + FileFd fd(FinalFile, FileFd::ReadOnlyGzip); SHA1Summation SHA1; SHA1.AddFD(fd.Fd(), fd.Size()); string local_sha1 = string(SHA1.Result()); diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 11a9e7f7b..2b91a46f7 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -604,12 +604,16 @@ bool FileFd::Open(string FileName,OpenMode Mode, unsigned long Perms) { case ReadOnly: iFd = open(FileName.c_str(),O_RDONLY); + break; + + case ReadOnlyGzip: + iFd = open(FileName.c_str(),O_RDONLY); if (iFd > 0 && FileName.compare(FileName.size()-3, 3, ".gz") == 0) { - gz = gzdopen (iFd, "r"); - if (gz == NULL) { - close (iFd); - iFd = -1; - } + gz = gzdopen (iFd, "r"); + if (gz == NULL) { + close (iFd); + iFd = -1; + } } break; diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 9925bbed4..c4b282126 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -41,7 +41,7 @@ class FileFd gzFile gz; public: - enum OpenMode {ReadOnly,WriteEmpty,WriteExists,WriteAny,WriteTemp}; + enum OpenMode {ReadOnly,WriteEmpty,WriteExists,WriteAny,WriteTemp,ReadOnlyGzip}; inline bool Read(void *To,unsigned long Size,bool AllowEof) { diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 9832329c0..7d7bd09fb 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -273,7 +273,7 @@ unsigned long debPackagesIndex::Size() const bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const { string PackageFile = IndexFile("Packages"); - FileFd Pkg(PackageFile,FileFd::ReadOnly); + FileFd Pkg(PackageFile,FileFd::ReadOnlyGzip); debListParser Parser(&Pkg); if (_error->PendingError() == true) return _error->Error("Problem opening %s",PackageFile.c_str()); @@ -464,7 +464,7 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const string TranslationFile = IndexFile(Language); if (TranslationsAvailable() && FileExists(TranslationFile)) { - FileFd Trans(TranslationFile,FileFd::ReadOnly); + FileFd Trans(TranslationFile,FileFd::ReadOnlyGzip); debListParser TransParser(&Trans); if (_error->PendingError() == true) return false; @@ -544,7 +544,7 @@ unsigned long debStatusIndex::Size() const /* */ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress &Prog) const { - FileFd Pkg(File,FileFd::ReadOnly); + FileFd Pkg(File,FileFd::ReadOnlyGzip); if (_error->PendingError() == true) return false; debListParser Parser(&Pkg); diff --git a/apt-pkg/deb/debrecords.cc b/apt-pkg/deb/debrecords.cc index 34ef0d8f2..ec9e395ef 100644 --- a/apt-pkg/deb/debrecords.cc +++ b/apt-pkg/deb/debrecords.cc @@ -19,7 +19,7 @@ // --------------------------------------------------------------------- /* */ debRecordParser::debRecordParser(string FileName,pkgCache &Cache) : - File(FileName,FileFd::ReadOnly), + File(FileName,FileFd::ReadOnlyGzip), Tags(&File, std::max(Cache.Head().MaxVerFileSize, Cache.Head().MaxDescFileSize) + 200) { diff --git a/apt-pkg/deb/debsrcrecords.h b/apt-pkg/deb/debsrcrecords.h index c39d78bae..905264daa 100644 --- a/apt-pkg/deb/debsrcrecords.h +++ b/apt-pkg/deb/debsrcrecords.h @@ -48,7 +48,7 @@ class debSrcRecordParser : public pkgSrcRecords::Parser virtual bool Files(vector &F); debSrcRecordParser(string const &File,pkgIndexFile const *Index) - : Parser(Index), Fd(File,FileFd::ReadOnly), Tags(&Fd,102400), + : Parser(Index), Fd(File,FileFd::ReadOnlyGzip), Tags(&Fd,102400), Buffer(0), BufSize(0) {} ~debSrcRecordParser(); }; -- cgit v1.2.3 From 7aeee3653d7d0dc34769bb74a2bf4824b438834f Mon Sep 17 00:00:00 2001 From: "martin@piware.de" <> Date: Thu, 24 Jun 2010 22:43:07 +0200 Subject: apt-pkg/acquire-item.cc: Fix handling of local (file:/) sources --- apt-pkg/acquire-item.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 9abdb0ad0..a506aa9aa 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -757,7 +757,7 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string Hash, string decompProg; // If we enable compressed indexes and already have gzip, keep it - if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz") { + if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz" && !Local) { string FinalFile = _config->FindDir("Dir::State::lists"); FinalFile += URItoFileName(RealURI) + ".gz"; //if(Debug) -- cgit v1.2.3 From d13c2d3f7b10e558301a05948e91ac4a60160793 Mon Sep 17 00:00:00 2001 From: "martin@piware.de" <> Date: Tue, 6 Jul 2010 12:48:06 +0200 Subject: FileFd(): Drop file name extension check in ReadOnlyGzip mode Drop the ".gz" extension check in FileFd::Open() in ReadOnlyGzip mode, to not depend on a particular file extension. This allows rewriting the gzip method using internal decompression (on ".decomp" files). This requires a zlib bug workaround in FileFd::Close(): When opening an empty file with gzdopen(), gzclose() fails with Z_BUF_ERROR. Do not count this as a failure. --- apt-pkg/contrib/fileutl.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 2b91a46f7..0d2d3f356 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -608,7 +608,7 @@ bool FileFd::Open(string FileName,OpenMode Mode, unsigned long Perms) case ReadOnlyGzip: iFd = open(FileName.c_str(),O_RDONLY); - if (iFd > 0 && FileName.compare(FileName.size()-3, 3, ".gz") == 0) { + if (iFd > 0) { gz = gzdopen (iFd, "r"); if (gz == NULL) { close (iFd); @@ -827,8 +827,16 @@ bool FileFd::Close() { bool Res = true; if ((Flags & AutoClose) == AutoClose) - if ((gz != NULL && gzclose(gz) != 0) || (gz == NULL && iFd > 0 && close(iFd) != 0)) - Res &= _error->Errno("close",_("Problem closing the file")); + { + if (gz != NULL) { + int e = gzclose(gz); + // gzdopen() on empty files always fails with "buffer error" here, ignore that + if (e != 0 && e != Z_BUF_ERROR) + Res &= _error->Errno("close",_("Problem closing the gzip file")); + } else + if (iFd > 0 && close(iFd) != 0) + Res &= _error->Errno("close",_("Problem closing the file")); + } iFd = -1; gz = NULL; -- cgit v1.2.3