|
@@ -37,6 +37,7 @@
|
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
#include <unistd.h>
|
|
#include <unistd.h>
|
|
|
|
|
+#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "apt-extracttemplates.h"
|
|
#include "apt-extracttemplates.h"
|
|
|
|
|
|
|
@@ -239,23 +240,25 @@ static int ShowHelp(void)
|
|
|
static string WriteFile(const char *package, const char *prefix, const char *data)
|
|
static string WriteFile(const char *package, const char *prefix, const char *data)
|
|
|
{
|
|
{
|
|
|
char fn[512];
|
|
char fn[512];
|
|
|
- static int i;
|
|
|
|
|
|
|
|
|
|
std::string tempdir = GetTempDir();
|
|
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",
|
|
_config->Find("APT::ExtractTemplates::TempDir",
|
|
|
tempdir.c_str()).c_str(),
|
|
tempdir.c_str()).c_str(),
|
|
|
- package, prefix, getpid(), i++);
|
|
|
|
|
|
|
+ package, prefix);
|
|
|
FileFd f;
|
|
FileFd f;
|
|
|
if (data == NULL)
|
|
if (data == NULL)
|
|
|
data = "";
|
|
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);
|
|
_error->Errno("ofstream::ofstream",_("Unable to write to %s"),fn);
|
|
|
return string();
|
|
return string();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
f.Write(data, strlen(data));
|
|
f.Write(data, strlen(data));
|
|
|
f.Close();
|
|
f.Close();
|
|
|
return fn;
|
|
return fn;
|