don't delete downloaded files in certain edge cases
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user