diff options
author | Richard Purdie <rpurdie@linux.intel.com> | 2008-12-06 12:09:11 +0000 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2008-12-06 12:09:11 +0000 |
commit | 2a2513138d9d1f5c7b6a1a6994b4f75deadb232c (patch) | |
tree | 9c90c6bc5f5962b36082bccc697e1cd7729c1728 | |
parent | f0a99305198672cba31ae3a77e750de72ab129f3 (diff) | |
download | bitbake-2a2513138d9d1f5c7b6a1a6994b4f75deadb232c.tar.gz |
utils.py: Improve lock file function error handling (from Poky)
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | lib/bb/utils.py | 27 |
2 files changed, 19 insertions, 9 deletions
@@ -162,6 +162,7 @@ Changes in Bitbake 1.9.x: - Add tryaltconfigs option to control whether bitbake trys using alternative providers to fulfil failed dependencies. It defaults to off, changing the default since this behaviour confuses many users and isn't often useful. + - Improve lock file function error handling Changes in Bitbake 1.8.0: - Release 1.7.x as a stable series diff --git a/lib/bb/utils.py b/lib/bb/utils.py index 904884550..59943bf55 100644 --- a/lib/bb/utils.py +++ b/lib/bb/utils.py @@ -235,6 +235,12 @@ def lockfile(name): 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): + import bb, sys + bb.msg.error(bb.msg.domain.Util, "Error, lockfile path does not exist!: %s" % path) + sys.exit(1) + while True: # If we leave the lockfiles lying around there is no problem # but we should clean up after ourselves. This gives potential @@ -246,15 +252,18 @@ def lockfile(name): # This implementation is unfair since the last person to request the # lock is the most likely to win it. - lf = open(name, "a+") - fcntl.flock(lf.fileno(), fcntl.LOCK_EX) - statinfo = os.fstat(lf.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 + try: + lf = open(name, "a+") + fcntl.flock(lf.fileno(), fcntl.LOCK_EX) + statinfo = os.fstat(lf.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, e: + continue def unlockfile(lf): """ |