summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorMartin Pitt <martin@piware.de>2010-10-13 13:00:49 +0200
committerMartin Pitt <martin@piware.de>2010-10-13 13:00:49 +0200
commit9c182afa045dc889a5025d166328c6115924d706 (patch)
tree87dcb5dce121c3dc09c60684b1247b29b82cc632 /apt-pkg/contrib
parent5473df3fec08eaea6e84b98551cc247e87f4b6df (diff)
downloadapt-9c182afa045dc889a5025d166328c6115924d706.tar.gz
* apt-pkg/contrib/fileutl.cc:
- Fix FileFd::Size() for gzipped files to give the size of the uncompressed data. This fixes cache progress building progress going way over 100%.
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/fileutl.cc21
1 files changed, 20 insertions, 1 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index eabaadf90..bf07f6008 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -915,8 +915,27 @@ 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;
+ long size;
+ off_t orig_pos;
+
+ if (gz)
+ {
+ /* unfortunately zlib.h doesn't provide a gzsize(), so we have to do
+ * this ourselves; the original (uncompressed) file size is the last 32
+ * bits of the file */
+ orig_pos = lseek(iFd, 0, SEEK_CUR);
+ if (lseek(iFd, -4, SEEK_END) < 0)
+ return _error->Errno("lseek","Unable to seek to end of gzipped file");
+ if (read(iFd, &size, 4) != 4)
+ return _error->Errno("read","Unable to read original size of gzipped file");
+ size &= 0xFFFFFFFF;
+
+ if (lseek(iFd, orig_pos, SEEK_SET) < 0)
+ return _error->Errno("lseek","Unable to seek in gzipped file");
+ return size;
+ }
+
if (fstat(iFd,&Buf) != 0)
return _error->Errno("fstat","Unable to determine the file size");
return Buf.st_size;