file_manager: remove redundant code in delete_file method
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
538c68fc8b
commit
4e262dfa14
|
@ -681,23 +681,11 @@ class FileManager:
|
||||||
|
|
||||||
async def delete_file(self, path: str) -> Dict[str, Any]:
|
async def delete_file(self, path: str) -> Dict[str, Any]:
|
||||||
async with self.write_mutex:
|
async with self.write_mutex:
|
||||||
parts = os.path.normpath(path).lstrip("/").split("/", 1)
|
root, full_path = self._convert_request_path(path)
|
||||||
if len(parts) != 2:
|
filename = self.get_relative_path(root, full_path)
|
||||||
|
if root not in self.full_access_roots:
|
||||||
raise self.server.error(
|
raise self.server.error(
|
||||||
f"Path not available for DELETE: {path}", 405)
|
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):
|
if not os.path.isfile(full_path):
|
||||||
raise self.server.error(f"Invalid file path: {path}")
|
raise self.server.error(f"Invalid file path: {path}")
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue