MCPcopy Create free account
hub / github.com/nodejs/node / walk

Method walk

lib/internal/vfs/providers/memory.js:615–653  ·  view source on GitHub ↗
(entry, currentPath, relativePath)

Source from the content-addressed store, hash-verified

613 const results = [];
614
615 const walk = (entry, currentPath, relativePath) => {
616 this.#ensurePopulated(entry, currentPath);
617
618 for (const { 0: name, 1: childEntry } of entry.children) {
619 const childRelative = relativePath ?
620 relativePath + '/' + name : name;
621
622 if (withFileTypes) {
623 let type;
624 if (childEntry.isSymbolicLink()) {
625 type = UV_DIRENT_LINK;
626 } else if (childEntry.isDirectory()) {
627 type = UV_DIRENT_DIR;
628 } else {
629 type = UV_DIRENT_FILE;
630 }
631 ArrayPrototypePush(results,
632 new Dirent(childRelative, type, dirPath));
633 } else {
634 ArrayPrototypePush(results, childRelative);
635 }
636
637 // Follow symlinks to directories for recursive traversal
638 let resolvedChild = childEntry;
639 if (childEntry.isSymbolicLink()) {
640 const targetPath = this.#resolveSymlinkTarget(
641 pathPosix.join(currentPath, name), childEntry.target,
642 );
643 const result = this.#lookupEntry(targetPath, true, 0);
644 if (result.entry) {
645 resolvedChild = result.entry;
646 }
647 }
648 if (resolvedChild.isDirectory()) {
649 const childPath = pathPosix.join(currentPath, name);
650 walk(resolvedChild, childPath, childRelative);
651 }
652 }
653 };
654
655 walk(dirEntry, dirPath, '');
656 return results;

Callers 15

glob_to_varFunction · 0.80
package_filesFunction · 0.80
subdir_filesFunction · 0.80
_ExpandDirectoriesFunction · 0.80
list_templatesMethod · 0.80
find_all_gyptest_filesFunction · 0.80
_read_logsFunction · 0.80
mainFunction · 0.80
FindFilesInMethod · 0.80
FindTestsFunction · 0.80
mainFunction · 0.80

Calls 7

#ensurePopulatedMethod · 0.95
#resolveSymlinkTargetMethod · 0.95
#lookupEntryMethod · 0.95
walkFunction · 0.50
isSymbolicLinkMethod · 0.45
isDirectoryMethod · 0.45
joinMethod · 0.45

Tested by 2

find_all_gyptest_filesFunction · 0.64
_list_test_filenamesMethod · 0.64