summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/fileutl.cc28
-rw-r--r--apt-pkg/contrib/strutl.cc4
2 files changed, 28 insertions, 4 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index eabaadf90..cbf1d64a9 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -915,11 +915,35 @@ 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;
+ unsigned long size;
+ off_t orig_pos;
+
if (fstat(iFd,&Buf) != 0)
return _error->Errno("fstat","Unable to determine the file size");
- return Buf.st_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
+ * 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;
+ }
+
+ return size;
}
/*}}}*/
// FileFd::Close - Close the file if the close flag is set /*{{{*/
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index c1844de40..987f4c3a4 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -340,13 +340,13 @@ string SizeToStr(double Size)
{
if (ASize < 100 && I != 0)
{
- sprintf(S,"%'.1f%c",ASize,Ext[I]);
+ sprintf(S,"%'.1f %c",ASize,Ext[I]);
break;
}
if (ASize < 10000)
{
- sprintf(S,"%'.0f%c",ASize,Ext[I]);
+ sprintf(S,"%'.0f %c",ASize,Ext[I]);
break;
}
ASize /= 1000.0;