Skip to content

Commit

Permalink
fix crash in getFileInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Mar 25, 2024
1 parent 9d1e46f commit 08325c5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/javascript/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {createHash} from "node:crypto";
import {readFileSync, statSync} from "node:fs";
import {accessSync, constants, readFileSync, statSync} from "node:fs";
import {join} from "node:path/posix";
import type {Program} from "acorn";
import {resolvePath} from "../path.js";
Expand Down Expand Up @@ -141,10 +141,13 @@ export function getFileInfo(root: string, path: string): FileInfo | undefined {
const key = join(root, path);
let mtimeMs: number;
try {
({mtimeMs} = statSync(key));
const stat = statSync(key);
if (!stat.isFile()) return; // ignore non-files
accessSync(key, constants.R_OK); // verify that file is readable
({mtimeMs} = stat);
} catch {
fileInfoCache.delete(key); // delete stale entry
return; // ignore missing file
return; // ignore missing, non-readable file
}
let entry = fileInfoCache.get(key);
if (!entry || entry.mtimeMs < mtimeMs) {
Expand Down

0 comments on commit 08325c5

Please sign in to comment.