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):
|
def get_source_file(apiurl, prj, package, filename, targetfilename=None, revision = None):
|
||||||
|
import tempfile, shutil
|
||||||
query = None
|
query = None
|
||||||
if revision:
|
if revision:
|
||||||
query = { 'rev': revision }
|
query = { 'rev': revision }
|
||||||
|
o = None
|
||||||
o = open(targetfilename or filename, 'wb')
|
try:
|
||||||
u = makeurl(apiurl, ['source', prj, package, pathname2url(filename)], query=query)
|
(fd, tmpfile) = tempfile.mkstemp(prefix = filename, suffix = '.osc')
|
||||||
for buf in streamfile(u, http_GET, BUFSIZE):
|
o = os.fdopen(fd, 'wb')
|
||||||
o.write(buf)
|
u = makeurl(apiurl, ['source', prj, package, pathname2url(filename)], query=query)
|
||||||
o.close()
|
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,
|
def get_binary_file(apiurl, prj, repo, arch,
|
||||||
|
Loading…
Reference in New Issue
Block a user