Revert chown behavior change from the previous commit, so that chown will
authorZac Medico <zmedico@gentoo.org>
Fri, 16 Jan 2009 19:27:20 +0000 (19:27 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 16 Jan 2009 19:27:20 +0000 (19:27 -0000)
not be called on a pre-existing file.

svn path=/main/trunk/; revision=12522

pym/portage/locks.py

index be7cdf07d2075c4857a04b20afc5ca9264e48395..50fe317bfe72c5b94e97499be481db5eb1c1e261 100644 (file)
@@ -55,6 +55,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0,
        if type(mypath) == types.StringType:
                if not os.path.exists(os.path.dirname(mypath)):
                        raise DirectoryNotFound(os.path.dirname(mypath))
+               preexisting = os.path.exists(lockfilename)
                old_mask = os.umask(000)
                try:
                        try:
@@ -67,17 +68,21 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0,
                                        raise PermissionDenied(func_call)
                                else:
                                        raise
-                       try:
-                               if os.stat(lockfilename).st_gid != portage_gid:
-                                       os.chown(lockfilename, os.getuid(), portage_gid)
-                       except OSError, e:
-                               if e.errno == errno.ENOENT: # No such file or directory
-                                       return lockfile(mypath, wantnewlockfile=wantnewlockfile,
-                                               unlinkfile=unlinkfile, waiting_msg=waiting_msg,
-                                               flags=flags)
-                               else:
-                                       writemsg("Cannot chown a lockfile. This could " + \
-                                               "cause inconvenience later.\n")
+
+                       if not preexisting:
+                               try:
+                                       if os.stat(lockfilename).st_gid != portage_gid:
+                                               os.chown(lockfilename, -1, portage_gid)
+                               except OSError, e:
+                                       if e.errno == errno.ENOENT: # No such file or directory
+                                               return lockfile(mypath,
+                                                       wantnewlockfile=wantnewlockfile,
+                                                       unlinkfile=unlinkfile, waiting_msg=waiting_msg,
+                                                       flags=flags)
+                                       else:
+                                               writemsg("Cannot chown a lockfile. This could " + \
+                                                       "cause inconvenience later.\n")
+
                finally:
                        os.umask(old_mask)