From 64ad8e7bd15df71ab1116eede414558631bcad32 Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Sun, 4 Aug 2019 17:52:59 -0400 Subject: New upstream version 1.10.1 --- gallery_dl/cache.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'gallery_dl/cache.py') 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 -- cgit v1.2.3