Use try/finally to ensure that locks are properly released in emergelog().
authorZac Medico <zmedico@gentoo.org>
Tue, 14 Nov 2006 02:43:22 +0000 (02:43 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 14 Nov 2006 02:43:22 +0000 (02:43 -0000)
svn path=/main/trunk/; revision=5032

bin/emerge

index 723e007c94db51d933fd454148ddcd41c6b76e40..3a05d0378b5cf3281c56a790aadb6f5f3a1ca0e1 100755 (executable)
@@ -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