From 5473df3fec08eaea6e84b98551cc247e87f4b6df Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 13 Oct 2010 12:45:47 +0200 Subject: * apt-pkg/deb/debindexfile.cc: - Use FileFd::Size() instead of stat()ing the sources/binary/translations indexes directly, so that we have transparent handling of gzipped indexes. --- apt-pkg/deb/debindexfile.cc | 22 +++++++++++++--------- debian/changelog | 6 ++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index ba5b3f266..a89a2574f 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -149,10 +149,11 @@ bool debSourcesIndex::Exists() const /* */ unsigned long debSourcesIndex::Size() const { - struct stat S; - if (stat(IndexFile("Sources").c_str(),&S) != 0) + FileFd f = FileFd (IndexFile("Sources"), FileFd::ReadOnlyGzip); + + if (f.Failed()) return 0; - return S.st_size; + return f.Size(); } /*}}}*/ @@ -268,10 +269,11 @@ bool debPackagesIndex::Exists() const /* This is really only used for progress reporting. */ unsigned long debPackagesIndex::Size() const { - struct stat S; - if (stat(IndexFile("Packages").c_str(),&S) != 0) + FileFd f = FileFd (IndexFile("Packages"), FileFd::ReadOnlyGzip); + + if (f.Failed()) return 0; - return S.st_size; + return f.Size(); } /*}}}*/ // PackagesIndex::Merge - Load the index file into a cache /*{{{*/ @@ -458,10 +460,12 @@ bool debTranslationsIndex::Exists() const /* This is really only used for progress reporting. */ unsigned long debTranslationsIndex::Size() const { - struct stat S; - if (stat(IndexFile(Language).c_str(),&S) != 0) + FileFd f = FileFd (IndexFile(Language), FileFd::ReadOnlyGzip); + + if (f.Failed()) return 0; - return S.st_size; + + return f.Size(); } /*}}}*/ // TranslationsIndex::Merge - Load the index file into a cache /*{{{*/ diff --git a/debian/changelog b/debian/changelog index e7d784eb8..ad6d05cf0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,12 @@ apt (0.8.7) UNRELEASED; urgency=low * Wrong translation for "showauto" fixed. Thanks to Raphaƫl Hertzog Closes: #599265 + [ Martin Pitt ] + * apt-pkg/deb/debindexfile.cc: + - Use FileFd::Size() instead of stat()ing the sources/binary/translations + indexes directly, so that we have transparent handling of gzipped + indexes. + -- Christian Perrier Tue, 05 Oct 2010 05:35:58 +0200 apt (0.8.6) unstable; urgency=low -- cgit v1.2.3 From 9c182afa045dc889a5025d166328c6115924d706 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 13 Oct 2010 13:00:49 +0200 Subject: * 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%. --- apt-pkg/contrib/fileutl.cc | 21 ++++++++++++++++++++- debian/changelog | 4 ++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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; diff --git a/debian/changelog b/debian/changelog index ad6d05cf0..f1737a5a2 100644 --- a/debian/changelog +++ b/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 Tue, 05 Oct 2010 05:35:58 +0200 -- cgit v1.2.3 From e344c4a7a1569c77ef8f8921852fd9822ee64b90 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 13 Oct 2010 14:34:23 +0200 Subject: fix changelog typo --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 3a552d01e..739f1b425 100644 --- a/debian/changelog +++ b/debian/changelog @@ -23,7 +23,7 @@ apt (0.8.7) UNRELEASED; urgency=low 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 + uncompressed data. This fixes cache building progress going way over 100%. -- Christian Perrier Tue, 05 Oct 2010 05:35:58 +0200 -- cgit v1.2.3