]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-extracttemplates.cc
fix crash in order writing in pkgDPkgPM::WriteApportReport()
[apt.git] / cmdline / apt-extracttemplates.cc
index 2b01968e3117bb855f9d6f2780d8a6f248aa32e7..e4428e05154e26ad2b4cef7d36a0423965702242 100644 (file)
@@ -18,8 +18,8 @@
 #include <apt-pkg/init.h>
 #include <apt-pkg/cmndline.h>
 #include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 #include <apt-pkg/configuration.h>
-#include <apt-pkg/progress.h>
 #include <apt-pkg/sourcelist.h>
 #include <apt-pkg/pkgcachegen.h>
 #include <apt-pkg/version.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/pkgsystem.h>
+#include <apt-pkg/dirstream.h>
+#include <apt-pkg/mmap.h>
 
+#include <iostream>
 #include <stdio.h>
 #include <string.h>
-#include <stdlib.h>
 #include <unistd.h>
-#include <locale.h>
-
-#include <fstream>
+#include <stdlib.h>
 
 #include "apt-extracttemplates.h"
 
@@ -137,7 +137,7 @@ bool DebFile::DoItem(Item &I, int &Fd)
 // DebFile::Process examine element in package and copy                        /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool DebFile::Process(Item &I, const unsigned char *data, 
+bool DebFile::Process(Item &/*I*/, const unsigned char *data,
                unsigned long size, unsigned long pos)
 {
        switch (Which)
@@ -240,23 +240,25 @@ static int ShowHelp(void)
 static string WriteFile(const char *package, const char *prefix, const char *data)
 {
        char fn[512];
-       static int i;
 
         std::string tempdir = GetTempDir();
-       snprintf(fn, sizeof(fn), "%s/%s.%s.%u%d",
+       snprintf(fn, sizeof(fn), "%s/%s.%s.XXXXXX",
                  _config->Find("APT::ExtractTemplates::TempDir", 
                                tempdir.c_str()).c_str(),
-                 package, prefix, getpid(), i++);
+                 package, prefix);
        FileFd f;
        if (data == NULL)
                data = "";
-
-       if (!f.Open(fn, FileFd::WriteTemp, 0600))
+        int fd = mkstemp(fn);
+        if (fd < 0) {
+               _error->Errno("ofstream::ofstream",_("Unable to mkstemp %s"),fn);
+                return string();
+        }
+       if (!f.OpenDescriptor(fd, FileFd::WriteOnly, FileFd::None, true))
        {
                _error->Errno("ofstream::ofstream",_("Unable to write to %s"),fn);
                return string();
        }
-
        f.Write(data, strlen(data));
        f.Close();
        return fn;