mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Prevent race condition in directory creation (#4362)
Checking whether a path does not exist before trying to create it does not follow the Python paradigm of asking for forgiveness, rather than permission, and opens up a time-of-check to time-of-use race.
This commit is contained in:
@@ -38,6 +38,7 @@ import logging
|
||||
import os
|
||||
import sys
|
||||
from json import loads
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import importlib_metadata as metadata
|
||||
@@ -70,14 +71,10 @@ MEDIA_ROOT = os.path.join(DATA_DIR, 'media')
|
||||
PROFILE_DIR = os.path.join(DATA_DIR, 'profiles')
|
||||
CACHE_DIR = config.get('pretix', 'cachedir', fallback=os.path.join(DATA_DIR, 'cache'))
|
||||
|
||||
if not os.path.exists(DATA_DIR):
|
||||
os.mkdir(DATA_DIR)
|
||||
if not os.path.exists(LOG_DIR):
|
||||
os.mkdir(LOG_DIR)
|
||||
if not os.path.exists(MEDIA_ROOT):
|
||||
os.mkdir(MEDIA_ROOT)
|
||||
if not os.path.exists(CACHE_DIR):
|
||||
os.mkdir(CACHE_DIR)
|
||||
Path(DATA_DIR).mkdir(parents=False, exist_ok=True)
|
||||
Path(LOG_DIR).mkdir(parents=False, exist_ok=True)
|
||||
Path(MEDIA_ROOT).mkdir(parents=False, exist_ok=True)
|
||||
Path(CACHE_DIR).mkdir(parents=False, exist_ok=True)
|
||||
|
||||
if config.has_option('django', 'secret'):
|
||||
SECRET_KEY = config.get('django', 'secret')
|
||||
|
||||
Reference in New Issue
Block a user