MCPcopy Create free account
hub / github.com/nodejs/node / #ensurePopulated

Method #ensurePopulated

lib/internal/vfs/providers/memory.js:460–492  ·  view source on GitHub ↗

* Ensures a directory is populated by calling its populate callback if needed. * @param {MemoryEntry} entry The directory entry * @param {string} path The directory path (for error messages and scoped VFS)

(entry, path)

Source from the content-addressed store, hash-verified

458 * @param {string} path The directory path (for error messages and scoped VFS)
459 */
460 #ensurePopulated(entry, path) {
461 if (entry.isDirectory() && !entry.populated && entry.populate) {
462 // Create a scoped VFS for the populate callback
463 const scopedVfs = {
464 addFile: (name, content, opts) => {
465 const fileEntry = new MemoryEntry(TYPE_FILE, opts);
466 if (typeof content === 'function') {
467 fileEntry.content = Buffer.alloc(0);
468 fileEntry.contentProvider = content;
469 } else {
470 fileEntry.content = typeof content === 'string' ? Buffer.from(content) : content;
471 }
472 entry.children.set(name, fileEntry);
473 },
474 addDirectory: (name, populate, opts) => {
475 const dirEntry = new MemoryEntry(TYPE_DIR, opts);
476 dirEntry.children = new SafeMap();
477 if (typeof populate === 'function') {
478 dirEntry.populate = populate;
479 dirEntry.populated = false;
480 }
481 entry.children.set(name, dirEntry);
482 },
483 addSymlink: (name, target, opts) => {
484 const symlinkEntry = new MemoryEntry(TYPE_SYMLINK, opts);
485 symlinkEntry.target = target;
486 entry.children.set(name, symlinkEntry);
487 },
488 };
489 entry.populate(scopedVfs);
490 entry.populated = true;
491 }
492 }
493
494 openSync(path, flags, mode) {
495 const normalized = this.#normalizePath(path);

Callers 4

#lookupEntryMethod · 0.95
#ensureParentMethod · 0.95
readdirSyncMethod · 0.95
walkMethod · 0.95

Calls 4

allocMethod · 0.80
isDirectoryMethod · 0.45
fromMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected