fix: handle cross-device config writes#162
Conversation
There was a problem hiding this comment.
oh — I also opened a competing fix for #61 (PR #171) without realising yours was already in flight, the user moved fast and I didn't sweep the open list. closing #171 in favor of yours.
your design is the better one: exporting renameWithCrossDeviceFallback as a generic helper (not just for the config file) with the ops parameter for DI is much cleaner than what I did. the three tests covering happy/fallback/rethrow are the right minimum.
one small thing: the EXDEV-fallback and rethrow tests only check the sequence of mocked calls, not that the file actually gets written. an end-to-end test that injects a throwing renameWithCrossDeviceFallback into writeConfigFile and verifies the file content lands would close the loop on user-facing behavior. if a future refactor breaks the wiring between writeConfigFile and the helper, neither of the current tests would catch it.
style nit: (err as NodeJS.ErrnoException).code !== 'EXDEV' — a tiny isExdevError type guard would read cleaner than the cast.
approved. thanks for the better design.
|
Thanks for the detailed review! I pushed a follow-up commit that addresses both suggestions:
Validation:
|
Summary
Fix config writes when
renameSync(tmp, path)fails withEXDEV.This addresses #61.
Changes
renameSyncpath for normal config writes.EXDEVfallback that copies the temp config file to the final path and then removes the temp file.EXDEVerrors by rethrowing them.Why
Issue #61 reports: