Skip to content

Commit

Permalink
Add exception messages during data directory creation
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyamalviya committed May 26, 2021
1 parent a89a62c commit baee74b
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions monkey/monkey_island/cc/environment/data_dir_generator.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import logging
import os

from monkey_island.cc.environment.utils import is_windows_os
from monkey_island.cc.environment.windows_permissions import set_full_folder_access

LOG = logging.getLogger(__name__)


def create_data_dir(data_dir: str, create_parent_dirs: bool) -> None:
if not os.path.isdir(data_dir):
if create_parent_dirs:
os.makedirs(data_dir, mode=0o700)
else:
os.mkdir(data_dir, mode=0o700)
try:
if create_parent_dirs:
os.makedirs(data_dir, mode=0o700)
else:
os.mkdir(data_dir, mode=0o700)
except Exception as ex:
LOG.error(
f'Could not create data directory at "{data_dir}" (maybe `$HOME` could not be '
f"resolved?): {str(ex)}"
)

if is_windows_os(): # `mode=0o700` doesn't work on Windows
set_full_folder_access(folder_path=data_dir)
try:
set_full_folder_access(folder_path=data_dir)
except Exception as ex:
LOG.error(
f'Data directory was created at "{data_dir}" but permissions could not be '
f"set successfully: {str(ex)}"
)

0 comments on commit baee74b

Please sign in to comment.