From e5dc10a29eddd3dbf2cad5e523b331ff67ff0e70 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 22 Feb 2016 23:38:18 +0100 Subject: [PATCH 1/2] downloads: handle relative XDG_DOWNLOAD_DIR Issues #1269, #866 qutebrowser would crash when XDG_DOWNLOAD_DIR was set to some non-absolute value (which should not happen, but it can) and "storage -> download-dir" was empty, since when the user didn't give an absolute filename, even the joined path of download_dir() (i.e. XDG_DOWNLOAD_DIR in this case) and the filename was not absolute either. Since the path was not absolute, create_full_filename returned None, which meant that os.path.basename(self._filename) raised an exception. Now we display an error message and fall back to $HOME. --- CHANGELOG.asciidoc | 1 + qutebrowser/browser/downloads.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 4a79c8543..6b52eba9b 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -51,6 +51,7 @@ Fixed - Fixed crashes when opening an empty URL (e.g. via pasting). - Fixed validation of duplicate values in `hints -> chars`. - Fixed crash when PDF.js was partially installed. +- Fixed crash when XDG_DOWNLOAD_DIR was not an absolute path. v0.5.1 ------ diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index 8c977fb34..d9d412f1e 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -534,6 +534,22 @@ class DownloadItem(QObject): self._filename = create_full_filename( self.basename, os.path.join(download_dir(), filename)) + # At this point, we have a misconfigured XDG_DOWNLOAd_DIR, as + # download_dir() + filename is still no absolute path. + # The config value is checked for "absoluteness", but + # ~/.config/user-dirs.dirs may be misconfigured and a non-absolute path + # may be set for XDG_DOWNLOAD_DIR + if self._filename is None: + message.error( + self._win_id, + "XDG_DOWNLOAD_DIR points to a relative path - please check" + " your ~/.config/user-dirs.dirs. The download is saved in your " + "home directory.", + ) + # fall back to $HOME as download_dir + self._filename = create_full_filename( + self.basename, os.path.expanduser(os.path.join('~', filename))) + self.basename = os.path.basename(self._filename) last_used_directory = os.path.dirname(self._filename) From 20daf1f86ec24a1a84335c938325253c1f8e7648 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 23 Feb 2016 14:33:10 +0100 Subject: [PATCH 2/2] fix lint --- qutebrowser/browser/downloads.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index d9d412f1e..a3453513b 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -543,8 +543,8 @@ class DownloadItem(QObject): message.error( self._win_id, "XDG_DOWNLOAD_DIR points to a relative path - please check" - " your ~/.config/user-dirs.dirs. The download is saved in your " - "home directory.", + " your ~/.config/user-dirs.dirs. The download is saved in" + " your home directory.", ) # fall back to $HOME as download_dir self._filename = create_full_filename(