+// FileFd::Size - Return the size of the content in the file /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+unsigned long long FileFd::Size()
+{
+ unsigned long long size = FileSize();
+
+ // for compressor pipes st_size is undefined and at 'best' zero,
+ // so we 'read' the content and 'seek' back - see there
+ if (d->pipe == true)
+ {
+ unsigned long long const oldSeek = Tell();
+ char ignore[1000];
+ unsigned long long read = 0;
+ do {
+ Read(ignore, sizeof(ignore), &read);
+ } while(read != 0);
+ size = Tell();
+ Seek(oldSeek);
+ }
+#if APT_USE_ZLIB
+ // only check gzsize if we are actually a gzip file, just checking for
+ // "gz" is not sufficient as uncompressed files could be opened with
+ // gzopen in "direct" mode as well
+ else if (d->gz && !gzdirect(d->gz) && size > 0)
+ {
+ off_t const oldPos = lseek(iFd,0,SEEK_CUR);
+ /* 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 */
+ // FIXME: Size for gz-files is limited by 32bit… no largefile support
+ if (lseek(iFd, -4, SEEK_END) < 0)
+ return _error->Errno("lseek","Unable to seek to end of gzipped file");
+ size = 0L;
+ if (read(iFd, &size, 4) != 4)
+ return _error->Errno("read","Unable to read original size of gzipped file");
+
+#ifdef WORDS_BIGENDIAN
+ uint32_t tmp_size = size;
+ uint8_t const * const p = (uint8_t const * const) &tmp_size;
+ tmp_size = (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0];
+ size = tmp_size;
+#endif
+
+ if (lseek(iFd, oldPos, SEEK_SET) < 0)
+ return _error->Errno("lseek","Unable to seek in gzipped file");
+
+ return size;
+ }
+#endif
+
+ return size;
+}
+ /*}}}*/
+// FileFd::ModificationTime - Return the time of last touch /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+time_t FileFd::ModificationTime()
+{
+ struct stat Buf;
+ if (d->pipe == false && fstat(iFd,&Buf) != 0)
+ {
+ _error->Errno("fstat","Unable to determine the modification time of file %s", FileName.c_str());
+ return 0;
+ }
+
+ // for compressor pipes st_size is undefined and at 'best' zero
+ if (d->pipe == true || S_ISFIFO(Buf.st_mode))
+ {
+ // we set it here, too, as we get the info here for free
+ // in theory the Open-methods should take care of it already
+ d->pipe = true;
+ if (stat(FileName.c_str(), &Buf) != 0)
+ {
+ _error->Errno("fstat","Unable to determine the modification time of file %s", FileName.c_str());
+ return 0;
+ }
+ }
+
+ return Buf.st_mtime;
+}
+ /*}}}*/