Bug 485390 - utils.lockFile doesn't hold the file descriptor, which can cause parallel races in JarMaker, r=ted

This commit is contained in:
Benjamin Smedberg 2009-03-30 10:34:13 -04:00
parent f361caeff0
commit 5cb4a30638

View File

@ -50,9 +50,11 @@ class LockFile(object):
This object should not be used directly, but only through
the lockFile method below.
'''
def __init__(self, lockfile):
def __init__(self, lockfile, fd):
self.lockfile = lockfile
self.fd = fd
def __del__(self):
os.close(self.fd)
os.remove(self.lockfile)
@ -100,10 +102,8 @@ def lockFile(lockfile, max_wait = 600):
# if we get here. we have the lockfile. Convert the os.open file
# descriptor into a Python file object and record our PID in it
f = os.fdopen(fd, "w")
f.write("%d\n" % os.getpid())
f.close()
return LockFile(lockfile)
os.write(fd, "%d\n" % os.getpid())
return LockFile(lockfile, fd)
class pushback_iter(object):
'''Utility iterator that can deal with pushed back elements.