-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exception messages during data directory creation
- Loading branch information
1 parent
a89a62c
commit baee74b
Showing
1 changed file
with
21 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}" | ||
) |