diff options
author | Michael Vogt <mvo@debian.org> | 2010-10-13 16:12:00 +0200 |
---|---|---|
committer | Michael Vogt <mvo@debian.org> | 2010-10-13 16:12:00 +0200 |
commit | be61b563c20267c521494cca92bd7ac158366c89 (patch) | |
tree | 69f40bd11de1100b4b2d452e4cbab1cb72c10458 /apt-pkg | |
parent | 6bea738672fb503d2813ae2d998096015a81c4a2 (diff) | |
parent | 44dc669e08353716da835608ea54563b4c8c32bb (diff) |
merged FileFd::Size() fix from lp:~mvo/apt/mvo
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index bf07f6008..cbf1d64a9 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -916,10 +916,17 @@ unsigned long FileFd::Tell() unsigned long FileFd::Size() { struct stat Buf; - long size; + unsigned long size; off_t orig_pos; - if (gz) + if (fstat(iFd,&Buf) != 0) + return _error->Errno("fstat","Unable to determine the file size"); + size = Buf.st_size; + + // only check gzsize if we are actually a gzip file, just checking for + // "gz" is not sufficient as uncompressed files will be opened with + // gzopen in "direct" mode as well + if (gz && !gzdirect(gz) && size > 0) { /* unfortunately zlib.h doesn't provide a gzsize(), so we have to do * this ourselves; the original (uncompressed) file size is the last 32 @@ -936,9 +943,7 @@ unsigned long FileFd::Size() return size; } - if (fstat(iFd,&Buf) != 0) - return _error->Errno("fstat","Unable to determine the file size"); - return Buf.st_size; + return size; } /*}}}*/ // FileFd::Close - Close the file if the close flag is set /*{{{*/ |