Repository navigation
fix(fs): keep a descriptor from writing its bytes over a file renamed over its path or created after an unlink - #149
Conversation
… over its path or created after an unlink
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 2 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
The PR adds a file-identity check so an in-memory descriptor only flushes while its path still names the file it opened. Backend.identity and VFS.identity are added, MemoryBackend assigns stable ids to entries across writes, OpenFile.contents.ident is recorded at open and used in shared-descriptor matching, and flushFile skips the write when the path's current identity differs from the descriptor's. Backends without identity are unchanged. The logic is consistent across the rewrite, rename-over, and unlink cases, and the test exercises exactly those paths.
review-bot, model nvidia/nemotron-3.5-super-vl:free, verdict approve
What this changes
A descriptor no longer writes its buffered bytes over a file that has since replaced the one it opened. java-web buffers writes in the open descriptor and writes them out by path. On Linux the bytes go to the opened file (its inode), so when another file is renamed over the path, or the file is unlinked, the path keeps the new file, or none. Before this change, if two VMs in one page's worker shared the in-memory file system and one renamed a file over a path (the usual atomic save) while the other still held unwritten bytes for the old file, the other VM's next flush, sync or close overwrote the new file. Since #140 a
cjFileBlobread does that flush too. An unlinked file was also created again by such a flush.Backend.identity) that it keeps across writes and renames.Inside one VM a rename or unlink already moved or detached that VM's descriptors, so this only changes what one VM sees of another.
Tests
test/fs.test.ts: a descriptor's bytes are written while its path names the same file (rewritten by path), and not after a file is renamed over the path or the file is removed. A rename keeps a file's identity. Without the check, the renamed-over file reads back the stale bytes.test/fs.test.ts,nio.test.ts,snapshot.test.tspass.pnpm typecheck.