Преглед изворни кода

* apt-pkg/contrib/fileutl.cc:
- Add FileFd::OpenDescriptor() (needed for python-apt's #383617).

Julian Andres Klode пре 16 година
родитељ
комит
144c096976
3 измењених фајлова са 24 додато и 0 уклоњено
  1. 18 0
      apt-pkg/contrib/fileutl.cc
  2. 4 0
      apt-pkg/contrib/fileutl.h
  3. 2 0
      debian/changelog

+ 18 - 0
apt-pkg/contrib/fileutl.cc

@@ -700,6 +700,24 @@ bool FileFd::Open(string FileName,OpenMode Mode, unsigned long Perms)
    SetCloseExec(iFd,true);
    return true;
 }
+
+bool FileFd::OpenDescriptor(int Fd, OpenMode Mode, bool AutoClose)
+{
+   Close();
+   Flags = (AutoClose) ? FileFd::AutoClose : 0;
+   iFd = Fd;
+   if (Mode == ReadOnlyGzip) {
+      gz = gzdopen (iFd, "r");
+      if (gz == NULL) {
+	 if (AutoClose)
+	    close (iFd);
+	 return _error->Errno("gzdopen",_("Could not open file descriptor %d"),
+			      Fd);
+      }
+   }
+   this->FileName = "";
+   return true;
+}
 									/*}}}*/
 // FileFd::~File - Closes the file					/*{{{*/
 // ---------------------------------------------------------------------

+ 4 - 0
apt-pkg/contrib/fileutl.h

@@ -28,6 +28,9 @@
 
 #include <zlib.h>
 
+/* Define this for python-apt */
+#define APT_HAS_GZIP 1
+
 using std::string;
 
 class FileFd
@@ -60,6 +63,7 @@ class FileFd
    unsigned long Tell();
    unsigned long Size();
    bool Open(string FileName,OpenMode Mode,unsigned long Perms = 0666);
+   bool OpenDescriptor(int Fd, OpenMode Mode, bool AutoClose=false);
    bool Close();
    bool Sync();
    

+ 2 - 0
debian/changelog

@@ -3,6 +3,8 @@ apt (0.7.26~exp11) experimental; urgency=low
   * apt-pkg/deb/dpkgpm.cc:
     - Write architecture information to history file.
     - Add to history whether a change was automatic or not.
+  * apt-pkg/contrib/fileutl.cc:
+    - Add FileFd::OpenDescriptor() (needed for python-apt's #383617).
 
  -- Julian Andres Klode <jak@debian.org>  Wed, 21 Jul 2010 17:09:11 +0200