From dcad81a78f321027d1dcbea90c4d47cd253807c9 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 26 Apr 2016 23:14:55 +0200 Subject: [PATCH] cache: fix crash when cache_dir is None Issue #1412 When passing --cachedir="" on the command line, standarddir.cache() returns None, which stands for "deactivate cache" and has to be properly handled in DiskCache.__init__() (i.e. don't pass it to os.path.join) --- qutebrowser/browser/cache.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/qutebrowser/browser/cache.py b/qutebrowser/browser/cache.py index b34fa232b..5ef53837a 100644 --- a/qutebrowser/browser/cache.py +++ b/qutebrowser/browser/cache.py @@ -32,16 +32,23 @@ class DiskCache(QNetworkDiskCache): """Disk cache which sets correct cache dir and size. + If the cache is deactivated via the command line argument --cachedir="", + both attributes _cache_dir and _http_cache_dir are set to None. + Attributes: _activated: Whether the cache should be used. - _cache_dir: The base directory for cache files (standarddir.cache()) - _http_cache_dir: the HTTP subfolder in _cache_dir. + _cache_dir: The base directory for cache files (standarddir.cache()) or + None. + _http_cache_dir: the HTTP subfolder in _cache_dir or None. """ def __init__(self, cache_dir, parent=None): super().__init__(parent) self._cache_dir = cache_dir - self._http_cache_dir = os.path.join(cache_dir, 'http') + if cache_dir is None: + self._http_cache_dir = None + else: + self._http_cache_dir = os.path.join(cache_dir, 'http') self._maybe_activate() objreg.get('config').changed.connect(self.on_config_changed)