aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/cache.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2019-08-04 17:53:04 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2019-08-04 17:53:04 -0400
commit09e19cd4b63183a3cc38cea7bc5c5b8d308d22fa (patch)
tree2ef7e5afcc539bf5ca7fc2a0c525709b41e309d7 /gallery_dl/cache.py
parent1d18be9fc5a9d6577eb1bbb5f9a135bfa0ce0495 (diff)
parent64ad8e7bd15df71ab1116eede414558631bcad32 (diff)
Update upstream source from tag 'upstream/1.10.1'
Update to upstream version '1.10.1' with Debian dir 81401e5e3e324250ded90d4caf7bf60cd0b9affb
Diffstat (limited to 'gallery_dl/cache.py')
-rw-r--r--gallery_dl/cache.py19
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