v1.1.0-beta.074 - fix(safe-fs): atomic staged publish for cross-device moves (issue #170)
๐ Fixes
- moveFileSafe's EXDEV fallback copied straight to the final destination path โ an interrupted copy (container restart, drive drop) could leave a truncated archive at the final name where the library scanner would index it (raised by ProjectCetacean in issue #170)
โ๏ธ Changes
- EXDEV fallback now stages the copy to a randomized .tmp file BESIDE the destination, then renames it into place โ the rename is same-filesystem and atomic, so the final path only ever holds a complete file
- Explicit EEXIST guard before publishing (preserves the never-overwrite contract previously enforced by errorOnExist); a failed copy removes the staged temp and leaves the source intact
- Import path audited per the same report: importer.ts and the watched-folder handlers already use fs-extra move/copy, which handle EXDEV internally โ no changes needed there
๐งช Tests
- 2 new moveFileSafe tests: EXDEV fallback refuses to overwrite an existing destination (EEXIST, both files intact); mid-copy failure cleans up the staged temp with the source untouched
- EXDEV fallback test now also asserts no stray .tmp files remain after a successful staged publish
โ Verification
- tsc clean, vitest 307/307
Co-Authored-By: Claude Fable 5 noreply@anthropic.com