downloads: Be okay with the tmpdir being gone

This commit is contained in:
Florian Bruhin 2016-09-12 11:30:44 +02:00
parent 38a3d118ab
commit 2388489038
3 changed files with 23 additions and 1 deletions

View File

@ -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):

View File

@ -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

View File

@ -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()