fix: 修复创建目录时指定权限为 755

pull/8968/head
Jiangjie.Bai 2 years ago
parent 33860bb955
commit 4711813af8

@ -389,3 +389,10 @@ def static_or_direct(logo_path):
return static(logo_path) return static(logo_path)
else: else:
return logo_path return logo_path
def make_dirs(name, mode=None, exist_ok=False):
""" 默认权限设置为 0o755 """
if mode is None:
mode = 0o755
return os.makedirs(name, mode=mode, exist_ok=exist_ok)

@ -154,4 +154,4 @@ if CONFIG.SYSLOG_ADDR != '' and len(CONFIG.SYSLOG_ADDR.split(':')) == 2:
}) })
if not os.path.isdir(LOG_DIR): if not os.path.isdir(LOG_DIR):
os.makedirs(LOG_DIR) os.makedirs(LOG_DIR, mode=0o755)

@ -11,7 +11,7 @@ from django.conf import settings
from django.utils import timezone from django.utils import timezone
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from common.utils import get_logger, lazyproperty from common.utils import get_logger, lazyproperty, make_dirs
from common.utils.translate import translate_value from common.utils.translate import translate_value
from common.db.fields import ( from common.db.fields import (
JsonListTextField, JsonDictCharField, EncryptJsonDictCharField, JsonListTextField, JsonDictCharField, EncryptJsonDictCharField,
@ -274,7 +274,7 @@ class AdHocExecution(OrgModelMixin):
dt = datetime.datetime.now().strftime('%Y-%m-%d') dt = datetime.datetime.now().strftime('%Y-%m-%d')
log_dir = os.path.join(settings.PROJECT_DIR, 'data', 'ansible', dt) log_dir = os.path.join(settings.PROJECT_DIR, 'data', 'ansible', dt)
if not os.path.exists(log_dir): if not os.path.exists(log_dir):
os.makedirs(log_dir) make_dirs(log_dir)
return os.path.join(log_dir, str(self.id) + '.log') return os.path.join(log_dir, str(self.id) + '.log')
def start_runner(self): def start_runner(self):

@ -4,7 +4,7 @@ import uuid
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from common.utils import get_logger, get_object_or_none from common.utils import get_logger, get_object_or_none, make_dirs
from common.tasks import send_mail_async from common.tasks import send_mail_async
from orgs.utils import org_aware_func from orgs.utils import org_aware_func
from jumpserver.const import PROJECT_DIR from jumpserver.const import PROJECT_DIR
@ -78,5 +78,5 @@ def get_task_log_path(base_path, task_id, level=2):
rel_path = os.path.join(*task_id[:level], task_id + '.log') rel_path = os.path.join(*task_id[:level], task_id + '.log')
path = os.path.join(base_path, rel_path) path = os.path.join(base_path, rel_path)
os.makedirs(os.path.dirname(path), exist_ok=True) make_dirs(os.path.dirname(path), exist_ok=True)
return path return path

@ -8,7 +8,7 @@ from django.core.files.storage import default_storage
import jms_storage import jms_storage
from common.utils import get_logger from common.utils import get_logger, make_dirs
from ..models import ReplayStorage from ..models import ReplayStorage
@ -56,7 +56,7 @@ def download_session_replay(session):
target_path = os.path.join(default_storage.base_location, local_path) target_path = os.path.join(default_storage.base_location, local_path)
target_dir = os.path.dirname(target_path) target_dir = os.path.dirname(target_path)
if not os.path.isdir(target_dir): if not os.path.isdir(target_dir):
os.makedirs(target_dir, exist_ok=True) make_dirs(target_dir, exist_ok=True)
ok, err = storage.download(session_path, target_path) ok, err = storage.download(session_path, target_path)
if not ok: if not ok:

5
jms

@ -35,6 +35,7 @@ except ImportError as e:
try: try:
from jumpserver.const import CONFIG from jumpserver.const import CONFIG
from common.utils.file import download_file from common.utils.file import download_file
from common.utils import make_dirs
except ImportError as e: except ImportError as e:
print("Import error: {}".format(e)) print("Import error: {}".format(e))
print("Could not find config file, `cp config_example.yml config.yml`") print("Could not find config file, `cp config_example.yml config.yml`")
@ -50,8 +51,8 @@ logging.basicConfig(
logger = logging.getLogger() logger = logging.getLogger()
try: try:
os.makedirs(os.path.join(BASE_DIR, "data", "static")) make_dirs(os.path.join(BASE_DIR, "data", "static"))
os.makedirs(os.path.join(BASE_DIR, "data", "media")) make_dirs(os.path.join(BASE_DIR, "data", "media"))
except: except:
pass pass

Loading…
Cancel
Save