Repository navigation
Commit 7dc802f
write_file and edit_file replaced an existing file by renaming a temp file
over it. That gave the file a new inode every time, so it lost its creation
time, hard links and inode identity (#4512), and on Windows the rename fails
with EPERM when another process holds the file open (#3199).
Both now go through overwriteInPlace in lib.ts, which truncates and writes
through a single handle on the existing file. Symlink safety is kept by
three checks: lstat refuses anything that is not a regular file, the open
uses O_NOFOLLOW where the platform has it (POSIX), and the opened handle
must have the device and inode lstat saw, which catches a swap between the
lstat and the open on every platform, Windows included. Permission bits now
survive by construction, so the chmod repair after the rename is gone.
The trade-off is crash-atomicity: a crash mid-write can leave the file
partly written. Documented in the README and the changeset.
The pinning tests for #4512 and #3199 now assert the correct behavior and
lose their KNOWN BUG markers; new tests stage a symlink swap and a file
swap inside the TOCTOU window against the real filesystem.
Approach follows #4516 (O_NOFOLLOW open, fstat, truncate and write) and
the Windows O_NOFOLLOW caveat raised on #4512.
Part of #5004 (Wave 2).
Co-authored-by: 0ywfe <[email protected]>
Co-authored-by: Ayush Padhy <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
1 parent 571e2b3 commit 7dc802f
6 files changed
Lines changed: 348 additions & 193 deletions
File tree
- .changeset
- src/filesystem
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
98 | 102 | | |
99 | 103 | | |
100 | 104 | | |
| |||
0 commit comments