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).
pull/373/head
Mike Fährmann 5 years ago
parent afce1ee1eb
commit 4b6edfbfd2
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -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

Loading…
Cancel
Save