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

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