From 7073d14cb8001f67cbcdd7236c51bdba5565c0a1 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 25 Jun 2014 22:06:16 +0200 Subject: [PATCH] Handle absolute paths for downloads better --- doc/TODO | 1 - qutebrowser/browser/downloads.py | 16 +++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/doc/TODO b/doc/TODO index fe3132246..4712ac9f2 100644 --- a/doc/TODO +++ b/doc/TODO @@ -42,7 +42,6 @@ New big features Improvements / minor features ============================= -- Downloading: do something more sensible than using $PWD if path is relative? - Downloading: re-ask instead of killing download if path is invalid - Downloading: open files - Distinction between :q and :wq, add ZZ and ZQ shortcuts. diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index e8b669452..48804262f 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -208,12 +208,17 @@ class DownloadItem(QObject): filename: The full filename to save the download to. None: special value to stop the download. """ + if os.path.isabs(filename): + target = filename + else: + download_dir = config.get('storage', 'download-directory') + target = os.path.join(download_dir, filename) logger.debug("Setting filename to {}".format(filename)) if self.filename is not None: raise ValueError("Filename was already set! filename: {}, " "existing: {}".format(filename, self.filename)) - self.filename = filename - self.basename = os.path.basename(filename) + self.filename = target + self.basename = os.path.basename(target) try: self.fileobj = open(filename, 'wb') if self._do_delayed_write: @@ -368,10 +373,7 @@ class DownloadManager(QObject): reply: The QNetworkReply to download. """ _inline, suggested_filename = utils.parse_content_disposition(reply) - download_location = config.get('storage', 'download-directory') - suggested_filepath = os.path.join(download_location, - suggested_filename) - logger.debug("fetch: {} -> {}".format(reply.url(), suggested_filepath)) + logger.debug("fetch: {} -> {}".format(reply.url(), suggested_filename)) download = DownloadItem(reply, self) download.finished.connect(partial(self.on_finished, download)) download.data_changed.connect(partial(self.on_data_changed, download)) @@ -384,7 +386,7 @@ class DownloadManager(QObject): q = Question(self) q.text = "Save file to:" q.mode = PromptMode.text - q.default = suggested_filepath + q.default = suggested_filename q.answered.connect(download.set_filename) q.cancelled.connect(download.cancel) q.answered.connect(q.deleteLater)