From 2dbb9bb3bdb826a7da41ba1ccd89f4f8c8ee529c Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 14 Dec 2011 01:11:07 -0800 Subject: [PATCH] hardlink_lockfile: preserve existing permissions --- pym/portage/locks.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pym/portage/locks.py b/pym/portage/locks.py index 297609c27..a645e255f 100644 --- a/pym/portage/locks.py +++ b/pym/portage/locks.py @@ -316,6 +316,7 @@ def hardlink_lockfile(lockfilename, max_wait=DeprecationWarning, global _quiet out = None displayed_waiting_msg = False + preexisting = os.path.exists(lockfilename) myhardlock = hardlock_name(lockfilename) # myhardlock must not exist prior to our link() call, and we can @@ -350,8 +351,11 @@ def hardlink_lockfile(lockfilename, max_wait=DeprecationWarning, myfd_st = None try: myfd_st = os.fstat(myfd) - if myfd_st.st_gid != portage_gid: - os.fchown(myfd, -1, portage_gid) + if not preexisting: + # Don't chown the file if it is preexisting, since we + # want to preserve existing permissions in that case. + if myfd_st.st_gid != portage_gid: + os.fchown(myfd, -1, portage_gid) except OSError as e: if e.errno not in (errno.ENOENT, errno.ESTALE): writemsg("%s: fchown('%s', -1, %d)\n" % \ -- 2.26.2