diff options
author | David Kalnischkies <david@kalnischkies.de> | 2014-04-11 11:22:10 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2014-04-11 11:22:10 +0200 |
commit | 230e69d718f761a39ee3ee057938dcd0264af74f (patch) | |
tree | b88edd6584609cb63343d78c74c9dbda29c089fa /apt-pkg | |
parent | 21ba8115c873ae4085770e4bf0bed765e0e099a6 (diff) |
deal with umask only if we really need to for mkstemp
As the comment actually says: open() does the umask dance by itself, so
we don't need to do it for it. We have to do it after mkstemp in Atomic
though, so move it into the if.
Also removes the "micro-optimisation" "FilePermissions == 600" as it
doesn't trigger at the moment anyway as 600 != 0600.
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index c51f75984..c9d419fc4 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1067,13 +1067,6 @@ bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Co if_FLAGGED_SET(Exclusive, O_EXCL); #undef if_FLAGGED_SET - // umask() will always set the umask and return the previous value, so - // we first set the umask and then reset it to the old value - mode_t CurrentUmask = umask(0); - umask(CurrentUmask); - // calculate the actual file permissions (just like open/creat) - mode_t FilePermissions = (AccessMode & ~CurrentUmask); - if ((Mode & Atomic) == Atomic) { char *name = strdup((FileName + ".XXXXXX").c_str()); @@ -1087,11 +1080,18 @@ bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Co TemporaryFileName = string(name); free(name); - if(FilePermissions != 600 && fchmod(iFd, FilePermissions) == -1) + // umask() will always set the umask and return the previous value, so + // we first set the umask and then reset it to the old value + mode_t const CurrentUmask = umask(0); + umask(CurrentUmask); + // calculate the actual file permissions (just like open/creat) + mode_t const FilePermissions = (AccessMode & ~CurrentUmask); + + if(fchmod(iFd, FilePermissions) == -1) return FileFdErrno("fchmod", "Could not change permissions for temporary file %s", TemporaryFileName.c_str()); } else - iFd = open(FileName.c_str(), fileflags, FilePermissions); + iFd = open(FileName.c_str(), fileflags, AccessMode); this->FileName = FileName; if (iFd == -1 || OpenInternDescriptor(Mode, compressor) == false) |