2017-04-23 22:06:55 -05:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2020-01-02 08:43:50 -06:00
|
|
|
# Copyright (C) 2013 - 2020, The pgAdmin Development Team
|
2017-04-23 22:06:55 -05:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
import os
|
2019-05-20 03:46:02 -05:00
|
|
|
from flask import current_app
|
2017-04-23 22:06:55 -05:00
|
|
|
|
|
|
|
|
|
|
|
def _create_directory_if_not_exists(_path):
|
|
|
|
if not os.path.exists(_path):
|
|
|
|
os.mkdir(_path)
|
|
|
|
|
|
|
|
|
|
|
|
def create_app_data_directory(config):
|
|
|
|
"""
|
|
|
|
Create the required directories (if not present).
|
|
|
|
"""
|
|
|
|
# Create the directory containing the configuration file (if not present).
|
|
|
|
_create_directory_if_not_exists(os.path.dirname(config.SQLITE_PATH))
|
2019-07-16 08:36:29 -05:00
|
|
|
# Try to set the permissions on the directory, but don't complain
|
2019-05-20 03:46:02 -05:00
|
|
|
# if we can't. This may be the case on a mounted directory, e.g. in
|
|
|
|
# OpenShift. We'll still secure the config database anyway.
|
2019-05-20 07:53:08 -05:00
|
|
|
if os.name != 'nt':
|
|
|
|
try:
|
|
|
|
os.chmod(os.path.dirname(config.SQLITE_PATH), 0o700)
|
|
|
|
except Exception as e:
|
|
|
|
# The flask app isn't setup yet, so we can't use the logger
|
|
|
|
print('WARNING: Failed to set ACL on the directory containing the '
|
|
|
|
'configuration database: {}'.format(e))
|
2017-04-23 22:06:55 -05:00
|
|
|
|
|
|
|
# Create the directory containing the log file (if not present).
|
|
|
|
_create_directory_if_not_exists(os.path.dirname(config.LOG_FILE))
|
|
|
|
|
|
|
|
# Create the session directory (if not present).
|
|
|
|
_create_directory_if_not_exists(config.SESSION_DB_PATH)
|
2019-05-20 07:53:08 -05:00
|
|
|
if os.name != 'nt':
|
2019-05-21 06:14:36 -05:00
|
|
|
os.chmod(config.SESSION_DB_PATH, 0o700)
|
2017-04-23 22:06:55 -05:00
|
|
|
|
|
|
|
# Create the storage directory (if not present).
|
|
|
|
_create_directory_if_not_exists(config.STORAGE_DIR)
|