Slight tweak

This commit is contained in:
Sybren A. Stüvel 2016-03-21 17:43:25 +01:00
parent 3352d405c9
commit 5f3a83737c

View File

@ -149,17 +149,14 @@ async def download_to_file(url, filename, *,
try: try:
with open(header_store, 'r') as infile: with open(header_store, 'r') as infile:
stored_headers = requests.structures.CaseInsensitiveDict(json.load(infile)) stored_headers = requests.structures.CaseInsensitiveDict(json.load(infile))
try:
expected_content_length = int(stored_headers['Content-Length']) # Check file length.
statinfo = os.stat(filename) expected_content_length = int(stored_headers['Content-Length'])
if expected_content_length != statinfo.st_size: statinfo = os.stat(filename)
log.debug('File size should be %i but is %i; ignoring cache.', if expected_content_length != statinfo.st_size:
expected_content_length, statinfo.st_size) log.debug('File size should be %i but is %i; ignoring cache.',
stored_headers = {} expected_content_length, statinfo.st_size)
except (KeyError, ValueError): stored_headers = {}
pass
except IOError:
log.debug('IO error ')
except Exception as ex: except Exception as ex:
log.warning('Unable to load headers from %r, ignoring cache: %s', header_store, str(ex)) log.warning('Unable to load headers from %r, ignoring cache: %s', header_store, str(ex))