Skip to content

vfs: route mkdtempDisposable through the fs hooks - #66695

Open
samuelmbabhazi wants to merge 1 commit into
nodejs:mainfrom
samuelmbabhazi:vfs/mkdtemp-disposable-hooks
Open

samuelmbabhazi wants to merge 1 commit into
nodejs:mainfrom
samuelmbabhazi:vfs/mkdtemp-disposable-hooks

Conversation

@samuelmbabhazi

Copy link
Copy Markdown

fs.mkdtempDisposableSync() and fsPromises.mkdtempDisposable() bypass the VFS handlers that fs.mkdtempSync() and fsPromises.mkdtemp() consult, so on a mounted path they fail with ENOTDIR (the mount point does not exist on the real file system):

const myVfs = vfs.create();
myVfs.mkdirSync('/work', { recursive: true });
const prefix = `${myVfs.mount()}/work/tmp-`;
fs.mkdtempSync(prefix);                 // ok
fs.mkdtempDisposableSync(prefix);       // ENOTDIR

This adds the two handlers, built on the VFS mkdtemp and rm, and a test covering the sync and promise variants, Symbol.dispose and Symbol.asyncDispose, the buffer encoding, repeated remove() calls, and a prefix outside the mount.

Verified locally on Linux: the new test, every test/parallel/test-vfs-* test and the fs mkdtemp tests pass. Same approach as #65852.

A coding assistant helped with the investigation and the first draft; I reviewed the change, built Node and ran the tests locally.

fs.mkdtempSync() and fsPromises.mkdtemp() consult the VFS handlers, but
fs.mkdtempDisposableSync() and fsPromises.mkdtempDisposable() call the
binding directly. On a mounted path they fail with ENOTDIR, because the
mount point does not exist on the real file system, while the
non-disposable variants succeed.

Add the two handlers. They create the directory with the VFS mkdtemp
and remove it with the VFS rm, so the disposable object behaves like
the real one: the path is a Buffer when the buffer encoding is
requested, and remove() can be called more than once.

Refs: nodejs#65852
Signed-off-by: Samuel Mbabhazi <samuelmbabhazi@gmail.com>
@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. vfs Issues and PRs related to the virtual filesystem subsystem. labels Oct 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fs Issues and PRs related to file-system APIs and the fs module. 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.

2 participants