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:
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user