Files
reverse-engineering-anything/src/artifacts/ArtifactFileAdmission.ts
T
morluto f4f7c75c66 refactor(artifacts): consolidate selected source lifetimes
Use the shared source owner for Mach-O and PyInstaller admission, descriptor and selected-path identity, hashing and cleanup. Retain lipo joining and reader-owned PyInstaller admission, caller cancellation and private PYZ leases. Centralize admission failure projection and remove the superseded PyInstaller wrapper.

Preserve physical identity verification before late hash-completion cancellation. Close an owned source before returning failed initial metadata acquisition and retain the exact handle when close fails. A focused regression failed twice before that fix and now passes.

Validation: fresh runtime build, 259 focused fixture tests, nine documentation checks and all local static/discovery/duplication gates passed. An earlier check also ran four system-lipo suite cases (three read-only native inspections) before the final source fix; those were excluded from subsequent fixture qualification.
2026-10-25 03:42:49 +08:00

47 lines
1.5 KiB
TypeScript

import {
NonRegularFileReadError,
RegularFileAdmissionFailure,
RegularFileChangedError,
RegularFileOperationCancelled,
} from "../filesystem/RegularFile.js";
import { ArtifactReaderFailure } from "./ArtifactReader.js";
/** Project physical admission failures without taking the caller's descriptor ownership. */
export const artifactFileAdmissionFailure = (
path: string,
diagnosticLabel: string,
cause: unknown,
): ArtifactReaderFailure => {
if (cause instanceof ArtifactReaderFailure) return cause;
if (cause instanceof RegularFileOperationCancelled)
return new ArtifactReaderFailure(
"cancelled",
`${diagnosticLabel} admission cancelled`,
{ cause: cause.reason },
);
if (cause instanceof RegularFileAdmissionFailure)
return ArtifactReaderFailure.withCleanup(
artifactFileAdmissionFailure(path, diagnosticLabel, cause.cause),
ArtifactReaderFailure.cleanupObservation(cause.cleanupCause, path),
);
if (cause instanceof RegularFileChangedError)
return new ArtifactReaderFailure(
"integrity",
`${diagnosticLabel} source changed during admission: ${path}`,
{ cause },
);
if (cause instanceof NonRegularFileReadError)
return new ArtifactReaderFailure(
"format",
`${diagnosticLabel} source is not a regular file: ${path}`,
{ cause },
);
return new ArtifactReaderFailure(
"io",
cause instanceof Error
? cause.message
: `Cannot admit ${diagnosticLabel} source: ${path}`,
{ cause },
);
};