(directory: string, depth: number)
| 123 | // the tree rather than assume a depth. The cap stops a mistaken root from walking a whole disk. |
| 124 | const found: string[] = []; |
| 125 | const visit = async (directory: string, depth: number): Promise<void> => { |
| 126 | let entries: Dirent[]; |
| 127 | try { entries = await readdir(directory, { withFileTypes: true }); } |
| 128 | catch (error) { |
| 129 | if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) return; |
| 130 | throw error; |
| 131 | } |
| 132 | for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) { |
| 133 | const path = join(directory, entry.name); |
| 134 | if (entry.isDirectory() && depth < 10) await visit(path, depth + 1); |
| 135 | else if (entry.isFile() && entry.name === "resources.json") { |
| 136 | try { |
| 137 | if (!(await parseJournalFile(path)).cleaned) found.push(path); |
| 138 | } catch { |
| 139 | found.push(path); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | }; |
| 144 | await visit(root, 0); |
| 145 | return found; |
| 146 | } |
no test coverage detected