Adds the node:vfs builtin module with VirtualFileSystem and provider classes. No integration with fs, modules, or SEA. Assisted-by: Claude-Opus4.7 Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/63115 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
// Flags: --experimental-vfs
|
|
'use strict';
|
|
|
|
// Symlink behaviour in the default (memory) VFS:
|
|
// - Loop detection (ELOOP)
|
|
// - Absolute and relative targets
|
|
// - Symlinked parent directories transparently follow
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const vfs = require('node:vfs');
|
|
|
|
// Direct symlink loop: /a -> /b -> /a
|
|
{
|
|
const myVfs = vfs.create();
|
|
myVfs.symlinkSync('/b', '/a');
|
|
myVfs.symlinkSync('/a', '/b');
|
|
assert.throws(() => myVfs.statSync('/a'), { code: 'ELOOP' });
|
|
assert.throws(() => myVfs.realpathSync('/a'), { code: 'ELOOP' });
|
|
}
|
|
|
|
// Symlink loop in an intermediate path component
|
|
{
|
|
const myVfs = vfs.create();
|
|
myVfs.symlinkSync('/loop2', '/loop1');
|
|
myVfs.symlinkSync('/loop1', '/loop2');
|
|
assert.throws(() => myVfs.statSync('/loop1/sub'), { code: 'ELOOP' });
|
|
}
|
|
|
|
// Absolute symlink target inside the VFS
|
|
{
|
|
const myVfs = vfs.create();
|
|
myVfs.mkdirSync('/dir');
|
|
myVfs.writeFileSync('/dir/file.txt', 'hi');
|
|
myVfs.symlinkSync('/dir', '/abs-link');
|
|
assert.strictEqual(myVfs.readFileSync('/abs-link/file.txt', 'utf8'), 'hi');
|
|
}
|
|
|
|
// Symlinked parent directory transparently follows on read+write
|
|
{
|
|
const myVfs = vfs.create();
|
|
myVfs.mkdirSync('/real-dir');
|
|
myVfs.writeFileSync('/real-dir/file.txt', 'hello');
|
|
myVfs.symlinkSync('/real-dir', '/link-dir');
|
|
|
|
assert.strictEqual(myVfs.readFileSync('/link-dir/file.txt', 'utf8'), 'hello');
|
|
myVfs.writeFileSync('/link-dir/new.txt', 'new');
|
|
assert.strictEqual(myVfs.readFileSync('/real-dir/new.txt', 'utf8'), 'new');
|
|
}
|
|
|
|
// Symlink onto an existing path throws EEXIST
|
|
{
|
|
const myVfs = vfs.create();
|
|
myVfs.writeFileSync('/a.txt', 'x');
|
|
assert.throws(() => myVfs.symlinkSync('/a.txt', '/a.txt'), { code: 'EEXIST' });
|
|
}
|