fix downloads w/o content-length

Fixes: https://pagure.io/koji/issue/982
This commit is contained in:
Tomas Kopecek 2018-06-25 10:53:01 +02:00
parent ad61fdee12
commit 98b83eff69
3 changed files with 14 additions and 22 deletions

View file

@ -680,14 +680,11 @@ class VMExecTask(BaseTaskHandler):
else:
raise koji.BuildError('unsupported file type: %s' % type)
koji.ensuredir(os.path.dirname(localpath))
# closing needs to be used for requests < 2.18.0
with closing(requests.get(remote_url, stream=True)) as response:
with open(localpath, 'wb') as f:
length = response.headers.get('content-length')
if length is None:
f.write(response.content)
else:
for chunk in response.iter_content(chunk_size=65536):
f.write(chunk)
for chunk in response.iter_content(chunk_size=65536):
f.write(chunk)
if type == 'rpm':
# rpm, check sigmd5. It is enough, as if content is broken,
# rpm will fail later