don't delete downloaded files in certain edge cases

pull/13/head
Mike Fährmann 8 years ago
parent 2b2bdce366
commit 3c1daef839
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -15,6 +15,9 @@ class BasicDownloader():
max_tries = 5
def __init__(self):
self.downloading = False
def download(self, url, pathfmt):
"""Download the resource at 'url' and write it to a file-like object"""
try:
@ -22,7 +25,8 @@ class BasicDownloader():
except:
# remove file if download failed
try:
os.unlink(pathfmt.realpath)
if self.downloading:
os.unlink(pathfmt.realpath)
except (AttributeError, FileNotFoundError):
pass
raise

@ -61,9 +61,11 @@ class Downloader(BasicDownloader):
return
self.out.start(pathfmt.path)
self.downloading = True
with pathfmt.open() as file:
for data in response.iter_content(16384):
file.write(data)
self.downloading = False
self.out.success(pathfmt.path, tries)
def set_headers(self, headers):

@ -24,6 +24,8 @@ class Downloader(BasicDownloader):
return
self.out.start(pathfmt.path)
self.downloading = True
with pathfmt.open() as file:
file.write(bytes(url[7:], "utf-8"))
self.downloading = False
self.out.success(pathfmt.path, 0)

Loading…
Cancel
Save