mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-10-03 09:10:11 +03:00
Fix silent file write failure in write_compute_project_file
The inner try-except caught OSError/UnicodeEncodeError with 'pass', silently swallowing all write failures and returning HTTP 204 as if the file was written successfully. Remove the nested try-except and let errors propagate properly: - OSError → 500 with error detail - PermissionError → 403 (already handled) - FileNotFoundError → 404 (already handled)
This commit is contained in:
parent
cbb21e8e40
commit
16a9064eb8
@ -194,17 +194,17 @@ async def write_compute_project_file(
|
|||||||
try:
|
try:
|
||||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||||
|
|
||||||
try:
|
with open(path, "wb+") as f:
|
||||||
with open(path, "wb+") as f:
|
async for chunk in request.stream():
|
||||||
async for chunk in request.stream():
|
f.write(chunk)
|
||||||
f.write(chunk)
|
|
||||||
except (UnicodeEncodeError, OSError) as e:
|
|
||||||
pass # FIXME
|
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
|
||||||
|
except OSError as e:
|
||||||
|
log.error(f"Error writing file '{path}': {e}")
|
||||||
|
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/projects/{project_id}/files/{file_path:path}", status_code=status.HTTP_204_NO_CONTENT)
|
@router.delete("/projects/{project_id}/files/{file_path:path}", status_code=status.HTTP_204_NO_CONTENT)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user