@@ -30,6 +30,7 @@ const { createENOENT, createEXDEV } = require('internal/vfs/errors');
3030const { getVirtualFd, closeVirtualFd } = require ( 'internal/vfs/fd' ) ;
3131const { vfsState, setVfsHandlers } = require ( 'internal/fs/utils' ) ;
3232const permission = require ( 'internal/process/permission' ) ;
33+ const { getOptionValue } = require ( 'internal/options' ) ;
3334
3435/**
3536 * Converts a path argument (string or URL) to a string path.
@@ -72,10 +73,10 @@ let vfsHandlerObj;
7273 * @param {VirtualFileSystem } vfs The VFS instance to register
7374 */
7475function registerVFS ( vfs ) {
75- if ( permission . isEnabled ( ) && ! vfs . allowWithPermissionModel ) {
76+ if ( permission . isEnabled ( ) && ! getOptionValue ( '--allow-fs- vfs' ) ) {
7677 throw new ERR_INVALID_STATE (
7778 'VFS cannot be used when the permission model is enabled. ' +
78- 'Set allowWithPermissionModel: true to override .' ,
79+ 'Use --allow-fs-vfs to allow it .' ,
7980 ) ;
8081 }
8182 if ( ArrayPrototypeIndexOf ( activeVFSList , vfs ) === - 1 ) {
@@ -85,8 +86,11 @@ function registerVFS(vfs) {
8586 for ( let i = 0 ; i < activeVFSList . length ; i ++ ) {
8687 const existingMount = activeVFSList [ i ] . mountPoint ;
8788 if ( existingMount == null ) continue ;
88- if ( StringPrototypeStartsWith ( newMount , existingMount ) ||
89- StringPrototypeStartsWith ( existingMount , newMount ) ) {
89+ const newPrefix = newMount === '/' ? '/' : newMount + '/' ;
90+ const existingPrefix = existingMount === '/' ? '/' : existingMount + '/' ;
91+ if ( newMount === existingMount ||
92+ StringPrototypeStartsWith ( newMount , existingPrefix ) ||
93+ StringPrototypeStartsWith ( existingMount , newPrefix ) ) {
9094 throw new ERR_INVALID_STATE (
9195 `VFS mount '${ newMount } ' overlaps with existing mount '${ existingMount } '` ,
9296 ) ;
@@ -884,6 +888,9 @@ function createVfsHandlers() {
884888 chmod : ( path , mode ) => vfsOp ( path , ( vfs , n ) => vfs . promises . chmod ( n , mode ) . then ( ( ) => true ) ) ,
885889 utimes : ( path , atime , mtime ) => vfsOp ( path , ( vfs , n ) => vfs . promises . utimes ( n , atime , mtime ) . then ( ( ) => true ) ) ,
886890 open ( path , flags , mode ) {
891+ return vfsOp ( path , ( vfs , n ) => PromiseResolve ( vfs . openSync ( n , flags , mode ) ) ) ;
892+ } ,
893+ promisesOpen ( path , flags , mode ) {
887894 const pathStr = toPathStr ( path ) ;
888895 if ( pathStr !== null ) {
889896 const r = findVFSForPath ( pathStr ) ;
0 commit comments