From 3a885cb10336c612c6ad2a19594a6d882a41b239 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 14 Nov 2006 02:43:22 +0000 Subject: [PATCH] Use try/finally to ensure that locks are properly released in emergelog(). svn path=/main/trunk/; revision=5032 --- bin/emerge | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/bin/emerge b/bin/emerge index 723e007c9..3a05d0378 100755 --- a/bin/emerge +++ b/bin/emerge @@ -242,15 +242,18 @@ def emergelog(xterm_titles, mystr, short_msg=None): portage_util.apply_secpass_permissions(file_path, uid=portage.portage_uid, gid=portage.portage_gid, mode=0660) - - l=portage_locks.lockfile(mylogfile) - # seek because we may have gotten held up by the lock. - # if so, we may not be positioned at the end of the file. - mylogfile.seek(0,2) - mylogfile.write(str(time.time())[:10]+": "+mystr+"\n") - mylogfile.flush() - portage_locks.unlockfile(l) - mylogfile.close() + mylock = None + try: + mylock = portage_locks.lockfile(mylogfile) + # seek because we may have gotten held up by the lock. + # if so, we may not be positioned at the end of the file. + mylogfile.seek(0, 2) + mylogfile.write(str(time.time())[:10]+": "+mystr+"\n") + mylogfile.flush() + finally: + if mylock: + portage_locks.unlockfile(mylock) + mylogfile.close() except (IOError,OSError,portage_exception.PortageException), e: if secpass >= 1: print >> sys.stderr, "emergelog():",e -- 2.26.2