[yum-commits] Branch 'yum-3_2_X' - yum/__init__.py

James Antill james at osuosl.org
Fri Jan 7 00:46:56 UTC 2011


 yum/__init__.py |   18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

New commits:
commit 69300791769eda9b5d8bef3c2416fdd3ea57e4c8
Author: James Antill <james at and.org>
Date:   Thu Jan 6 10:58:46 2011 -0500

    Do locking for non-root users, using cachedir. BZ 590675.

diff --git a/yum/__init__.py b/yum/__init__.py
index 6bb1614..39ed0db 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -1674,11 +1674,13 @@ class YumBase(depsolve.Depsolve):
     def doLock(self, lockfile = YUM_PID_FILE):
         """perform the yum locking, raise yum-based exceptions, not OSErrors"""
         
-        # if we're not root then we don't lock - just return nicely
+        # if we're not root then lock the cache
         if self.conf.uid != 0:
-            return
-            
-        root = self.conf.installroot
+            root = self.conf.cachedir
+            # Don't want <cachedir>/var/run/yum.pid ... just: <cachedir>/yum.pid
+            lockfile = os.path.basename(lockfile)
+        else:
+            root = self.conf.installroot
         lockfile = root + '/' + lockfile # lock in the chroot
         lockfile = os.path.normpath(lockfile) # get rid of silly preceding extra /
         
@@ -1720,8 +1722,14 @@ class YumBase(depsolve.Depsolve):
         #  Note that we can get here from __del__, so if we haven't created
         # YumBase.conf we don't want to do so here as creating stuff inside
         # __del__ is bad.
-        if hasattr(self, 'preconf') or self.conf.uid != 0:
+        if hasattr(self, 'preconf'):
             return
+
+        #  Obviously, we can't lock random places as non-root, but we still want
+        # to get rid of our lock file. Given we now have _lockfile I'm pretty
+        # sure nothing should ever pass lockfile in here anyway.
+        if self.conf.uid != 0:
+            lockfile = None
         
         if lockfile is not None:
             root = self.conf.installroot


More information about the Yum-commits mailing list