summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/fileutl.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2010-10-13 15:36:54 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2010-10-13 15:36:54 +0200
commit61153c284c832a0d0f7faecd9ad96f6cd9591c64 (patch)
treea60d61b723bbc90b8b715a476c5f1ee5e8d6e0c2 /apt-pkg/contrib/fileutl.cc
parent940ff5d6b5634b57c2e622b5295f499a7807f3de (diff)
parent6bea738672fb503d2813ae2d998096015a81c4a2 (diff)
merged from debian-sid branch
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r--apt-pkg/contrib/fileutl.cc25
1 files changed, 22 insertions, 3 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;