Skip to content

Commit e4668f1

Browse files
authored
ignore enoent during visitFiles (#1700)
* ignore enoent during visitFiles * handle readdirSync ENOENT, too
1 parent 0723b2a commit e4668f1

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/files.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,21 @@ export function* visitFiles(root: string, test?: (name: string) => boolean): Gen
5050
const visited = new Set<number>();
5151
const queue: string[] = [(root = normalize(root))];
5252
for (const path of queue) {
53-
const status = statSync(path);
54-
if (status.isDirectory()) {
55-
if (visited.has(status.ino)) continue; // circular symlink
56-
visited.add(status.ino);
57-
for (const entry of readdirSync(path)) {
58-
if (entry === ".observablehq") continue; // ignore the .observablehq directory
59-
if (test !== undefined && !test(entry)) continue;
60-
queue.push(join(path, entry));
53+
try {
54+
const status = statSync(path);
55+
if (status.isDirectory()) {
56+
if (visited.has(status.ino)) continue; // circular symlink
57+
visited.add(status.ino);
58+
for (const entry of readdirSync(path)) {
59+
if (entry === ".observablehq") continue; // ignore the .observablehq directory
60+
if (test !== undefined && !test(entry)) continue;
61+
queue.push(join(path, entry));
62+
}
63+
} else {
64+
yield relative(root, path);
6165
}
62-
} else {
63-
yield relative(root, path);
66+
} catch (error) {
67+
if (!isEnoent(error)) throw error;
6468
}
6569
}
6670
}

0 commit comments

Comments
 (0)