]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
utils: fix calls to close() in the lock/unlock functions
authorChris Larson <chris_larson@mentor.com>
Fri, 10 Dec 2010 02:50:23 +0000 (21:50 -0500)
committerChris Larson <chris_larson@mentor.com>
Fri, 10 Dec 2010 03:26:33 +0000 (22:26 -0500)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
lib/bb/utils.py

index c96d72cdde79e21a6cf6343f885184c609e8ad49..fcb180c51a9304fb848fa2a6aefd524b091b5d62 100644 (file)
@@ -367,6 +367,7 @@ def better_eval(source, locals):
 
 @contextmanager
 def fileslocked(files):
+    """Context manager for locking and unlocking file locks."""
     locks = []
     if files:
         for lockfile in files:
@@ -384,7 +385,7 @@ def lockfile(name):
     """
     path = os.path.dirname(name)
     if not os.path.isdir(path):
-        logger.error("Lockfile path '%s' does not exist", path)
+        logger.error("Lockfile destination directory '%s' does not exist", path)
         sys.exit(1)
 
     while True:
@@ -399,16 +400,16 @@ def lockfile(name):
         # lock is the most likely to win it.
 
         try:
-            lf = open(name, "a + ")
-            fcntl.flock(lf.fileno(), fcntl.LOCK_EX)
-            statinfo = os.fstat(lf.fileno())
+            lf = open(name, 'a+')
+            fileno = lf.fileno()
+            fcntl.flock(fileno, fcntl.LOCK_EX)
+            statinfo = os.fstat(fileno)
             if os.path.exists(lf.name):
                 statinfo2 = os.stat(lf.name)
                 if statinfo.st_ino == statinfo2.st_ino:
                     return lf
-            # File no longer exists or changed, retry
-            lf.close
-        except Exception as e:
+            lf.close()
+        except Exception:
             continue
 
 def unlockfile(lf):
@@ -417,7 +418,7 @@ def unlockfile(lf):
     """
     os.unlink(lf.name)
     fcntl.flock(lf.fileno(), fcntl.LOCK_UN)
-    lf.close
+    lf.close()
 
 def md5_file(filename):
     """