From 3451b86a6927ab7b21ae8e8a0421e4c51597df1d Mon Sep 17 00:00:00 2001 From: Prashanth Pai Date: Fri, 18 Mar 2016 18:25:36 +0530 Subject: Don't (f)chown when it has no effect For (f)chown calls which can change both UID and GID at once, -1 is reserved as a sentinel value to indicate "omitted argument" or "do not change". This makes sense when one of the args to (f)chown is -1. When both uid and gid args are -1, it doesn't make sense to call (f)chown as neither is going to be changed. Further, as of today, diskfile doesn't get the information (uid and gid) of the authenticated user from auth middleware. Retained the calls in code for future when such functionality might be added. Change-Id: If8463ae78a32c379d698260879810ed3c207af02 Signed-off-by: Prashanth Pai Reviewed-on: http://review.gluster.org/13778 Reviewed-by: Thiago da Silva Tested-by: Thiago da Silva --- gluster/swift/obj/diskfile.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'gluster') diff --git a/gluster/swift/obj/diskfile.py b/gluster/swift/obj/diskfile.py index 2e0837e..f140a62 100644 --- a/gluster/swift/obj/diskfile.py +++ b/gluster/swift/obj/diskfile.py @@ -164,7 +164,12 @@ def make_directory(full_path, uid, gid, metadata=None): # We created it, so we are reponsible for always setting the proper # ownership. - do_chown(full_path, uid, gid) + if not ((uid == DEFAULT_UID) and (gid == DEFAULT_GID)): + # If both UID and GID is -1 (default values), it has no effect. + # So don't do a chown. + # Further, at the time of this writing, UID and GID information + # is not passed to DiskFile. + do_chown(full_path, uid, gid) return True, metadata @@ -965,7 +970,12 @@ class DiskFile(object): dw = None try: # Ensure it is properly owned before we make it available. - do_fchown(fd, self._uid, self._gid) + if not ((self._uid == DEFAULT_UID) and (self._gid == DEFAULT_GID)): + # If both UID and GID is -1 (default values), it has no effect. + # So don't do a fchown. + # Further, at the time of this writing, UID and GID information + # is not passed to DiskFile. + do_fchown(fd, self._uid, self._gid) # NOTE: we do not perform the fallocate() call at all. We ignore # it completely since at the time of this writing FUSE does not # support it. -- cgit