mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Only set permissions on the storage directory upon creation. Fixes #6958
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
|
||||
import os
|
||||
import getpass
|
||||
from flask import current_app
|
||||
from pgadmin.utils.constants import KERBEROS
|
||||
|
||||
FAILED_CREATE_DIR = \
|
||||
@@ -19,6 +18,9 @@ FAILED_CREATE_DIR = \
|
||||
def _create_directory_if_not_exists(_path):
|
||||
if _path and not os.path.exists(_path):
|
||||
os.mkdir(_path)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def create_app_data_directory(config):
|
||||
@@ -26,8 +28,10 @@ def create_app_data_directory(config):
|
||||
Create the required directories (if not present).
|
||||
"""
|
||||
# Create the directory containing the configuration file (if not present).
|
||||
is_directory_created = False
|
||||
try:
|
||||
_create_directory_if_not_exists(os.path.dirname(config.SQLITE_PATH))
|
||||
is_directory_created = _create_directory_if_not_exists(
|
||||
os.path.dirname(config.SQLITE_PATH))
|
||||
except PermissionError as e:
|
||||
print(FAILED_CREATE_DIR.format(os.path.dirname(config.SQLITE_PATH), e))
|
||||
print(
|
||||
@@ -44,7 +48,7 @@ def create_app_data_directory(config):
|
||||
# Try to set the permissions on the directory, but don't complain
|
||||
# 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.
|
||||
if os.name != 'nt':
|
||||
if os.name != 'nt' and is_directory_created:
|
||||
try:
|
||||
os.chmod(os.path.dirname(config.SQLITE_PATH), 0o700)
|
||||
except Exception as e:
|
||||
@@ -74,7 +78,8 @@ def create_app_data_directory(config):
|
||||
|
||||
# Create the session directory (if not present).
|
||||
try:
|
||||
_create_directory_if_not_exists(config.SESSION_DB_PATH)
|
||||
is_directory_created = \
|
||||
_create_directory_if_not_exists(config.SESSION_DB_PATH)
|
||||
except PermissionError as e:
|
||||
print(FAILED_CREATE_DIR.format(config.SESSION_DB_PATH, e))
|
||||
print(
|
||||
@@ -88,7 +93,7 @@ def create_app_data_directory(config):
|
||||
config.APP_VERSION))
|
||||
exit(1)
|
||||
|
||||
if os.name != 'nt':
|
||||
if os.name != 'nt' and is_directory_created:
|
||||
os.chmod(config.SESSION_DB_PATH, 0o700)
|
||||
|
||||
# Create the storage directory (if not present).
|
||||
|
||||
Reference in New Issue
Block a user