From: Steven Walter Date: Wed, 3 Dec 2008 21:14:38 +0000 (-0500) Subject: workdir: cleanup the created tmp file X-Git-Tag: v0.3~2^2 X-Git-Url: https://repo.or.cz/w/yap.git/commitdiff_plain/4e7b0faa9bb7fb55a7a8302e985d792857b1d7ea workdir: cleanup the created tmp file --- diff --git a/plugins/workdir.py b/plugins/workdir.py index f9b4353..1c6eb46 100644 --- a/plugins/workdir.py +++ b/plugins/workdir.py @@ -35,24 +35,27 @@ class WorkdirPlugin(YapCore): pass fd, tmplock = tempfile.mkstemp("yap", dir=dir) - os.write(fd, locked_by) - os.close(fd) - while True: - lockfile = os.path.join(dir, branch.replace('/', '\/')) - try: - os.link(tmplock, lockfile) - break - except OSError, e: + try: + os.write(fd, locked_by) + os.close(fd) + while True: + lockfile = os.path.join(dir, branch.replace('/', '\/')) try: - fd = file(lockfile) - except: - raise e - user = fd.readline() - # If the workdir has been deleted, break his lock - if os.access(user, os.R_OK): - raise YapError("That branch is being used by an existing workdir") - os.unlink(lockfile) - continue + os.link(tmplock, lockfile) + break + except OSError, e: + try: + fd = file(lockfile) + except: + raise e + user = fd.readline() + # If the workdir has been deleted, break his lock + if os.access(user, os.R_OK): + raise YapError("That branch is being used by an existing workdir") + os.unlink(lockfile) + continue + finally: + os.unlink(tmplock) def cmd_workdir(self, branch, workdir=None): " [workdir]"