Przeglądaj źródła

* 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%.

Martin Pitt 15 lat temu
rodzic
commit
9c182afa04
2 zmienionych plików z 24 dodań i 1 usunięć
  1. 20 1
      apt-pkg/contrib/fileutl.cc
  2. 4 0
      debian/changelog

+ 20 - 1
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;

+ 4 - 0
debian/changelog

@@ -11,6 +11,10 @@ apt (0.8.7) UNRELEASED; urgency=low
     - Use FileFd::Size() instead of stat()ing the sources/binary/translations
       indexes directly, so that we have transparent handling of gzipped
       indexes.
+  * 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%.
 
  -- Christian Perrier <bubulle@debian.org>  Tue, 05 Oct 2010 05:35:58 +0200