Mercurial > public > sg101
comparison core/download.py @ 976:f5aa74dcdd7a
Ensure temporary files get deleted during hotlinking.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 05 Oct 2015 20:07:44 -0500 |
parents | 6f55c086db1e |
children | a6331579ff43 |
comparison
equal
deleted
inserted
replaced
975:8c3d52b7cbd1 | 976:f5aa74dcdd7a |
---|---|
47 with open(path, 'wb') as fp: | 47 with open(path, 'wb') as fp: |
48 r.raw.decode_content = True | 48 r.raw.decode_content = True |
49 shutil.copyfileobj(r.raw, fp) | 49 shutil.copyfileobj(r.raw, fp) |
50 except requests.RequestException: | 50 except requests.RequestException: |
51 logger.exception("download_file download exception") | 51 logger.exception("download_file download exception") |
52 os.remove(path) | |
52 raise | 53 raise |
53 | 54 |
54 file_size = os.stat(path).st_size | 55 file_size = os.stat(path).st_size |
55 logger.info("download_file retrieved %s bytes from %s; saved to %s", file_size, url, path) | 56 logger.info("download_file retrieved %s bytes from %s; saved to %s", file_size, url, path) |
56 return path | 57 return path |