From 57ceaeeb557dbb6f4cad78ea5dcdcdd7fb2e755c Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 2 Aug 2016 01:10:40 +0200 Subject: [PATCH] open-download: don't crash on download cancel Fixes #1728. --- qutebrowser/browser/webkit/downloads.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/webkit/downloads.py b/qutebrowser/browser/webkit/downloads.py index 47d264d37..723edebb8 100644 --- a/qutebrowser/browser/webkit/downloads.py +++ b/qutebrowser/browser/webkit/downloads.py @@ -954,12 +954,21 @@ class DownloadManager(QAbstractListModel): message.error(self._win_id, msg) download.cancel() return - download.finished.connect(download.open_file) + download.finished.connect( + functools.partial(self._open_download, download)) download.autoclose = True download.set_fileobj(fobj) else: log.downloads.error("Unknown download target: {}".format(target)) + def _open_download(self, download): + """Open the given download but only if it was successful.""" + if download.successful: + download.open_file() + else: + log.downloads.debug("{} finished but not successful, not opening!" + .format(download)) + def raise_no_download(self, count): """Raise an exception that the download doesn't exist.