vfs: read RealFSProvider files from open fd by trivikr · Pull Request #64104 · nodejs/node · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 85 additions & 2 deletions lib/internal/vfs/providers/real.js
29 changes: 29 additions & 0 deletions test/parallel/test-vfs-fs-readFileSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,32 @@ assert.strictEqual(
}

myVfs.unmount();

// readFileSync via a RealFSProvider fd remains usable after the backing path
// is renamed.
{
const root = path.join('/tmp', 'vfs-real-readFileSync-' + process.pid);
const realMountPoint = path.join('/tmp', 'vfs-real-readFileSync-mount-' + process.pid);
fs.rmSync(root, { recursive: true, force: true });
fs.rmSync(realMountPoint, { recursive: true, force: true });
fs.mkdirSync(root, { recursive: true });
fs.mkdirSync(realMountPoint, { recursive: true });

const realVfs = vfs
.create(new vfs.RealFSProvider(root), { emitExperimentalWarning: false })
.mount(realMountPoint);
try {
fs.writeFileSync(path.join(root, 'a.txt'), 'still readable');
const fd = fs.openSync(path.join(realMountPoint, 'a.txt'), 'r');
try {
fs.renameSync(path.join(root, 'a.txt'), path.join(root, 'b.txt'));
assert.strictEqual(fs.readFileSync(fd, 'utf8'), 'still readable');
} finally {
fs.closeSync(fd);
}
} finally {
realVfs.unmount();
fs.rmSync(root, { recursive: true, force: true });
fs.rmSync(realMountPoint, { recursive: true, force: true });
}
}
49 changes: 49 additions & 0 deletions test/parallel/test-vfs-real-provider-handle.js
Loading