From da22ea8ced3340700c4ed5c3e5ccdb1ceabcd832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 28 May 2020 02:56:38 +0200 Subject: [PATCH] use %APPDATA%\gallery-dl for config/cache on Windows --- README.rst | 2 +- docs/configuration.rst | 2 +- gallery_dl/cache.py | 15 ++++++++------- gallery_dl/config.py | 1 + 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index 362178a3..af918044 100644 --- a/README.rst +++ b/README.rst @@ -170,7 +170,7 @@ Configuration files for *gallery-dl* use a JSON-based file format. +--------------------------------------------+------------------------------------------+ | Linux | Windows | +--------------------------------------------+------------------------------------------+ -|* ``/etc/gallery-dl.conf`` |* | +|* ``/etc/gallery-dl.conf`` |* ``%APPDATA%\gallery-dl\config.json`` | |* ``${HOME}/.config/gallery-dl/config.json``|* ``%USERPROFILE%\gallery-dl\config.json``| |* ``${HOME}/.gallery-dl.conf`` |* ``%USERPROFILE%\gallery-dl.conf`` | +--------------------------------------------+------------------------------------------+ diff --git a/docs/configuration.rst b/docs/configuration.rst index e4c305b3..71067992 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1892,7 +1892,7 @@ cache.file ---------- =========== ===== Type |Path|_ -Default * |tempfile.gettempdir()|__ + ``".gallery-dl.cache"`` on Windows +Default * (``%APPDATA%`` or ``"~"``) + ``"/gallery-dl/cache.sqlite3"`` on Windows * (``$XDG_CACHE_HOME`` or ``"~/.cache"``) + ``"/gallery-dl/cache.sqlite3"`` 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 70442f4f..38860913 100644 --- a/gallery_dl/cache.py +++ b/gallery_dl/cache.py @@ -194,20 +194,21 @@ def _path(): return util.expand_path(path) if util.WINDOWS: - import tempfile - return os.path.join(tempfile.gettempdir(), ".gallery-dl.cache") + cachedir = os.environ.get("APPDATA", "~") + else: + cachedir = os.environ.get("XDG_CACHE_HOME", "~/.cache") - cachedir = util.expand_path(os.path.join( - os.environ.get("XDG_CACHE_HOME", "~/.cache"), "gallery-dl")) + cachedir = util.expand_path(os.path.join(cachedir, "gallery-dl")) os.makedirs(cachedir, exist_ok=True) return os.path.join(cachedir, "cache.sqlite3") try: dbfile = _path() - if not util.WINDOWS: - # restrict access permissions for new db files - os.close(os.open(dbfile, os.O_CREAT | os.O_RDONLY, 0o600)) + + # restrict access permissions for new db files + os.close(os.open(dbfile, os.O_CREAT | os.O_RDONLY, 0o600)) + DatabaseCacheDecorator.db = sqlite3.connect( dbfile, timeout=30, check_same_thread=False) except (OSError, TypeError, sqlite3.OperationalError): diff --git a/gallery_dl/config.py b/gallery_dl/config.py index 3221a9d5..53036169 100644 --- a/gallery_dl/config.py +++ b/gallery_dl/config.py @@ -24,6 +24,7 @@ _config = {} if util.WINDOWS: _default_configs = [ + r"%APPDATA%\gallery-dl\config.json", r"%USERPROFILE%\gallery-dl\config.json", r"%USERPROFILE%\gallery-dl.conf", ]