MCPcopy Create free account
hub / github.com/DustinBrett/daedalOS / walk

Function walk

scripts/fs2json.js:36–93  ·  view source on GitHub ↗
(walkDir)

Source from the content-addressed store, hash-verified

34 };
35
36 const walk = (walkDir) => {
37 return new Promise((resolve, reject) => {
38 const result = [];
39
40 readdir(walkDir, (dirError, files) => {
41 if (dirError) {
42 reject(dirError);
43 return;
44 }
45
46 const includedFiles =
47 dir === walkDir
48 ? files.filter((file) => !excludedPaths.includes(file))
49 : files;
50
51 const recur = () => {
52 const file = includedFiles.shift();
53
54 if (file) {
55 const fullPath = join(walkDir, file);
56
57 stat(fullPath, (statError, fileStat) => {
58 if (statError) {
59 reject(statError);
60 return;
61 }
62
63 const name = basename(fullPath);
64 const node = makeNode(fileStat, name);
65
66 if (fileStat.isSymbolicLink()) {
67 readlink(fullPath, (linkError, path) => {
68 if (!linkError) {
69 node[IDX_TARGET] = path;
70 result.push(node);
71 recur();
72 }
73 });
74 } else if (fileStat.isDirectory()) {
75 walk(fullPath).then((rest) => {
76 node[IDX_TARGET] = rest;
77 result.push(node);
78 recur();
79 });
80 } else {
81 result.push(node);
82 recur();
83 }
84 });
85 } else {
86 resolve(result);
87 }
88 };
89
90 recur();
91 });
92 });
93 };

Callers 3

textContentMethod · 0.85
recurFunction · 0.85
fs2jsonFunction · 0.85

Calls 5

rejectFunction · 0.85
recurFunction · 0.85
includesMethod · 0.80
readdirFunction · 0.50
filterMethod · 0.45

Tested by

no test coverage detected