summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-11-14 02:08:07 +0000
committerZac Medico <zmedico@gentoo.org>2006-11-14 02:08:07 +0000
commitdd0f3834d1c0c13d42d4151c2568e6eaf3682518 (patch)
tree40e483e2d45c1587ccc66919867bed43812efeee
parenta414e6c2524bfb3d9177cd734effd5e7fc3c372b (diff)
downloadportage-dd0f3834d1c0c13d42d4151c2568e6eaf3682518.tar.gz
portage-dd0f3834d1c0c13d42d4151c2568e6eaf3682518.tar.bz2
portage-dd0f3834d1c0c13d42d4151c2568e6eaf3682518.zip
Use try/finally to ensure that locks are properly released in portdbapi.aux_get().
svn path=/main/trunk/; revision=5030
-rw-r--r--pym/portage.py71
1 files changed, 33 insertions, 38 deletions
diff --git a/pym/portage.py b/pym/portage.py
index 3e7777ab8..6baf2e55c 100644
--- a/pym/portage.py
+++ b/pym/portage.py
@@ -4924,7 +4924,6 @@ class portdbapi(dbapi):
def __init__(self,porttree_root,mysettings=None):
portdbapi.portdbapi_instances.append(self)
- self.lock_held = 0;
if mysettings:
self.mysettings = mysettings
@@ -5149,48 +5148,44 @@ class portdbapi(dbapi):
else:
mydbkey = self.depcachedir+"/aux_db_key_temp"
- if self.lock_held:
- raise "Lock is already held by me?"
- self.lock_held = 1
- mylock = portage_locks.lockfile(mydbkey, wantnewlockfile=1)
-
- if os.path.exists(mydbkey):
+ mylock = None
+ try:
+ portage_locks.lockfile(mydbkey, wantnewlockfile=1)
try:
os.unlink(mydbkey)
except (IOError, OSError), e:
- portage_locks.unlockfile(mylock)
- self.lock_held = 0
- writemsg("Uncaught handled exception: %(exception)s\n" % {"exception":str(e)})
- raise
-
- self.doebuild_settings.reset()
- myret = doebuild(myebuild, "depend", "/", self.doebuild_settings,
- dbkey=mydbkey, tree="porttree", mydbapi=self)
- if myret:
- portage_locks.unlockfile(mylock)
- self.lock_held = 0
- #depend returned non-zero exit code...
- writemsg(str(red("\naux_get():")+" (0) Error in "+mycpv+" ebuild. ("+str(myret)+")\n"
- " Check for syntax error or corruption in the ebuild. (--debug)\n\n"),
- noiselevel=-1)
- raise KeyError
-
- try:
- mycent=open(mydbkey,"r")
- os.unlink(mydbkey)
- mylines=mycent.readlines()
- mycent.close()
+ if e.errno != errno.ENOENT:
+ raise
+ del e
- except (IOError, OSError):
- portage_locks.unlockfile(mylock)
- self.lock_held = 0
- writemsg(str(red("\naux_get():")+" (1) Error in "+mycpv+" ebuild.\n"
- " Check for syntax error or corruption in the ebuild. (--debug)\n\n"),
- noiselevel=-1)
- raise KeyError
+ self.doebuild_settings.reset()
+ myret = doebuild(myebuild, "depend", "/",
+ self.doebuild_settings, dbkey=mydbkey, tree="porttree",
+ mydbapi=self)
+ if myret != os.EX_OK:
+ #depend returned non-zero exit code...
+ writemsg((red("\naux_get():") + \
+ " (0) Error in '%s'. (%s)\n" + \
+ " Check for syntax error or " + \
+ "corruption in the ebuild. (--debug)\n\n") % \
+ (myebuild, myret), noiselevel=-1)
+ raise KeyError(mycpv)
- portage_locks.unlockfile(mylock)
- self.lock_held = 0
+ try:
+ mycent = open(mydbkey, "r")
+ os.unlink(mydbkey)
+ mylines = mycent.readlines()
+ mycent.close()
+ except (IOError, OSError):
+ writemsg((red("\naux_get():") + \
+ " (1) Error in '%s' ebuild.\n" + \
+ " Check for syntax error or " + \
+ "corruption in the ebuild. (--debug)\n\n") % myebuild,
+ noiselevel=-1)
+ raise KeyError(mycpv)
+ finally:
+ if mylock:
+ portage_locks.unlockfile(mylock)
mydata = {}
for x in range(0,len(mylines)):