From f1a04bc50d0b53460acaa37afa3edabedae0921f Mon Sep 17 00:00:00 2001 From: Marcus Huewe Date: Fri, 5 Feb 2010 15:17:45 +0100 Subject: [PATCH] - always close the file --- osc/core.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/osc/core.py b/osc/core.py index 5f35ee5b..7cdcb074 100644 --- a/osc/core.py +++ b/osc/core.py @@ -2707,19 +2707,20 @@ def get_source_file(apiurl, prj, package, filename, targetfilename=None, revisio query = { 'rev': revision } o = None try: - (fd, tmpfile) = tempfile.mkstemp(prefix = filename, suffix = '.osc') - o = os.fdopen(fd, 'wb') - u = makeurl(apiurl, ['source', prj, package, pathname2url(filename)], query=query) - for buf in streamfile(u, http_GET, BUFSIZE): - o.write(buf) - o.close() - shutil.move(tmpfile, targetfilename or filename) - except: + try: + (fd, tmpfile) = tempfile.mkstemp(prefix = filename, suffix = '.osc') + o = os.fdopen(fd, 'wb') + u = makeurl(apiurl, ['source', prj, package, pathname2url(filename)], query=query) + for buf in streamfile(u, http_GET, BUFSIZE): + o.write(buf) + o.close() + shutil.move(tmpfile, targetfilename or filename) + except: + os.unlink(tmpfile) + raise + finally: if o is not None: o.close() - os.unlink(tmpfile) - raise - def get_binary_file(apiurl, prj, repo, arch, filename,