summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-11-14 02:29:54 +0000
committerZac Medico <zmedico@gentoo.org>2006-11-14 02:29:54 +0000
commit6164520eb5a263f132e2c645e374a66f279e5cd7 (patch)
tree03a4f54b8f2d31af2b1d7abd861f17b540af8178
parentdd0f3834d1c0c13d42d4151c2568e6eaf3682518 (diff)
downloadportage-6164520eb5a263f132e2c645e374a66f279e5cd7.tar.gz
portage-6164520eb5a263f132e2c645e374a66f279e5cd7.tar.bz2
portage-6164520eb5a263f132e2c645e374a66f279e5cd7.zip
Use try/finally to ensure that locks are properly released in perform_checksum().
svn path=/main/trunk/; revision=5031
-rw-r--r--pym/portage_checksum.py54
1 files changed, 27 insertions, 27 deletions
diff --git a/pym/portage_checksum.py b/pym/portage_checksum.py
index a23ac7a56..7f1a89c8e 100644
--- a/pym/portage_checksum.py
+++ b/pym/portage_checksum.py
@@ -166,35 +166,35 @@ def perform_checksum(filename, hashname="MD5", calc_prelink=0):
myfilename = filename[:]
prelink_tmpfile = os.path.join("/", PRIVATE_PATH, "prelink-checksum.tmp." + str(os.getpid()))
mylock = None
-
- if calc_prelink and prelink_capable:
- mylock = portage_locks.lockfile(prelink_tmpfile, wantnewlockfile=1)
- # Create non-prelinked temporary file to checksum.
- # Files rejected by prelink are summed in place.
- retval=portage_exec.spawn([PRELINK_BINARY,"--undo","-o",prelink_tmpfile,filename],fd_pipes={})
- if retval==0:
- #portage_util.writemsg(">>> prelink checksum '"+str(filename)+"'.\n")
- myfilename=prelink_tmpfile
try:
- if hashname not in hashfunc_map:
- raise portage_exception.DigestException, hashname+" hash function not available (needs dev-python/pycrypto)"
- myhash, mysize = hashfunc_map[hashname](myfilename)
- except (OSError, IOError), e:
- if e.errno == errno.ENOENT:
- raise portage_exception.FileNotFound(myfilename)
- else:
- raise
- if calc_prelink and prelink_capable:
+ if calc_prelink and prelink_capable:
+ mylock = portage_locks.lockfile(prelink_tmpfile, wantnewlockfile=1)
+ # Create non-prelinked temporary file to checksum.
+ # Files rejected by prelink are summed in place.
+ retval = portage_exec.spawn([PRELINK_BINARY, "--undo", "-o",
+ prelink_tmpfile, filename], fd_pipes={})
+ if retval == os.EX_OK:
+ myfilename = prelink_tmpfile
try:
- os.unlink(prelink_tmpfile)
- except OSError, oe:
- if oe.errno == errno.ENOENT:
- pass
- else:
- raise
- portage_locks.unlockfile(mylock)
-
- return (myhash,mysize)
+ if hashname not in hashfunc_map:
+ raise portage_exception.DigestException(hashname + \
+ " hash function not available (needs dev-python/pycrypto)")
+ myhash, mysize = hashfunc_map[hashname](myfilename)
+ except (OSError, IOError), e:
+ if e.errno == errno.ENOENT:
+ raise portage_exception.FileNotFound(myfilename)
+ raise
+ if calc_prelink and prelink_capable:
+ try:
+ os.unlink(prelink_tmpfile)
+ except OSError, e:
+ if e.errno != errno.ENOENT:
+ raise
+ del e
+ return myhash, mysize
+ finally:
+ if mylock:
+ portage_locks.unlockfile(mylock)
def perform_multiple_checksums(filename, hashes=["MD5"], calc_prelink=0):
"""