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

Function fs2json

scripts/fs2json.js:21–112  ·  view source on GitHub ↗
(dir)

Source from the content-addressed store, hash-verified

19});
20
21const fs2json = (dir) => {
22 let totalSize = 0;
23
24 const makeNode = (st, name) => {
25 const obj = [];
26
27 obj[IDX_NAME] = name;
28 obj[IDX_SIZE] = st.size;
29 obj[IDX_MTIME] = Number(st.mtime);
30
31 totalSize += st.size;
32
33 return obj;
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();

Callers 1

fs2json.jsFile · 0.85

Calls 7

walkFunction · 0.85
mkdirFunction · 0.50
dirnameFunction · 0.50
writeFileFunction · 0.50
infoMethod · 0.45
thenMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected