diff options
author | Chris Larson <chris_larson@mentor.com> | 2010-12-09 21:50:23 -0500 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2011-01-04 14:46:48 +0000 |
commit | 25e519a80fc453de1468823b2bf26ab053aa0dca (patch) | |
tree | 05d4d35e663728fda034992554ad9a2913eabe16 /bitbake/lib/bb/utils.py | |
parent | e2363f3cdddb597c0321b6c396306be966ac58f9 (diff) | |
download | poky-25e519a80fc453de1468823b2bf26ab053aa0dca.tar.gz |
utils: fix calls to close() in the lock/unlock functions
(Bitbake rev: 4262c26d36d1c1b6801ac422716a227c1f6b9589)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r-- | bitbake/lib/bb/utils.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index ba50801ae9..107b001401 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -401,6 +401,7 @@ def better_eval(source, locals): | |||
401 | 401 | ||
402 | @contextmanager | 402 | @contextmanager |
403 | def fileslocked(files): | 403 | def fileslocked(files): |
404 | """Context manager for locking and unlocking file locks.""" | ||
404 | locks = [] | 405 | locks = [] |
405 | if files: | 406 | if files: |
406 | for lockfile in files: | 407 | for lockfile in files: |
@@ -418,7 +419,7 @@ def lockfile(name): | |||
418 | """ | 419 | """ |
419 | path = os.path.dirname(name) | 420 | path = os.path.dirname(name) |
420 | if not os.path.isdir(path): | 421 | if not os.path.isdir(path): |
421 | logger.error("Lockfile path '%s' does not exist", path) | 422 | logger.error("Lockfile destination directory '%s' does not exist", path) |
422 | sys.exit(1) | 423 | sys.exit(1) |
423 | 424 | ||
424 | if not os.access(path, os.W_OK): | 425 | if not os.access(path, os.W_OK): |
@@ -437,16 +438,16 @@ def lockfile(name): | |||
437 | # lock is the most likely to win it. | 438 | # lock is the most likely to win it. |
438 | 439 | ||
439 | try: | 440 | try: |
440 | lf = open(name, "a + ") | 441 | lf = open(name, 'a+') |
441 | fcntl.flock(lf.fileno(), fcntl.LOCK_EX) | 442 | fileno = lf.fileno() |
442 | statinfo = os.fstat(lf.fileno()) | 443 | fcntl.flock(fileno, fcntl.LOCK_EX) |
444 | statinfo = os.fstat(fileno) | ||
443 | if os.path.exists(lf.name): | 445 | if os.path.exists(lf.name): |
444 | statinfo2 = os.stat(lf.name) | 446 | statinfo2 = os.stat(lf.name) |
445 | if statinfo.st_ino == statinfo2.st_ino: | 447 | if statinfo.st_ino == statinfo2.st_ino: |
446 | return lf | 448 | return lf |
447 | # File no longer exists or changed, retry | 449 | lf.close() |
448 | lf.close | 450 | except Exception: |
449 | except Exception as e: | ||
450 | continue | 451 | continue |
451 | 452 | ||
452 | def unlockfile(lf): | 453 | def unlockfile(lf): |
@@ -455,7 +456,7 @@ def unlockfile(lf): | |||
455 | """ | 456 | """ |
456 | os.unlink(lf.name) | 457 | os.unlink(lf.name) |
457 | fcntl.flock(lf.fileno(), fcntl.LOCK_UN) | 458 | fcntl.flock(lf.fileno(), fcntl.LOCK_UN) |
458 | lf.close | 459 | lf.close() |
459 | 460 | ||
460 | def md5_file(filename): | 461 | def md5_file(filename): |
461 | """ | 462 | """ |