diff options
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 25 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.h | 2 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.cc | 4 |
3 files changed, 25 insertions, 6 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 94d994e8b..bf07f6008 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -251,11 +251,11 @@ bool CreateDirectory(string const &Parent, string const &Path) return true; } /*}}}*/ -// CheckDirectory - ensure that the given directory exists /*{{{*/ +// CreateAPTDirectoryIfNeeded - ensure that the given directory exists /*{{{*/ // --------------------------------------------------------------------- /* a small wrapper around CreateDirectory to check if it exists and to remove the trailing "/apt/" from the parent directory if needed */ -bool CheckDirectory(string const &Parent, string const &Path) +bool CreateAPTDirectoryIfNeeded(string const &Parent, string const &Path) { if (DirectoryExists(Path) == true) return true; @@ -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/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index f79c9032f..419506273 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -101,7 +101,7 @@ bool CreateDirectory(string const &Parent, string const &Path); * /apt/ will be removed before CreateDirectory call. * \param Path which should exist after (successful) call */ -bool CheckDirectory(string const &Parent, string const &Path); +bool CreateAPTDirectoryIfNeeded(string const &Parent, string const &Path); std::vector<string> GetListOfFilesInDir(string const &Dir, string const &Ext, bool const &SortList, bool const &AllowNoExt=false); 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; |