From 4e262dfa14a9a44d1b2bceda22c517208db0ebca Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Sat, 30 Oct 2021 07:34:40 -0400 Subject: [PATCH] file_manager: remove redundant code in delete_file method Signed-off-by: Eric Callahan --- .../components/file_manager/file_manager.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/moonraker/components/file_manager/file_manager.py b/moonraker/components/file_manager/file_manager.py index 19eb6ad..d6eaa33 100644 --- a/moonraker/components/file_manager/file_manager.py +++ b/moonraker/components/file_manager/file_manager.py @@ -681,23 +681,11 @@ class FileManager: async def delete_file(self, path: str) -> Dict[str, Any]: async with self.write_mutex: - parts = os.path.normpath(path).lstrip("/").split("/", 1) - if len(parts) != 2: + root, full_path = self._convert_request_path(path) + filename = self.get_relative_path(root, full_path) + if root not in self.full_access_roots: raise self.server.error( f"Path not available for DELETE: {path}", 405) - root = parts[0] - filename = parts[1] - if ( - root not in self.file_paths or - root not in self.full_access_roots - ): - raise self.server.error( - f"Path not available for DELETE: {path}", 405) - root_path = self.file_paths[root] - full_path = os.path.abspath(os.path.join(root_path, filename)) - if not full_path.startswith(root_path): - raise self.server.error( - f"Delete request on file outside of root: {path}") if not os.path.isfile(full_path): raise self.server.error(f"Invalid file path: {path}") try: