Skip to content

Commit

Permalink
use %APPDATA%\gallery-dl for config/cache on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed May 28, 2020
1 parent 275ccee commit da22ea8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`` |
+--------------------------------------------+------------------------------------------+
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 8 additions & 7 deletions gallery_dl/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions gallery_dl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

if util.WINDOWS:
_default_configs = [
r"%APPDATA%\gallery-dl\config.json",
r"%USERPROFILE%\gallery-dl\config.json",
r"%USERPROFILE%\gallery-dl.conf",
]
Expand Down

0 comments on commit da22ea8

Please sign in to comment.