From ec5e291a98516844d3b88cf103706e6f7b5a01b6 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 28 Jan 2024 16:21:27 -0500 Subject: [PATCH] Fix bug where del fail would give no feedback --- app/classes/shared/file_helpers.py | 7 ++++--- app/classes/web/routes/api/servers/server/files.py | 10 +++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/classes/shared/file_helpers.py b/app/classes/shared/file_helpers.py index cc09dc4f..5e06c708 100644 --- a/app/classes/shared/file_helpers.py +++ b/app/classes/shared/file_helpers.py @@ -35,8 +35,9 @@ class FileHelpers: try: # This removes the top-level folder: path.rmdir() - except: + except Exception as e: logger.error("Unable to remove top level") + return e return True @staticmethod @@ -47,9 +48,9 @@ class FileHelpers: # Remove the file os.remove(path) return True - except FileNotFoundError: + except (FileNotFoundError, PermissionError) as e: logger.error(f"Path specified is not a file or does not exist. {path}") - return False + return e @staticmethod def copy_dir(src_path, dest_path, dirs_exist_ok=False): diff --git a/app/classes/web/routes/api/servers/server/files.py b/app/classes/web/routes/api/servers/server/files.py index 37007acd..8e70d4fe 100644 --- a/app/classes/web/routes/api/servers/server/files.py +++ b/app/classes/web/routes/api/servers/server/files.py @@ -237,10 +237,14 @@ class ApiServersServerFilesIndexHandler(BaseApiHandler): ) if os.path.isdir(data["filename"]): - FileHelpers.del_dirs(data["filename"]) + proc = FileHelpers.del_dirs(data["filename"]) else: - FileHelpers.del_file(data["filename"]) - return self.finish_json(200, {"status": "ok"}) + proc = FileHelpers.del_file(data["filename"]) + # disabling pylint because return value could be truthy + # but not a true boolean value + if proc == True: # pylint: disable=singleton-comparison + return self.finish_json(200, {"status": "ok"}) + return self.finish_json(500, {"status": "error", "error": str(proc)}) def patch(self, server_id: str): auth_data = self.authenticate_user()