diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2013-08-27 21:50:22 +0200 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2013-08-27 21:50:22 +0200 |
commit | dc545c0bcd252bca491d0c669adddb5d62390a15 (patch) | |
tree | 39c79ef67e23a6551bbc2a725c8712e2ac9f3151 /apt-pkg | |
parent | 7335eebea6dd43581d4650a8818b06383ab89901 (diff) |
use mkstemp instead of mkostemp in FileFd::Open()
FileFd currently supports no fileflags which would make sense to provide
via mkostemp, so we can just use mkstemp here which is a standard
function compared to glib extension mkostemp.
O_CREAT (Create) and O_TRUNC (Empty) are implied by O_EXCL, which is the
mode mkstemp uses by default. The file description is opened ReadWrite,
but that used to be the default for FileFd in the old times and not a
problem as the difference is needed by FileFd to decide in which way the
compressor pipeline needs to be created (if any).
Git-Dch: Ignore
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 3eeef58cf..4806ae3f9 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -968,27 +968,23 @@ bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Co if_FLAGGED_SET(Create, O_CREAT); if_FLAGGED_SET(Empty, O_TRUNC); if_FLAGGED_SET(Exclusive, O_EXCL); - else if_FLAGGED_SET(Atomic, O_EXCL); #undef if_FLAGGED_SET if ((Mode & Atomic) == Atomic) { char *name = strdup((FileName + ".XXXXXX").c_str()); - if((iFd = mkostemp(name, fileflags)) == -1) + if((iFd = mkstemp(name)) == -1) { free(name); return FileFdErrno("mkostemp", "Could not create temporary file for %s", FileName.c_str()); } TemporaryFileName = string(name); - - if(fchmod(iFd, Perms) == -1) - { - free(name); - return FileFdErrno("fchmod", "Could not assign permissions to temporary file %s with error %s", FileName.c_str(), strerror(errno)); - } free(name); + + if(Perms != 600 && fchmod(iFd, Perms) == -1) + return FileFdErrno("fchmod", "Could not change permissions for temporary file %s", TemporaryFileName.c_str()); } else iFd = open(FileName.c_str(), fileflags, Perms); |