From 1cabae05839a7e74b6ee6c713ca15093c5ced9c3 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 2 Jun 2016 21:23:11 +0200 Subject: [PATCH 1/6] 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. --- qutebrowser/browser/mhtml.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/mhtml.py b/qutebrowser/browser/mhtml.py index 24cc828f3..71e1f6122 100644 --- a/qutebrowser/browser/mhtml.py +++ b/qutebrowser/browser/mhtml.py @@ -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: From c3e7ab52b59c8bb76fb0f85ae6e8359b563a7b75 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 2 Jun 2016 23:07:03 +0200 Subject: [PATCH 2/6] tests: add test for cancelling a mhtml download --- tests/end2end/data/downloads/issue1535.html | 14 ++++++++++++++ tests/end2end/features/downloads.feature | 8 ++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/end2end/data/downloads/issue1535.html diff --git a/tests/end2end/data/downloads/issue1535.html b/tests/end2end/data/downloads/issue1535.html new file mode 100644 index 000000000..0375fe39f --- /dev/null +++ b/tests/end2end/data/downloads/issue1535.html @@ -0,0 +1,14 @@ + + + test case for issue 1535 + + +

Cancelling a download that belongs to a mhtml download.

+

See also GitHub

+ + + + diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index 152336c49..f5168e145 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -126,6 +126,14 @@ Feature: Downloading things from a website. Then "cancelled" should be logged And "cancelled" should be logged + # https://github.com/The-Compiler/qutebrowser/issues/1535 + Scenario: Cancelling a MHTML download (issue 1535) + When I open data/downloads/issue1535.html + And I run :download --mhtml + And I wait 1s + And I run :download-cancel + Then no crash should happen + ## :download-delete Scenario: Deleting a download From 44b1344467542c0e338187c46613a1177507dc34 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Fri, 3 Jun 2016 15:52:29 +0200 Subject: [PATCH 3/6] typo used -> user --- qutebrowser/browser/mhtml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/browser/mhtml.py b/qutebrowser/browser/mhtml.py index 71e1f6122..55ef1bd05 100644 --- a/qutebrowser/browser/mhtml.py +++ b/qutebrowser/browser/mhtml.py @@ -427,7 +427,7 @@ class _Downloader: """ # 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)) + log.downloads.debug("MHTML download cancelled by user: {}".format(url)) # Write an empty file instead item.fileobj.seek(0) item.fileobj.truncate() From fd27caf311026d1bf3655b05a0207ba5b90568cd Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Fri, 3 Jun 2016 16:09:31 +0200 Subject: [PATCH 4/6] tests: remove wait in mhtml cancel test --- tests/end2end/features/downloads.feature | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index f5168e145..e22d162b3 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -130,7 +130,6 @@ Feature: Downloading things from a website. Scenario: Cancelling a MHTML download (issue 1535) When I open data/downloads/issue1535.html And I run :download --mhtml - And I wait 1s And I run :download-cancel Then no crash should happen From 163082b3ea84eb25552e0e651699701a1d11ff91 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 4 Jun 2016 13:15:22 +0200 Subject: [PATCH 5/6] Wait until download is started --- tests/end2end/features/downloads.feature | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index e22d162b3..533acf57c 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -130,6 +130,7 @@ Feature: Downloading things from a website. Scenario: Cancelling a MHTML download (issue 1535) When I open data/downloads/issue1535.html And I run :download --mhtml + And I wait for "fetch: PyQt5.QtCore.QUrl('http://localhost:*/drip?numbytes=128&duration=2') -> drip" in the log And I run :download-cancel Then no crash should happen From 53b8ac1a60a30e2f0287d28745031435896849e0 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 3 Jun 2016 14:53:19 +0200 Subject: [PATCH 6/6] Update changelog --- CHANGELOG.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 62b79a73e..2bf9a3ab0 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -70,6 +70,7 @@ Fixed - Fixed a crash when entering `:-- ` in the commandline - Fixed `:debug-console` with PyQt 5.6 - Fixed qutebrowser not starting when `sys.stderr` is `None` +- Fixed crash when cancelling a download which belongs to a MHTML download v0.6.2 ------