summaryrefslogtreecommitdiffstats
path: root/lib/bb/utils.py
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2011-03-08 09:33:40 -0700
committerChris Larson <chris_larson@mentor.com>2011-03-08 09:38:24 -0700
commit238151441c74db53d6e4d4753f4f96c32f6f13b6 (patch)
tree4807dc3b5f87a2e8b9b8b6b30f1790e802356038 /lib/bb/utils.py
parent43dddb2f9689d523588146df3eb86e11f554a8c0 (diff)
downloadbitbake-contrib-238151441c74db53d6e4d4753f4f96c32f6f13b6.tar.gz
lockfile: ask for forgiveness, not permission
Create the lockfile directory if it doesn't exist, rather than erroring out if it doesn't exist (was also racy). Also improve the wording of the error message shown when the lockfile's directory is not writable. Note for the future, this function should be improved, particularly with regard to its exception handling. It should be catching the *exact* exception(s) it will encounter when the file is locked, and continuing in that case only. If it did that, there'd be no need for the proactive directory writability check, as bb.utils.lockfile() would raise an appropriate IOError for that case. Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'lib/bb/utils.py')
-rw-r--r--lib/bb/utils.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 44419d8f2..5a4e5731d 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -407,13 +407,12 @@ def lockfile(name, shared=False):
Use the file fn as a lock file, return when the lock has been acquired.
Returns a variable to pass to unlockfile().
"""
- path = os.path.dirname(name)
- if not os.path.isdir(path):
- logger.error("Lockfile destination directory '%s' does not exist", path)
- sys.exit(1)
+ dirname = os.path.dirname(name)
+ mkdirhier(dirname)
- if not os.access(path, os.W_OK):
- logger.error("Error, lockfile path is not writable!: %s" % path)
+ if not os.access(dirname, os.W_OK):
+ logger.error("Unable to acquire lock '%s', directory is not writable",
+ dirname)
sys.exit(1)
op = fcntl.LOCK_EX
@@ -449,7 +448,7 @@ def unlockfile(lf):
Unlock a file locked using lockfile()
"""
try:
- # If we had a shared lock, we need to promote to exclusive before
+ # If we had a shared lock, we need to promote to exclusive before
# removing the lockfile. Attempt this, ignore failures.
fcntl.flock(lf.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
os.unlink(lf.name)