refactor(filesystem): share directory cleanup ownership

Reuse the existing directory close state machine for artifact and reference readers. ArtifactResourceScope can retain the exact directory owner when cleanup fails.
This commit is contained in:
morluto
2026-10-11 06:10:10 +08:00
parent 9515d2fcd3
commit 215001a1ce
3 changed files with 41 additions and 33 deletions
+7
View File
@@ -1,4 +1,5 @@
import type { OwnedFileHandle } from "../filesystem/OwnedFileHandle.js";
import type { OwnedDirectoryHandle } from "../filesystem/OwnedDirectoryHandle.js";
import type { ArtifactReader } from "./ArtifactReader.js";
import { ArtifactReaderFailure } from "./ArtifactReader.js";
@@ -6,6 +7,11 @@ import type { SafeOutputTree } from "./SafeOutputTree.js";
/** One artifact resource and its format-specific cleanup owner. */
export type ArtifactResourceOwner =
| {
readonly kind: "directory-handle";
readonly resource: string;
readonly handle: OwnedDirectoryHandle;
}
| {
readonly kind: "reader";
readonly resource: string;
@@ -132,6 +138,7 @@ const cleanup = async (owner: ArtifactResourceOwner): Promise<void> => {
await owner.reader.close();
return;
case "file-handle":
case "directory-handle":
await owner.handle.close();
return;
case "output-tree":