Patch fetch_db to handle missing 'content-length' header

We don't know why the autopkgtest webserver has stopped providing a
Content-Length header but the current code doesn't handle its absence, so
detect this rather than throwing an exception.

Should be reverted once the header is back, we don't want to be in the dark
about short reads of the db.
This commit is contained in:
Steve Langasek 2024-04-12 09:48:26 -07:00
parent 9e28fceafa
commit 25eb52aa33

View File

@ -181,7 +181,8 @@ class AutopkgtestPolicy(BasePolicy):
if not data:
break
f_out.write(data)
if http_code and os.path.getsize(new_file) != int(f.getheader('content-length')):
content_length = f.getheader('content-length')
if http_code and content_length and os.path.getsize(new_file) != content_length):
self.logger.info('Short read downloading autopkgtest results')
os.unlink(new_file)
else: