summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <mvo@ubuntu.com>2014-04-10 09:11:57 +0200
committerMichael Vogt <mvo@ubuntu.com>2014-04-10 09:11:57 +0200
commitdb5bf949ed796395d281474c49033f882e73f3a9 (patch)
tree2e619308ff0b07f5ebe9d563aa8b9818c8653fa9
parente5f3f8c101b772a6eb6326203a2174e809ab406d (diff)
improve umask/fchmod code readability
-rw-r--r--apt-pkg/contrib/fileutl.cc13
1 files changed, 8 insertions, 5 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index c6072ca15..69a675648 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -1067,9 +1067,12 @@ bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Co
if_FLAGGED_SET(Exclusive, O_EXCL);
#undef if_FLAGGED_SET
- // there is no getumask() so we read it by setting it and reset
- mode_t current_umask = umask(0);
- umask(current_umask);
+ // 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)
{
@@ -1084,11 +1087,11 @@ bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Co
TemporaryFileName = string(name);
free(name);
- if(AccessMode != 600 && fchmod(iFd, AccessMode & ~current_umask) == -1)
+ if(FilePermissions != 600 && 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, AccessMode & ~current_umask);
+ iFd = open(FileName.c_str(), fileflags, FilePermissions);
this->FileName = FileName;
if (iFd == -1 || OpenInternDescriptor(Mode, compressor) == false)