Version
latest main branch
Platform
7.1.2-arch3-1
Subsystem
vfs
What steps will reproduce the bug?
const vfs = require('node:vfs');
const provider = new vfs.MemoryProvider();
const virtualFs = vfs.create(provider, {
emitExperimentalWarning: false,
});
virtualFs.writeFileSync('/file.txt', 'old');
const fd = virtualFs.openSync('/file.txt', 'r+');
provider.setReadOnly();
const data = Buffer.from('new');
virtualFs.writeSync(fd, data, 0, data.length, 0);
console.log(virtualFs.readFileSync('/file.txt', 'utf8')); // "new"
virtualFs.closeSync(fd);
Run with:
node --experimental-vfs reproduction.js
How often does it reproduce? Is there a required condition?
It reproduces consistently.
The writable file descriptor must be opened before setReadOnly() is called. Opening a new writable descriptor after setReadOnly() correctly throws EROFS.
What is the expected behavior? Why is that the expected behavior?
Once setReadOnly() has been called, subsequent writes through any VirtualFileSystem backed by that provider should throw an error with code === 'EROFS', including writes through file descriptors that were opened before the provider became read-only.
This follows the current documentation for MemoryProvider.setReadOnly():
Subsequent writes through any VirtualFileSystem using this provider throw EROFS.