From: Zac Medico Date: Tue, 14 Nov 2006 02:43:22 +0000 (-0000) Subject: Use try/finally to ensure that locks are properly released in emergelog(). X-Git-Tag: v2.1.2~473 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3a885cb10336c612c6ad2a19594a6d882a41b239;p=portage.git Use try/finally to ensure that locks are properly released in emergelog(). svn path=/main/trunk/; revision=5032 --- 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