1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-09-20 09:16:16 +02:00

- use a tempfile

This commit is contained in:
Marcus Huewe 2010-02-04 20:32:59 +01:00
parent f29fc17f83
commit 7d6ede13ab

View File

@ -2701,15 +2701,24 @@ def get_user_data(apiurl, user, *tags):
def get_source_file(apiurl, prj, package, filename, targetfilename=None, revision = None):
import tempfile, shutil
query = None
if revision:
query = { 'rev': revision }
o = open(targetfilename or filename, 'wb')
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:
if o is not None:
o.close()
os.unlink(tmpfile)
raise
def get_binary_file(apiurl, prj, repo, arch,