diff options
| author | 2019-08-04 17:52:59 -0400 | |
|---|---|---|
| committer | 2019-08-04 17:52:59 -0400 | |
| commit | 64ad8e7bd15df71ab1116eede414558631bcad32 (patch) | |
| tree | 7416e191aedce591087903a943198aed13fa0b26 /gallery_dl/cache.py | |
| parent | 2a63a9c9b7032a76894c48ac4d9cea732fcaee49 (diff) | |
New upstream version 1.10.1upstream/1.10.1
Diffstat (limited to 'gallery_dl/cache.py')
| -rw-r--r-- | gallery_dl/cache.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/gallery_dl/cache.py b/gallery_dl/cache.py index e6ba61a..3ceef75 100644 --- a/gallery_dl/cache.py +++ b/gallery_dl/cache.py @@ -11,6 +11,7 @@ import sqlite3 import pickle import time +import os import functools from . import config, util @@ -188,17 +189,25 @@ 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") - return util.expand_path(path) + cachedir = util.expand_path(os.path.join( + os.environ.get("XDG_CACHE_HOME", "~/.cache"), "gallery-dl")) + os.makedirs(cachedir, exist_ok=True) + return os.path.join(cachedir, "cache.sqlite3") try: + dbfile = _path() + if os.name != "nt": + # restrict access permissions for new db files + os.close(os.open(dbfile, os.O_CREAT | os.O_RDONLY, 0o600)) DatabaseCacheDecorator.db = sqlite3.connect( - _path(), timeout=30, check_same_thread=False) -except (TypeError, sqlite3.OperationalError): + dbfile, timeout=30, check_same_thread=False) +except (OSError, TypeError, sqlite3.OperationalError): cache = memcache # noqa: F811 |
