Skip to content

Commit e0cdf6d

Browse files
committed
catch exception when directory contents change mid-traversal (#14342)
1 parent f86a0bb commit e0cdf6d

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

news/changelog-1.10.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ All changes included in 1.10:
4040

4141
- ([#6651](https://github.com/quarto-dev/quarto-cli/issues/6651)): Fix dart-sass compilation failing in enterprise environments where `.bat` files are blocked by group policy.
4242
- ([#14255](https://github.com/quarto-dev/quarto-cli/issues/14255)): Fix shortcodes inside inline and display math expressions not being resolved.
43-
43+
- ([#14342](https://github.com/quarto-dev/quarto-cli/issues/14342)): Work around TOCTOU race in Deno's `expandGlobSync` that can cause unexpected exceptions to be raised while traversing directories during project initialization.

src/core/path.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,23 @@ export function resolvePathGlobs(
172172
const expandGlobs = (targetGlobs: string[]) => {
173173
const expanded: string[] = [];
174174
for (const glob of targetGlobs) {
175-
for (
176-
const file of expandGlobSync(
177-
glob,
178-
{ root, exclude, includeDirs: true, extended: true, globstar: true },
179-
)
180-
) {
181-
expanded.push(file.path);
175+
try {
176+
for (
177+
const file of expandGlobSync(
178+
glob,
179+
{ root, exclude, includeDirs: true, extended: true, globstar: true },
180+
)
181+
) {
182+
expanded.push(file.path);
183+
}
184+
} catch (e) {
185+
// expandGlobSync can throw NotFound if a file is deleted between
186+
// directory listing and stat (TOCTOU race). This is expected during
187+
// preview when the IDE or other processes modify the project
188+
// directory concurrently.
189+
if (!(e instanceof Deno.errors.NotFound)) {
190+
throw e;
191+
}
182192
}
183193
}
184194
return ld.uniq(expanded);

0 commit comments

Comments
 (0)