vfs: write RealFSProvider files to open fd - #65885
Conversation
Write RealFileHandle contents through the open file descriptor instead of reopening the original real path, mirroring 8cb8312 for reads. This keeps writes attached to the opened file across renames and makes them honor the handle's access mode. Preserve iterable support and filehandle.writeFile() current-position semantics. Signed-off-by: Christian Aurich <christian.aurichzm@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65885 +/- ##
=======================================
Coverage 90.16% 90.17%
=======================================
Files 771 771
Lines 265094 265172 +78
Branches 50355 50383 +28
=======================================
+ Hits 239027 239111 +84
+ Misses 17011 17006 -5
+ Partials 9056 9055 -1
🚀 New features to boost your workflow:
|
| function isCustomIterable(obj) { | ||
| return isIterable(obj) && !isArrayBufferView(obj) && typeof obj !== 'string'; | ||
| } | ||
|
|
||
| function checkAborted(signal) { | ||
| if (signal?.aborted) { | ||
| throw new AbortError(undefined, { cause: signal.reason }); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
nit: isCustomIterable() and checkAborted() already exist in lib/internal/fs/promises.js. Worth considering whether we can reuse them.
There was a problem hiding this comment.
Thanks. I looked into this. Both helpers are currently module-local in internal/fs/promises.js, so reusing them would require exporting them or moving them to a shared utility. checkAborted also already has a separate module-local implementation in lib/fs.js. I kept the small copies local to avoid broadening this fix, but I'm happy to extract them if you prefer.
RealFileHandle.writeFile()andwriteFileSync()reopen the original real path instead of writing through the handle's file descriptor. A write after the backing file is renamed can recreate the old path, and a read-only handle can write because the path is reopened with the defaultwflag.On
main:Write through the open fd instead, mirroring #64104 for reads. The async path keeps iterable input support and follows
filehandle.writeFile()current-position semantics, which is what #65854 is applying to the memory and zip handles.flushremains one fsync per call.Tests cover writes after rename, read-only handles, iterable input, option and abort handling, and
flush. Two existing assertions encoded the replacing behaviour and are updated.On linux-x64,
make lint, all 115test-vfs-*tests, and the configuredparallelandsequentialsuites pass.Refs: #64104
Refs: #64103
Refs: #65854