fix(artifacts): accept APFS image disks ejected with their container
An APFS disk image attaches as an image disk plus a synthesized APFS container, and hdiutil reports both as whole disks. Detaching the container also ejects the image disk, so the reverse-order detach then failed with "No such file or directory" and every APFS DMG inventory ended in "DMG detach or mount-root cleanup failed". APFS is the default format of `hdiutil create` on current macOS. When a detach fails, ask `hdiutil info -plist` whether the device is still attached. A device that is gone counts as detached; one that is still listed, or whose state cannot be read, remains a cleanup failure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
900d7c8606
commit
b72c079a9a
@@ -23,6 +23,13 @@ const attachOutputSchema = z.object({
|
||||
}),
|
||||
),
|
||||
});
|
||||
const infoOutputSchema = z.object({
|
||||
images: z.array(
|
||||
z.object({
|
||||
"system-entities": z.array(z.object({ "dev-entry": z.string() })),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
/** Narrow host seam for tested, shell-free hdiutil lifecycle operations. */
|
||||
export interface NativeDmgHost {
|
||||
@@ -113,7 +120,10 @@ export class NativeDmgArtifactReader implements ArtifactReader {
|
||||
});
|
||||
this.#provenance.push(command(["detach", device], ["mount"]));
|
||||
} catch (cause: unknown) {
|
||||
detachFailure ??= cause;
|
||||
// Detaching a synthesized APFS container also ejects the image that
|
||||
// backs it, so a later whole disk of the same image may already be
|
||||
// gone. Only a device that is still attached is a cleanup failure.
|
||||
if (await this.#isAttached(device)) detachFailure ??= cause;
|
||||
}
|
||||
}
|
||||
this.#devices = [];
|
||||
@@ -131,6 +141,24 @@ export class NativeDmgArtifactReader implements ArtifactReader {
|
||||
);
|
||||
}
|
||||
|
||||
/** Report whether hdiutil still lists a device; unknown state counts as attached. */
|
||||
async #isAttached(device: string): Promise<boolean> {
|
||||
try {
|
||||
const info = await runChecked(this.host, ["info", "-plist"], undefined, {
|
||||
timeoutMs: DETACH_TIMEOUT_MS,
|
||||
});
|
||||
const parsed = infoOutputSchema.parse(parse(info.stdout));
|
||||
this.#provenance.push(command(["info", "-plist"], ["read"]));
|
||||
return parsed.images.some((image) =>
|
||||
image["system-entities"].some(
|
||||
(entity) => entity["dev-entry"] === device,
|
||||
),
|
||||
);
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
async attach(signal?: AbortSignal): Promise<void> {
|
||||
await runChecked(this.host, ["verify", this.path], signal);
|
||||
this.#provenance.push(command(["verify", this.path], ["read"]));
|
||||
|
||||
Reference in New Issue
Block a user