Skip to content

Commit

Permalink
Add more permission checks
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-bc committed Jan 18, 2024
1 parent f960b61 commit 3f47f6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/fprime_gds/executables/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,12 @@ def get_arguments(self) -> Dict[Tuple[str, ...], Dict[str, Any]]:

def handle_arguments(self, args, **kwargs):
"""Handle arguments as parsed"""
os.makedirs(args.files_storage_directory, exist_ok=True)
try:
Path(args.files_storage_directory).mkdir(parents=True, exist_ok=True)
except PermissionError:
raise PermissionError(
f"{args.files_storage_directory} is not writable. Fix permissions or change storage directory with --file-storage-directory."
)
return args


Expand Down
9 changes: 6 additions & 3 deletions src/fprime_gds/flask/updown.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@ def save(self, file_storage: FileStorage):
filename = Path(secure_filename(file_storage.filename)).name
dest_dir = Path(self.dest_dir)

# not necessary
if not dest_dir.exists():
dest_dir.mkdir(parents=True)
try:
dest_dir.mkdir(parents=True, exist_ok=True)
except PermissionError:
raise PermissionError(
f"{dest_dir} is not writable. Fix permissions or change storage directory with --file-storage-directory."
)

# resolve conflict may not be needed
if (dest_dir / filename).exists():
Expand Down

0 comments on commit 3f47f6b

Please sign in to comment.