Skip to content

vfs: support writeFileSync with virtual fds#64165

Open
trivikr wants to merge 2 commits into
nodejs:mainfrom
trivikr:vfs-writefilesync-fd
Open

vfs: support writeFileSync with virtual fds#64165
trivikr wants to merge 2 commits into
nodejs:mainfrom
trivikr:vfs-writefilesync-fd

Conversation

@trivikr

@trivikr trivikr commented Jun 27, 2026

Copy link
Copy Markdown
Member

Fixes: #64164

This updates VFS fs dispatch so fs.writeFileSync(fd, data) and
fs.appendFileSync(fd, data) work with VFS-owned file descriptors instead of
falling through to the native fs binding and throwing EBADF.

The fd path now writes through the virtual file handle, preserving descriptor
semantics for both memory-backed VFS files and RealFSProvider handles.


Assisted-by: openai:gpt-5.5

Route fs.writeFileSync() and fs.appendFileSync() calls with VFS-owned
file descriptors through the virtual file handle instead of falling
back to the native fs binding. This preserves descriptor semantics for
both memory-backed VFS files and RealFSProvider handles.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. vfs Issues and PRs related to the virtual filesystem subsystem. labels Jun 27, 2026
@trivikr trivikr added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 27, 2026

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 27, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikr trivikr added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jun 27, 2026

@gurgunday gurgunday left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Comment thread lib/internal/vfs/setup.js Outdated

function writeFileSyncFd(fd, data, options) {
const vfd = getVirtualFd(fd);
if (!vfd) return undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know vfd's aren't going to be 0 but this seems brittle to me. Can we make this check more explicit rather than relying on a falsy coercion?

@trivikr trivikr removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. vfs Issues and PRs related to the virtual filesystem subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vfs: fs.writeFileSync(fd, ...) does not dispatch virtual file descriptors

5 participants