From 3f47f6be002a6a33f36884bd54b5489e841ffcf0 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Wed, 17 Jan 2024 16:28:05 -0800 Subject: [PATCH] Add more permission checks --- src/fprime_gds/executables/cli.py | 7 ++++++- src/fprime_gds/flask/updown.py | 9 ++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/fprime_gds/executables/cli.py b/src/fprime_gds/executables/cli.py index a24eeb96..31928aa4 100644 --- a/src/fprime_gds/executables/cli.py +++ b/src/fprime_gds/executables/cli.py @@ -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 diff --git a/src/fprime_gds/flask/updown.py b/src/fprime_gds/flask/updown.py index 596d9bb6..cf56e013 100644 --- a/src/fprime_gds/flask/updown.py +++ b/src/fprime_gds/flask/updown.py @@ -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():