Consolidate duplicate delete_temp_file_if_exists function

- Remove duplicate from routes.py
- Import from upload.py instead
- Rename to public API (remove leading underscore)

Amp-Thread-ID: https://ampcode.com/threads/T-019c3549-c245-7628-950c-dd6826185394
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Luke Mino-Altherr
2026-02-06 15:31:28 -08:00
parent 6edcd690b6
commit 2af0cf18f5
2 changed files with 16 additions and 21 deletions

View File

@@ -117,7 +117,7 @@ async def parse_multipart_upload(
f.write(chunk)
file_written += len(chunk)
except Exception:
_delete_temp_file_if_exists(tmp_path)
delete_temp_file_if_exists(tmp_path)
raise UploadError(
500, "UPLOAD_IO_ERROR", "Failed to receive and store uploaded file."
)
@@ -139,7 +139,7 @@ async def parse_multipart_upload(
and file_written == 0
and not (provided_hash and provided_hash_exists)
):
_delete_temp_file_if_exists(tmp_path)
delete_temp_file_if_exists(tmp_path)
raise UploadError(400, "EMPTY_UPLOAD", "Uploaded file is empty.")
return ParsedUpload(
@@ -155,7 +155,7 @@ async def parse_multipart_upload(
)
def _delete_temp_file_if_exists(tmp_path: str | None) -> None:
def delete_temp_file_if_exists(tmp_path: str | None) -> None:
"""Safely remove a temp file if it exists."""
if tmp_path:
try: