1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 10:42:34 +01:00

restrict permissions without importing 'pathlib'

and only on non-Windows systems.

1. On Windows the 'mode' argument for os.open() has no (visible) effect
   on access permissions for new files.
2. The default location for 'cache.file' on Windows is in
   %USERPROFILE%\AppData\Local\Temp which can only be accessed by the
   owner himself (or an admin).
This commit is contained in:
Mike Fährmann 2019-07-31 15:27:06 +02:00
parent afce1ee1eb
commit 4b6edfbfd2
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

View File

@ -9,9 +9,9 @@
"""Decorators to keep function results in an in-memory and database cache"""
import sqlite3
import pathlib
import pickle
import time
import os
import functools
from . import config, util
@ -200,8 +200,10 @@ def _path():
try:
dbfile = _path()
pathlib.Path(dbfile).touch(mode=0o600)
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(
dbfile, timeout=30, check_same_thread=False)
except (PermissionError, TypeError, sqlite3.OperationalError):
except (OSError, TypeError, sqlite3.OperationalError):
cache = memcache # noqa: F811