use %APPDATA%\gallery-dl for config/cache on Windows

This commit is contained in:
Mike Fährmann
2020-05-28 02:56:38 +02:00
parent 275cceeb6a
commit da22ea8ced
4 changed files with 11 additions and 9 deletions

View File

@@ -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`` |
+--------------------------------------------+------------------------------------------+

View File

@@ -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.

View File

@@ -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):

View File

@@ -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",
]