mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-10 06:46:15 +01:00
- use a tempfile
This commit is contained in:
parent
f29fc17f83
commit
7d6ede13ab
21
osc/core.py
21
osc/core.py
@ -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')
|
||||
u = makeurl(apiurl, ['source', prj, package, pathname2url(filename)], query=query)
|
||||
for buf in streamfile(u, http_GET, BUFSIZE):
|
||||
o.write(buf)
|
||||
o.close()
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user