Skip to content

Commit b17817e

Browse files
mcollinaaduh95
authored andcommitted
vfs: dispatch fs/promises to mounted VFS instances
Add mount/unmount lifecycle on `VirtualFileSystem`, a handler registry that fs.js and fs/promises.js consult via `vfsState.handlers`, and a router that maps absolute paths to the VFS that owns them. When a VFS is mounted, the public `fs.*` and `fs/promises` APIs (including streams, `fs.watch`, and `opendir`) dispatch to the provider for paths under the mount point, and fall through to the real filesystem otherwise. Includes per-method dispatch tests, error-path coverage, multi-mount routing tests, and router unit tests. Ref: #63115 Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #63537 Refs: #63115 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
1 parent 325087b commit b17817e

50 files changed

Lines changed: 3733 additions & 35 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎lib/fs.js‎

Lines changed: 547 additions & 24 deletions
Large diffs are not rendered by default.

‎lib/internal/fs/dir.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const {
3131
getDirent,
3232
getOptions,
3333
getValidatedPath,
34+
vfsState,
3435
}=require('internal/fs/utils');
3536
const{
3637
validateFunction,
@@ -330,6 +331,20 @@ function opendir(path, options, callback) {
330331
callback=typeofoptions==='function' ? options : callback;
331332
validateFunction(callback,'callback');
332333

334+
consth=vfsState.handlers;
335+
if(h!==null){
336+
try{
337+
constresult=h.opendirSync(path,options);
338+
if(result!==undefined){
339+
process.nextTick(callback,null,result);
340+
return;
341+
}
342+
}catch(err){
343+
process.nextTick(callback,err);
344+
return;
345+
}
346+
}
347+
333348
path=getValidatedPath(path);
334349
options=getOptions(options,{
335350
encoding: 'utf8',
@@ -354,6 +369,12 @@ function opendir(path, options, callback) {
354369
}
355370

356371
functionopendirSync(path,options){
372+
consth=vfsState.handlers;
373+
if(h!==null){
374+
constresult=h.opendirSync(path,options);
375+
if(result!==undefined)returnresult;
376+
}
377+
357378
path=getValidatedPath(path);
358379
options=getOptions(options,{encoding: 'utf8'});
359380

0 commit comments

Comments
 (0)