From 238848903877e41797979dda59ecac2125f6b695 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 12 Sep 2016 11:30:44 +0200 Subject: [PATCH] downloads: Be okay with the tmpdir being gone --- qutebrowser/browser/webkit/downloads.py | 6 +++++- tests/end2end/features/downloads.feature | 10 ++++++++++ tests/end2end/features/test_downloads_bdd.py | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/webkit/downloads.py b/qutebrowser/browser/webkit/downloads.py index 61b5128a3..9a92c1e29 100644 --- a/qutebrowser/browser/webkit/downloads.py +++ b/qutebrowser/browser/webkit/downloads.py @@ -1376,7 +1376,11 @@ class TempDownloadManager(QObject): def cleanup(self): """Clean up any temporary files.""" if self._tmpdir is not None: - self._tmpdir.cleanup() + try: + self._tmpdir.cleanup() + except OSError: + log.misc.exception("Failed to clean up temporary download " + "directory") self._tmpdir = None def _get_tmpdir(self): diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index a59169372..d42d4aeca 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -323,6 +323,16 @@ Feature: Downloading things from a website. And I wait until the download is finished Then "Opening *download.bin* with [*python*]" should be logged + Scenario: Opening a download with a handler which deletes the tmpdir + When I set storage -> prompt-download-directory to true + And I open data/downloads/download.bin + And I directly open the download with a handler deleting the tmpdir + And I wait until the download is finished + And I run :quit + Then "Opening *download.bin* with [*python*]" should be logged + And "Failed to clean up temporary download directory" should be logged + And qutebrowser should quit + # https://github.com/The-Compiler/qutebrowser/issues/1728 Scenario: Cancelling a download that should be opened diff --git a/tests/end2end/features/test_downloads_bdd.py b/tests/end2end/features/test_downloads_bdd.py index 3ce6790bb..319818876 100644 --- a/tests/end2end/features/test_downloads_bdd.py +++ b/tests/end2end/features/test_downloads_bdd.py @@ -126,6 +126,14 @@ def download_open_with_prompt(quteproc): quteproc.send_cmd(':prompt-open-download {}'.format(cmd)) +@bdd.when("I directly open the download with a handler deleting the tmpdir") +def download_open_with_prompt_deleting(quteproc): + cmd = ('{} -c "import sys, shutil, os.path; ' + 'shutil.rmtree(os.path.dirname(sys.argv[1]))"'.format( + shlex.quote(sys.executable))) + quteproc.send_cmd(':prompt-open-download {}'.format(cmd)) + + @bdd.when(bdd.parsers.parse("I delete the downloaded file {filename}")) def delete_file(tmpdir, filename): (tmpdir / filename).remove()