mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 14:31:22 +00:00
refactor(apple): project macOS Distribution metadata directly (#16688)
This commit is contained in:
1 parent
534428cf25
commit
aa6b6ea289
3 files changed
+17
-49
No files matched your search
@@ -865,28 +865,11 @@ export class MacosPkgArtifactReader implements ArtifactReader {
|
||||
metadataBudget.remainingRecords = Math.max(
|
||||
0,
|
||||
metadataBudget.remainingRecords -
|
||||
(parsed.value.pkgRefs.length +
|
||||
(parsed.value.pkg_refs.length +
|
||||
parsed.value.choices.length +
|
||||
parsed.value.allowedOsVersions.length),
|
||||
parsed.value.allowed_os_versions.length),
|
||||
);
|
||||
metadata.distribution = {
|
||||
title: parsed.value.title,
|
||||
pkg_refs: parsed.value.pkgRefs.map((ref) => ({
|
||||
id: ref.id,
|
||||
version: ref.version,
|
||||
install_kbytes: ref.installKBytes,
|
||||
})),
|
||||
choices: [...parsed.value.choices],
|
||||
allowed_os_versions: parsed.value.allowedOsVersions.map(
|
||||
(range) => ({
|
||||
min: range.min,
|
||||
max: range.max,
|
||||
}),
|
||||
),
|
||||
installation_check_script_bytes:
|
||||
parsed.value.installationCheckScriptBytes,
|
||||
volume_check_script_bytes: parsed.value.volumeCheckScriptBytes,
|
||||
};
|
||||
metadata.distribution = parsed.value;
|
||||
} else
|
||||
metadata.refusals.push(
|
||||
refusalFromParse(parsed.error, distribution.path),
|
||||
|
||||
@@ -18,7 +18,7 @@ const distribution = (installKBytes: string): Buffer =>
|
||||
const installKBytesOf = (installKBytes: string): number | null => {
|
||||
const parsed = parseDistributionXml(distribution(installKBytes));
|
||||
if (!parsed.ok) throw new Error("Distribution fixture did not parse");
|
||||
return parsed.value.pkgRefs[0]?.installKBytes ?? null;
|
||||
return parsed.value.pkg_refs[0]?.install_kbytes ?? null;
|
||||
};
|
||||
|
||||
it("keeps installKBytes up to the uint32 maximum", () => {
|
||||
@@ -44,8 +44,8 @@ it("counts check script length in UTF-8 bytes", () => {
|
||||
),
|
||||
);
|
||||
if (!parsed.ok) throw new Error("Distribution fixture did not parse");
|
||||
expect(parsed.value.installationCheckScriptBytes).toBe(7);
|
||||
expect(parsed.value.volumeCheckScriptBytes).toBe(8);
|
||||
expect(parsed.value.installation_check_script_bytes).toBe(7);
|
||||
expect(parsed.value.volume_check_script_bytes).toBe(8);
|
||||
});
|
||||
|
||||
it("refuses installer XML with an unrelated root element", () => {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import type { Element } from "@xmldom/xmldom";
|
||||
|
||||
import type { MacosPkgMetadata } from "../../domain/formatMetadata/macosPkgMetadata.js";
|
||||
|
||||
import {
|
||||
MACOS_PKG_FORMAT,
|
||||
MACOS_PKG_MAX_METADATA_RECORDS,
|
||||
@@ -16,26 +18,6 @@ import { decodeStrictUtf8 } from "../../domain/strictUtf8.js";
|
||||
import { parseXmlDocumentWithinNodeLimit } from "../../domain/xmlDocument.js";
|
||||
import { attributeOf, childElement, childElements } from "./xmlElements.js";
|
||||
|
||||
export interface PkgRefRecord {
|
||||
readonly id: string | null;
|
||||
readonly version: string | null;
|
||||
readonly installKBytes: number | null;
|
||||
}
|
||||
|
||||
export interface OsVersionRange {
|
||||
readonly min: string | null;
|
||||
readonly max: string | null;
|
||||
}
|
||||
|
||||
export interface DistributionFacts {
|
||||
readonly title: string | null;
|
||||
readonly pkgRefs: readonly PkgRefRecord[];
|
||||
readonly choices: readonly string[];
|
||||
readonly allowedOsVersions: readonly OsVersionRange[];
|
||||
readonly installationCheckScriptBytes: number | null;
|
||||
readonly volumeCheckScriptBytes: number | null;
|
||||
}
|
||||
|
||||
export interface PackageBundleRecord {
|
||||
readonly id: string | null;
|
||||
readonly path: string | null;
|
||||
@@ -199,7 +181,10 @@ const scriptLength = (parent: Element | undefined): number | null => {
|
||||
export const parseDistributionXml = (
|
||||
bytes: Buffer,
|
||||
limits?: Partial<InstallerXmlLimits>,
|
||||
): Result<DistributionFacts, MacosPkgParseError> => {
|
||||
): Result<
|
||||
NonNullable<MacosPkgMetadata["distribution"]>,
|
||||
MacosPkgParseError
|
||||
> => {
|
||||
const { remainingRecords, maxRecords, maxXmlNodes } =
|
||||
resolveXmlLimits(limits);
|
||||
const root = parseUtf8Xml(
|
||||
@@ -253,7 +238,7 @@ export const parseDistributionXml = (
|
||||
const pkgRefs = pkgRefElements.map((element) => ({
|
||||
id: attributeOf(element, "id"),
|
||||
version: attributeOf(element, "version"),
|
||||
installKBytes: uint32Attribute(element, "installKBytes"),
|
||||
install_kbytes: uint32Attribute(element, "installKBytes"),
|
||||
}));
|
||||
const allowedOsVersions = osVersionElements.map((element) => ({
|
||||
min: attributeOf(element, "min"),
|
||||
@@ -261,13 +246,13 @@ export const parseDistributionXml = (
|
||||
}));
|
||||
return ok({
|
||||
title,
|
||||
pkgRefs,
|
||||
pkg_refs: pkgRefs,
|
||||
choices,
|
||||
allowedOsVersions,
|
||||
installationCheckScriptBytes: scriptLength(
|
||||
allowed_os_versions: allowedOsVersions,
|
||||
installation_check_script_bytes: scriptLength(
|
||||
childElement(installer, "installation-check"),
|
||||
),
|
||||
volumeCheckScriptBytes: scriptLength(
|
||||
volume_check_script_bytes: scriptLength(
|
||||
childElement(installer, "volume-check"),
|
||||
),
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user