@@ -386,36 +386,34 @@ const make = Effect.gen(function* () { |
386 | 386 | let entries = 1; |
387 | 387 | let bytes = 0; |
388 | 388 | while (pending.length > 0) { |
389 | | - const target = pending.pop()!; |
390 | | - if (target === skipped) continue; |
391 | | - // Effect's stat follows links. Probe with readLink first to get lstat |
392 | | - // semantics, including skipping dangling links and directory links. |
393 | | - const isLink = yield* fs.readLink(target).pipe( |
394 | | - Effect.as(true), |
395 | | - Effect.catchIf( |
396 | | - (error) => |
397 | | - error.cause instanceof Error && |
398 | | - "code" in error.cause && |
399 | | - error.cause.code === "EINVAL", |
400 | | - () => Effect.succeed(false), |
401 | | - ), |
| 389 | + const inspected = yield* Effect.forEach( |
| 390 | + pending.splice(-8), |
| 391 | + // Untraced: this runs once per entry, and a worktree can hold millions. |
| 392 | + Effect.fnUntraced(function* (target) { |
| 393 | + if (target === skipped) return { target, bytes: 0, names: [] }; |
| 394 | + const stat = yield* fs.lstat(target); |
| 395 | + if (stat.type === "SymbolicLink") return { target, bytes: 0, names: [] }; |
| 396 | + if ((yield* fs.realPath(target)) !== target) return null; |
| 397 | + if (stat.type === "Directory") |
| 398 | + return { target, bytes: 0, names: yield* fs.readDirectory(target) }; |
| 399 | + // Removing a shared hardlink leaves its blocks allocated. |
| 400 | + if (stat.type !== "File" || Option.getOrElse(stat.nlink, () => 1n) !== 1n) |
| 401 | + return { target, bytes: 0, names: [] }; |
| 402 | + const bytes = Option.match(stat.blocks, { |
| 403 | + onNone: () => Number(stat.size), |
| 404 | + onSome: (blocks) => Number(blocks * 512n), |
| 405 | + }); |
| 406 | + return { target, bytes, names: [] }; |
| 407 | + }), |
| 408 | + { concurrency: "unbounded" }, |
402 | 409 | ); |
403 | | - if (isLink) continue; |
404 | | - if ((yield* fs.realPath(target)) !== target) return null; |
405 | | - const stat = yield* fs.stat(target); |
406 | | - if (stat.type === "File") { |
407 | | - // Removing a shared hardlink leaves its blocks allocated. |
408 | | - if (Option.getOrElse(stat.nlink, () => 1n) !== 1n) continue; |
409 | | - bytes += Option.match(stat.blocks, { |
410 | | - onNone: () => Number(stat.size), |
411 | | - onSome: (blocks) => Number(blocks * 512n), |
412 | | - }); |
413 | | - } else if (stat.type === "Directory") { |
414 | | - const names = yield* fs.readDirectory(target); |
415 | | - entries += names.length; |
| 410 | + for (const result of inspected) { |
| 411 | + if (result === null) return null; |
| 412 | + bytes += result.bytes; |
| 413 | + entries += result.names.length; |
416 | 414 | if (entries > 2_000_000) return null; |
417 | | - for (const name of names) { |
418 | | - const child = path.join(target, name); |
| 415 | + for (const name of result.names) { |
| 416 | + const child = path.join(result.target, name); |
419 | 417 | if (!inside(root, child)) return null; |
420 | 418 | pending.push(child); |
421 | 419 | } |
|