mhtml: don't crash when user cancels a download
Fixes 1535 The browser crashed because both callbacks were called (finished and error), trying to remove the item twice from the list of downloads.
This commit is contained in:
parent
24db93f3eb
commit
1cabae0583
@ -345,7 +345,7 @@ class _Downloader:
|
||||
self.pending_downloads.add((url, item))
|
||||
item.finished.connect(functools.partial(self._finished, url, item))
|
||||
item.error.connect(functools.partial(self._error, url, item))
|
||||
item.cancelled.connect(functools.partial(self._error, url, item))
|
||||
item.cancelled.connect(functools.partial(self._cancelled, url, item))
|
||||
|
||||
def _finished(self, url, item):
|
||||
"""Callback when a single asset is downloaded.
|
||||
@ -418,6 +418,20 @@ class _Downloader:
|
||||
return
|
||||
self._finish_file()
|
||||
|
||||
def _cancelled(self, url, item):
|
||||
"""Callback when a download is cancelled by the user.
|
||||
|
||||
Args:
|
||||
url: The original url of the asset as QUrl.
|
||||
item: The DownloadItem given by the DownloadManager.
|
||||
"""
|
||||
# This callback is called before _finished, so there's no need to
|
||||
# remove the item or close the fileobject.
|
||||
log.downloads.debug("MHTML download cancelled by used: {}".format(url))
|
||||
# Write an empty file instead
|
||||
item.fileobj.seek(0)
|
||||
item.fileobj.truncate()
|
||||
|
||||
def _finish_file(self):
|
||||
"""Save the file to the filename given in __init__."""
|
||||
if self._finished_file:
|
||||
|
Loading…
Reference in New Issue
Block a user