Add atomic write_bytes helper for upload temp files #11

Closed
opened 2026-05-03 10:09:14 +00:00 by gravityfargo · 0 comments
Owner

Context

Filed in support of athena-archive-api #81. The BE writes uploaded bytes to a temp file with raw `Path.write_bytes(file_content)` (utils.py:166), which is non-atomic — a crash mid-write leaves a half-written file.

Plan

Add a helper that takes `(target: Path, data: bytes)`, writes to `target.with_suffix(target.suffix + ".part")`, then `os.replace()` to the final path. Returns a `FileWorker` for the new file.

Could live as `FileWorker.from_bytes(target, data)` factory or as a standalone `atomic_write_bytes()` helper.

Acceptance criteria

  • Helper exists; tests cover happy path + interrupt-mid-write (file should not exist at target)
## Context Filed in support of athena-archive-api #81. The BE writes uploaded bytes to a temp file with raw \`Path.write_bytes(file_content)\` (utils.py:166), which is non-atomic — a crash mid-write leaves a half-written file. ## Plan Add a helper that takes \`(target: Path, data: bytes)\`, writes to \`target.with_suffix(target.suffix + ".part")\`, then \`os.replace()\` to the final path. Returns a \`FileWorker\` for the new file. Could live as \`FileWorker.from_bytes(target, data)\` factory or as a standalone \`atomic_write_bytes()\` helper. ## Acceptance criteria - [ ] Helper exists; tests cover happy path + interrupt-mid-write (file should not exist at target)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ModernLeft/athena-file#11
No description provided.