diff options
author | martin@piware.de <> | 2010-07-06 12:48:06 +0200 |
---|---|---|
committer | martin@piware.de <> | 2010-07-06 12:48:06 +0200 |
commit | d13c2d3f7b10e558301a05948e91ac4a60160793 (patch) | |
tree | 7252f169a95fc475bad8f3799dc8f7d2112e6768 /apt-pkg | |
parent | 9a3a552a2859040ffc587a4e5d8d96311038e680 (diff) |
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.
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 14 |
1 files changed, 11 insertions, 3 deletions
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; |