From a8b60b2bd987ee397f5688a91a3b110893ff55c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 31 Jul 2019 22:45:02 +0200 Subject: [PATCH] change default cache directory for unix systems Use either $XDG_CACHE_HOME or ~/.cache (if the former isn't set) and store potentially sensitive cookies and tokens in a user's home directory and not in the world-readable /tmp. --- docs/configuration.rst | 3 ++- gallery_dl/cache.py | 12 ++++++++---- gallery_dl/version.py | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 819874c5..e47b2807 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1492,7 +1492,8 @@ cache.file ---------- =========== ===== Type |Path|_ -Default |tempfile.gettempdir()|_ + ``".gallery-dl.cache"`` +Default * |tempfile.gettempdir()|_ + ``".gallery-dl.cache"`` on Windows + * (``$XDG_CACHE_HOME`` or ``"~/.cache"``) + ``".gallery-dl.cache"`` on all other platforms Description Path of the SQLite3 database used to cache login sessions, cookies and API tokens across `gallery-dl` invocations. diff --git a/gallery_dl/cache.py b/gallery_dl/cache.py index 25b66607..1cee4a29 100644 --- a/gallery_dl/cache.py +++ b/gallery_dl/cache.py @@ -189,13 +189,17 @@ def clear(): def _path(): path = config.get(("cache", "file"), -1) + if path != -1: + return util.expand_path(path) - if path == -1: + if os.name == "nt": import tempfile - import os.path - return os.path.join(tempfile.gettempdir(), ".gallery-dl.cache") + cachedir = tempfile.gettempdir() + else: + cachedir = util.expand_path( + os.environ.get("XDG_CACHE_HOME", "~/.cache")) - return util.expand_path(path) + return os.path.join(cachedir, ".gallery-dl.cache") try: diff --git a/gallery_dl/version.py b/gallery_dl/version.py index 33d19595..20797434 100644 --- a/gallery_dl/version.py +++ b/gallery_dl/version.py @@ -6,4 +6,4 @@ # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. -__version__ = "1.9.1-dev" +__version__ = "1.10.0-dev"