@adea-ai/app-framework 0.31.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -11
- package/dist/app/create-application.js +4 -3
- package/dist/app/serial-queue.d.ts +5 -0
- package/dist/app/serial-queue.js +14 -0
- package/dist/app/value-guards.d.ts +15 -0
- package/dist/app/value-guards.js +29 -0
- package/dist/ci/toolchain-identity.js +1 -1
- package/dist/desktop/channel-proof.js +2 -1
- package/dist/desktop/client-asset-stream.js +6 -12
- package/dist/desktop/desktop-host.d.ts +25 -5
- package/dist/desktop/desktop-host.js +75 -20
- package/dist/framework-source.json +1 -1
- package/dist/installer/command-artifact.js +4 -3
- package/dist/installer/command-qualification-command.js +6 -5
- package/dist/installer/hosted-runner.d.ts +9 -2
- package/dist/installer/hosted-runner.js +18 -5
- package/dist/installer/installed-payload.js +20 -46
- package/dist/installer/installer-archive.d.ts +33 -0
- package/dist/installer/installer-archive.js +116 -0
- package/dist/installer/installer-ci-bootstrap.js +10 -6
- package/dist/installer/installer-extraction.js +54 -120
- package/dist/installer/installer-identity.js +33 -111
- package/dist/installer/installer-observation.js +3 -2
- package/dist/installer/installer-process-cleanup.js +7 -46
- package/dist/installer/installer-qualification-command.js +6 -5
- package/dist/installer/installer-upgrade-command.js +5 -5
- package/dist/installer/installer-worker-guard.js +2 -1
- package/dist/native/canonical-path.d.ts +5 -0
- package/dist/native/canonical-path.js +10 -0
- package/dist/native/cef-helper.js +5 -4
- package/dist/native/electrobun-source-patch.js +3 -2
- package/dist/native/{directory-exchange.d.ts → native-rename.d.ts} +2 -0
- package/dist/native/native-rename.js +126 -0
- package/dist/native/native-secret-store.js +2 -6
- package/dist/native/native-utilities.js +4 -4
- package/dist/native/posix-launcher-build.js +1 -1
- package/dist/native/posix-tree-removal.js +2 -2
- package/dist/native/windows-process.d.ts +9 -0
- package/dist/native/windows-process.js +60 -0
- package/dist/release/feed-release-cut.js +2 -1
- package/dist/release/framework-package-publish.js +1 -1
- package/dist/release/framework-update-lock.js +2 -1
- package/dist/release/github-cli.d.ts +18 -0
- package/dist/release/github-cli.js +13 -1
- package/dist/release/github-release-cut.js +3 -2
- package/dist/release/github-release-provenance.js +2 -1
- package/dist/release/github-release-publisher.js +2 -1
- package/dist/release/local-provenance.js +3 -2
- package/dist/release/local-release.js +6 -6
- package/dist/release/qualification-run.d.ts +25 -0
- package/dist/release/qualification-run.js +43 -0
- package/dist/release/release-artifact.js +3 -11
- package/dist/release/release-assets-plan.js +16 -6
- package/dist/release/release-config.js +14 -14
- package/dist/release/release-cut-command.js +14 -4
- package/dist/release/release-cut.js +3 -2
- package/dist/release/release-descriptor-staging.js +13 -27
- package/dist/release/release-finalize.js +2 -1
- package/dist/release/release-publication.js +3 -11
- package/dist/release/release-publish-command.js +15 -6
- package/dist/release/release-qualification.js +3 -2
- package/dist/release/retained-release-build.js +12 -12
- package/dist/update-helper.bundle.js +250 -190
- package/dist/updates/desktop-updater.js +53 -58
- package/dist/updates/packaged-launch-admission.js +3 -2
- package/dist/updates/packaged-release-config.js +6 -5
- package/dist/updates/release-feed.js +9 -9
- package/dist/updates/signed-release.js +5 -5
- package/dist/updates/stable-file.d.ts +18 -0
- package/dist/updates/stable-file.js +54 -1
- package/dist/updates/update-adapter.d.ts +2 -13
- package/dist/updates/update-arm.js +7 -5
- package/dist/updates/update-channel-store.js +7 -9
- package/dist/updates/update-discovery.js +30 -34
- package/dist/updates/update-download-cleanup.js +2 -1
- package/dist/updates/update-download.js +2 -4
- package/dist/updates/update-extraction.js +1 -1
- package/dist/updates/update-generation-lease.js +4 -3
- package/dist/updates/update-handoff-plan.js +3 -2
- package/dist/updates/update-helper.js +8 -6
- package/dist/updates/update-instance-lease.js +3 -2
- package/dist/updates/update-launch-gate.js +12 -25
- package/dist/updates/update-launch.js +3 -2
- package/dist/updates/update-lock.js +3 -2
- package/dist/updates/update-marker.js +3 -2
- package/dist/updates/update-process-fence.js +10 -39
- package/dist/updates/update-process-liveness.js +2 -1
- package/dist/updates/update-resume.js +26 -22
- package/dist/updates/update-retention-marker.js +7 -5
- package/dist/updates/update-retention-plan.js +2 -2
- package/dist/updates/update-retirement.js +40 -39
- package/dist/updates/update-state-store.js +29 -37
- package/dist/updates/update-state.d.ts +8 -3
- package/dist/updates/update-swap-stage.js +6 -5
- package/dist/updates/update-swap.d.ts +1 -1
- package/dist/updates/update-swap.js +8 -6
- package/package.json +4 -12
- package/src/desktop/client-asset-stream.ts +6 -12
- package/src/updates/update-adapter.ts +2 -14
- package/src/updates/update-state.ts +11 -2
- package/dist/native/directory-exchange.js +0 -90
- package/dist/native/exclusive-rename.d.ts +0 -2
- package/dist/native/exclusive-rename.js +0 -52
- package/dist/release/retention-dry-run.d.ts +0 -46
- package/dist/release/retention-dry-run.js +0 -94
- package/dist/updates/update-exclusive-rename.d.ts +0 -3
- package/dist/updates/update-exclusive-rename.js +0 -5
|
@@ -8,9 +8,8 @@ async function downloadVerifiedRelease(options) {
|
|
|
8
8
|
const { descriptor, maxBytes } = options;
|
|
9
9
|
const timeout = options.timeoutMs ?? 12e4;
|
|
10
10
|
if (!isVerifiedRelease(descriptor) || !Number.isSafeInteger(maxBytes) || maxBytes < 1 || descriptor.asset.size > maxBytes || !Number.isSafeInteger(timeout) || timeout < 1 || timeout > 6e5) throw new Error("Invalid verified download request");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const signal = options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
11
|
+
const deadline = AbortSignal.timeout(timeout);
|
|
12
|
+
const signal = options.signal ? AbortSignal.any([deadline, options.signal]) : deadline;
|
|
14
13
|
const fetcher = options.fetch ?? globalThis.fetch;
|
|
15
14
|
let temporary;
|
|
16
15
|
let response;
|
|
@@ -83,7 +82,6 @@ async function downloadVerifiedRelease(options) {
|
|
|
83
82
|
});
|
|
84
83
|
throw error;
|
|
85
84
|
} finally {
|
|
86
|
-
clearTimeout(timer);
|
|
87
85
|
if (response?.body && !response.bodyUsed && !response.body.locked) try {
|
|
88
86
|
response.body.cancel().catch(() => {});
|
|
89
87
|
} catch {}
|
|
@@ -5,8 +5,8 @@ import { safeArchivePath } from "../installer/archive-entry.js";
|
|
|
5
5
|
import { isLinuxCefLibraryLink } from "../native/linux-cef-links.js";
|
|
6
6
|
import { lstat, mkdir, mkdtemp, open, readFile, realpath, rm, symlink } from "node:fs/promises";
|
|
7
7
|
import { isAbsolute, join } from "node:path";
|
|
8
|
-
import { constants as constants$1 } from "node:fs";
|
|
9
8
|
import { createHash } from "node:crypto";
|
|
9
|
+
import { constants as constants$1 } from "node:fs";
|
|
10
10
|
import { x } from "tar";
|
|
11
11
|
import { createZstdDecompress } from "node:zlib";
|
|
12
12
|
import { Transform } from "node:stream";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { isUuid } from "../app/value-guards.js";
|
|
2
|
+
import { isCanonicalPath } from "../native/canonical-path.js";
|
|
1
3
|
import { tryAcquireNativeFileLock } from "./native-file-lock.js";
|
|
2
|
-
import { basename, dirname,
|
|
4
|
+
import { basename, dirname, join } from "node:path";
|
|
3
5
|
// src/updates/update-generation-lease.ts
|
|
4
|
-
var UUID = /^[0-9a-f]{8}-[0-9a-f-]{27}$/i;
|
|
5
6
|
/** A persistent lock outside the retained tree; never remove or replace it. */
|
|
6
7
|
function updateGenerationLeasePath(target, generation) {
|
|
7
|
-
if (
|
|
8
|
+
if (!isCanonicalPath(target) || typeof generation !== "string" || !isUuid(generation)) throw new Error("Invalid update generation lease identity");
|
|
8
9
|
return join(dirname(target), `.${basename(target)}.framework-generation-${generation.toLowerCase()}.lock`);
|
|
9
10
|
}
|
|
10
11
|
/** Shared readers and future exclusive cleanup must use this same persistent lock. */
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { isCanonicalPath } from "../native/canonical-path.js";
|
|
1
2
|
import { assertPortableAppName } from "../installer/installer-layout.js";
|
|
2
3
|
import { isVerifiedReleaseForTrust } from "./signed-release.js";
|
|
3
4
|
import { versionLessThan } from "./release-version.js";
|
|
4
|
-
import { basename
|
|
5
|
+
import { basename } from "node:path";
|
|
5
6
|
// src/updates/update-handoff-plan.ts
|
|
6
7
|
/** Validate an explicitly approved update and its intended installation. This plan does not move files or launch a helper. */
|
|
7
8
|
function planUpdateHandoff(options) {
|
|
@@ -15,7 +16,7 @@ function planUpdateHandoff(options) {
|
|
|
15
16
|
};
|
|
16
17
|
if (!expected[platform] || !["native", "cef"].includes(renderer) || !isVerifiedReleaseForTrust(descriptor, trust) || descriptor.platform !== expected[platform][0] || descriptor.arch !== expected[platform][1] || approved !== true || approvedVersion !== descriptor.version || typeof currentVersion !== "string" || currentVersion.length > 64 || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(currentVersion) || !versionLessThan(currentVersion, descriptor.version)) throw new Error("Invalid approved update");
|
|
17
18
|
const name = platform === "macos-arm64" ? `${appName}.app` : "app";
|
|
18
|
-
if (
|
|
19
|
+
if (!isCanonicalPath(target) || basename(target) !== name) throw new Error("Invalid update target");
|
|
19
20
|
return Object.freeze({
|
|
20
21
|
target,
|
|
21
22
|
appName,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { errorCode, isUuid } from "../app/value-guards.js";
|
|
2
|
+
import { isCanonicalPath } from "../native/canonical-path.js";
|
|
1
3
|
import { acquireUpdateLock, readUpdateStageState, writeUpdateStageState, writeUpdateStageStateDurably } from "./update-state-store.js";
|
|
2
4
|
import { readUpdateTreeDigest, readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeDigest, sameUpdateTreeIdentity, swapUpdateTreeWhileLocked, syncUpdateTree, syncUpdateTreeParent, updateStagingFor } from "./update-swap.js";
|
|
3
5
|
import { publishExclusiveUpdateMarker, publishExclusiveUpdateMarkerSync, readUpdateMarker } from "./update-marker.js";
|
|
@@ -5,7 +7,7 @@ import { launchInstalledApp } from "./update-launch.js";
|
|
|
5
7
|
import { UpdateProcessFenceCancelledError, waitForUpdateProcesses } from "./update-process-fence.js";
|
|
6
8
|
import { cancelUpdateLaunchGateBeforeTransition, publishUpdateLaunchGate, tryAcquireUpdateHelperLiveness, waitForUpdateLaunchGateWriter } from "./update-launch-gate.js";
|
|
7
9
|
import { lstat, open, realpath } from "node:fs/promises";
|
|
8
|
-
import {
|
|
10
|
+
import { join } from "node:path";
|
|
9
11
|
import { constants as constants$1 } from "node:fs";
|
|
10
12
|
// src/updates/update-helper.ts
|
|
11
13
|
/** Return whether a staging directory contains artifacts from a helper handoff. */
|
|
@@ -21,19 +23,19 @@ async function hasUpdateHelperArtifacts(staging) {
|
|
|
21
23
|
await lstat(join(staging, name));
|
|
22
24
|
return true;
|
|
23
25
|
} catch (error) {
|
|
24
|
-
if (error
|
|
26
|
+
if (errorCode(error) !== "ENOENT") throw error;
|
|
25
27
|
}
|
|
26
28
|
return false;
|
|
27
29
|
}
|
|
28
30
|
/** Validate a helper request's shape. */
|
|
29
31
|
function parseUpdateHelperRequest(value) {
|
|
30
32
|
const data = value;
|
|
31
|
-
if (typeof value !== "object" || value === null || Array.isArray(value) || data.schema !== 1 && data.schema !== 2 && data.schema !== 3 ||
|
|
33
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || data.schema !== 1 && data.schema !== 2 && data.schema !== 3 || !isCanonicalPath(data.target) || ![
|
|
32
34
|
"macos-arm64",
|
|
33
35
|
"windows-x64",
|
|
34
36
|
"linux-x64",
|
|
35
37
|
"linux-arm64"
|
|
36
|
-
].includes(data.platform) || typeof data.version !== "string" || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(data.version) || !Array.isArray(data.processes) || data.schema === 2 && (typeof data.generation !== "string" || !/^[0-9a-f-]{36}$/i.test(data.generation) || data.helperOwner !== void 0 && (typeof data.helperOwner !== "string" || !/^[0-9a-f-]{36}$/i.test(data.helperOwner))) || data.schema === 3 && (typeof data.generation !== "string" ||
|
|
38
|
+
].includes(data.platform) || typeof data.version !== "string" || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(data.version) || !Array.isArray(data.processes) || data.schema === 2 && (typeof data.generation !== "string" || !/^[0-9a-f-]{36}$/i.test(data.generation) || data.helperOwner !== void 0 && (typeof data.helperOwner !== "string" || !/^[0-9a-f-]{36}$/i.test(data.helperOwner))) || data.schema === 3 && (typeof data.generation !== "string" || !isUuid(data.generation) || typeof data.helperOwner !== "string" || !isUuid(data.helperOwner)) || !Number.isSafeInteger(data.processTimeoutMs) || data.processTimeoutMs < 1 || data.processTimeoutMs > 12e4) throw new Error("Invalid update helper request");
|
|
37
39
|
return Object.freeze(data);
|
|
38
40
|
}
|
|
39
41
|
async function readRequest(staging) {
|
|
@@ -69,7 +71,7 @@ async function updatePathExists(path) {
|
|
|
69
71
|
await lstat(path);
|
|
70
72
|
return true;
|
|
71
73
|
} catch (error) {
|
|
72
|
-
if (error
|
|
74
|
+
if (errorCode(error) === "ENOENT") return false;
|
|
73
75
|
throw error;
|
|
74
76
|
}
|
|
75
77
|
}
|
|
@@ -80,7 +82,7 @@ async function updatePathExists(path) {
|
|
|
80
82
|
*/
|
|
81
83
|
async function runUpdateHelper(options) {
|
|
82
84
|
if (options.target !== void 0 || options.generation !== void 0 || options.helperOwner !== void 0) {
|
|
83
|
-
if (
|
|
85
|
+
if (!isCanonicalPath(options.target) || !isCanonicalPath(options.staging) || updateStagingFor(options.target) !== options.staging || typeof options.generation !== "string" || !isUuid(options.generation) || typeof options.helperOwner !== "string" || !isUuid(options.helperOwner)) throw new Error("Invalid update helper invocation");
|
|
84
86
|
const liveness = await tryAcquireUpdateHelperLiveness(options.target);
|
|
85
87
|
if (!liveness) throw new Error("Update helper liveness is already owned");
|
|
86
88
|
try {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { isCanonicalPath } from "../native/canonical-path.js";
|
|
1
2
|
import { tryAcquireNativeFileLock } from "./native-file-lock.js";
|
|
2
|
-
import { basename, dirname,
|
|
3
|
+
import { basename, dirname, join } from "node:path";
|
|
3
4
|
// src/updates/update-instance-lease.ts
|
|
4
5
|
/** Stable app-lifetime path, separate from the updater transition lock. */
|
|
5
6
|
function updateInstanceLeasePath(target) {
|
|
6
|
-
if (
|
|
7
|
+
if (!isCanonicalPath(target)) throw new Error("Invalid update instance lease target");
|
|
7
8
|
return join(dirname(target), "." + basename(target) + ".framework-instance-lease.lock");
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { errorCode, isUuid } from "../app/value-guards.js";
|
|
2
|
+
import { isCanonicalPath } from "../native/canonical-path.js";
|
|
3
|
+
import { readSmallStateFile } from "./stable-file.js";
|
|
1
4
|
import { tryAcquireNativeFileLock } from "./native-file-lock.js";
|
|
2
5
|
import { tryAcquireUpdateLock } from "./update-lock.js";
|
|
3
6
|
import { acquireUpdateLock } from "./update-state-store.js";
|
|
4
7
|
import { publishExclusiveUpdateMarker, readUpdateMarker } from "./update-marker.js";
|
|
5
8
|
import { tryAcquireUpdateInstanceLease } from "./update-instance-lease.js";
|
|
6
|
-
import {
|
|
7
|
-
import { basename, dirname,
|
|
8
|
-
import { constants as constants$1 } from "node:fs";
|
|
9
|
+
import { open, rename, unlink } from "node:fs/promises";
|
|
10
|
+
import { basename, dirname, join } from "node:path";
|
|
9
11
|
import { randomUUID } from "node:crypto";
|
|
12
|
+
import { constants as constants$1 } from "node:fs";
|
|
10
13
|
// src/updates/update-launch-gate.ts
|
|
11
14
|
/**
|
|
12
15
|
* Publish the schema-3 helper's cancellation request under the same
|
|
@@ -15,7 +18,7 @@ import { randomUUID } from "node:crypto";
|
|
|
15
18
|
*/
|
|
16
19
|
async function publishUpdateLaunchGateCancellationRequest(target, staging, generation, helperOwner) {
|
|
17
20
|
validateTarget(target);
|
|
18
|
-
if (staging !== join(dirname(target), `.${basename(target)}.framework-update`) || !
|
|
21
|
+
if (staging !== join(dirname(target), `.${basename(target)}.framework-update`) || !isUuid(generation) || !isUuid(helperOwner)) throw new Error("Invalid update launch gate cancellation owner");
|
|
19
22
|
const coordinator = await acquireUpdateLock(target);
|
|
20
23
|
try {
|
|
21
24
|
try {
|
|
@@ -26,7 +29,7 @@ async function publishUpdateLaunchGateCancellationRequest(target, staging, gener
|
|
|
26
29
|
});
|
|
27
30
|
return true;
|
|
28
31
|
} catch (error) {
|
|
29
|
-
if (error
|
|
32
|
+
if (errorCode(error) !== "EEXIST") throw error;
|
|
30
33
|
const existing = await readUpdateMarker(staging, "cancel.json").catch(() => void 0);
|
|
31
34
|
return existing?.schema === 1 && existing.generation === generation && existing.helperOwner === helperOwner;
|
|
32
35
|
}
|
|
@@ -73,11 +76,10 @@ var UpdateLaunchHandoffCleanupError = class extends Error {
|
|
|
73
76
|
this.released = true;
|
|
74
77
|
}
|
|
75
78
|
};
|
|
76
|
-
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
77
79
|
var VERSION = /^\d+\.\d+\.\d+(?:-dev\.\d+)?$/;
|
|
78
80
|
var MAX_GATE_BYTES = 1024;
|
|
79
81
|
function validateTarget(target) {
|
|
80
|
-
if (
|
|
82
|
+
if (!isCanonicalPath(target)) throw new Error("Invalid update launch gate target");
|
|
81
83
|
}
|
|
82
84
|
async function syncDirectory(directoryPath) {
|
|
83
85
|
const directory = await open(directoryPath, constants$1.O_RDONLY);
|
|
@@ -178,7 +180,7 @@ function helperLeaseState(lease, target, owner) {
|
|
|
178
180
|
return state;
|
|
179
181
|
}
|
|
180
182
|
function validateGateInput(gate) {
|
|
181
|
-
if (typeof gate !== "object" || gate === null || Object.keys(gate).length !== 4 || gate.schema !== 1 || typeof gate.generation !== "string" || !
|
|
183
|
+
if (typeof gate !== "object" || gate === null || Object.keys(gate).length !== 4 || gate.schema !== 1 || typeof gate.generation !== "string" || !isUuid(gate.generation) || typeof gate.version !== "string" || !VERSION.test(gate.version) || typeof gate.owner !== "string" || !isUuid(gate.owner)) throw new Error("Invalid update launch gate");
|
|
182
184
|
return Object.freeze({
|
|
183
185
|
schema: 1,
|
|
184
186
|
generation: gate.generation,
|
|
@@ -199,23 +201,8 @@ function parseGate(value) {
|
|
|
199
201
|
}
|
|
200
202
|
/** Read the atomic gate record. Missing means open; malformed or non-file state fails closed. */
|
|
201
203
|
async function readUpdateLaunchGate(target) {
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
try {
|
|
205
|
-
info = await lstat(path);
|
|
206
|
-
} catch (error) {
|
|
207
|
-
if (error.code === "ENOENT") return void 0;
|
|
208
|
-
throw error;
|
|
209
|
-
}
|
|
210
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > MAX_GATE_BYTES) throw new Error("Invalid update launch gate");
|
|
211
|
-
const file = await open(path, constants$1.O_RDONLY | (constants$1.O_NOFOLLOW ?? 0));
|
|
212
|
-
try {
|
|
213
|
-
const opened = await file.stat();
|
|
214
|
-
if (!opened.isFile() || opened.size < 1 || opened.size > MAX_GATE_BYTES) throw new Error("Invalid update launch gate");
|
|
215
|
-
return parseGate(JSON.parse(await file.readFile("utf8")));
|
|
216
|
-
} finally {
|
|
217
|
-
await file.close();
|
|
218
|
-
}
|
|
204
|
+
const text = await readSmallStateFile(updateLaunchGatePath(target), MAX_GATE_BYTES, "Invalid update launch gate");
|
|
205
|
+
return text === void 0 ? void 0 : parseGate(JSON.parse(text));
|
|
219
206
|
}
|
|
220
207
|
function sameGate(left, right) {
|
|
221
208
|
return left?.schema === right.schema && left.generation === right.generation && left.version === right.version && left.owner === right.owner;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { isCanonicalPath } from "../native/canonical-path.js";
|
|
1
2
|
import { INHERITED_LAUNCH_LEASE_ENV } from "./launch-environment.js";
|
|
2
|
-
import { dirname,
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
3
4
|
import { spawn } from "node:child_process";
|
|
4
5
|
// src/updates/update-launch.ts
|
|
5
6
|
/** The Electrobun launcher inside an installed app tree. */
|
|
6
7
|
function updateLauncherPath(platform, target) {
|
|
7
|
-
if (
|
|
8
|
+
if (!isCanonicalPath(target)) throw new Error("Invalid update target");
|
|
8
9
|
if (platform === "macos-arm64") return join(target, "Contents", "MacOS", "launcher");
|
|
9
10
|
if (platform === "windows-x64") return join(target, "bin", "launcher.exe");
|
|
10
11
|
if (platform === "linux-x64" || platform === "linux-arm64") return join(target, "bin", "launcher");
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { isCanonicalPath } from "../native/canonical-path.js";
|
|
1
2
|
import { tryAcquireNativeFileLock } from "./native-file-lock.js";
|
|
2
|
-
import { basename, dirname,
|
|
3
|
+
import { basename, dirname, join } from "node:path";
|
|
3
4
|
// src/updates/update-lock.ts
|
|
4
5
|
/** Stable transition lock path. The file must never be removed or replaced. */
|
|
5
6
|
function updateLockPath(target) {
|
|
6
|
-
if (
|
|
7
|
+
if (!isCanonicalPath(target)) throw new Error("Invalid update lock target");
|
|
7
8
|
return join(dirname(target), `.${basename(target)}.framework-update.lock`);
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { errorCode } from "../app/value-guards.js";
|
|
1
2
|
import { link, open, unlink, writeFile } from "node:fs/promises";
|
|
2
3
|
import { join } from "node:path";
|
|
3
|
-
import { closeSync, constants as constants$1, linkSync, openSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { closeSync, constants as constants$1, linkSync, openSync, unlinkSync, writeFileSync } from "node:fs";
|
|
5
6
|
// src/updates/update-marker.ts
|
|
6
7
|
function isUpdateHelperReadyMarker(value, generation, helperOwner) {
|
|
7
8
|
return value?.schema === 1 && value.generation === generation && value.helperOwner === helperOwner;
|
|
@@ -46,7 +47,7 @@ async function readUpdateMarker(staging, name) {
|
|
|
46
47
|
try {
|
|
47
48
|
file = await open(path, constants$1.O_RDONLY | (constants$1.O_NOFOLLOW ?? 0));
|
|
48
49
|
} catch (error) {
|
|
49
|
-
if (error
|
|
50
|
+
if (errorCode(error) === "ENOENT") return void 0;
|
|
50
51
|
throw error;
|
|
51
52
|
}
|
|
52
53
|
try {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { errorCode } from "../app/value-guards.js";
|
|
1
2
|
import { linuxProcessIsExited } from "./linux-process-state.js";
|
|
3
|
+
import { windowsProcessImage } from "../native/windows-process.js";
|
|
2
4
|
import { readFile, realpath } from "node:fs/promises";
|
|
3
5
|
import { isAbsolute } from "node:path";
|
|
4
6
|
import { FFIType, dlopen, ptr } from "bun:ffi";
|
|
@@ -14,7 +16,7 @@ function isProcessRunning(pid) {
|
|
|
14
16
|
process.kill(pid, 0);
|
|
15
17
|
return true;
|
|
16
18
|
} catch (error) {
|
|
17
|
-
if (error
|
|
19
|
+
if (errorCode(error) === "ESRCH") return false;
|
|
18
20
|
throw new Error("Cannot inspect update process", { cause: error });
|
|
19
21
|
}
|
|
20
22
|
}
|
|
@@ -26,7 +28,7 @@ async function hasVerifiedProcessExited(pid) {
|
|
|
26
28
|
try {
|
|
27
29
|
stat = await readFile(`/proc/${pid}/stat`, "utf8");
|
|
28
30
|
} catch (error) {
|
|
29
|
-
const code = error
|
|
31
|
+
const code = errorCode(error);
|
|
30
32
|
if ((code === "ENOENT" || code === "ESRCH") && !isProcessRunning(pid)) return true;
|
|
31
33
|
throw new Error("Cannot inspect update process", { cause: error });
|
|
32
34
|
}
|
|
@@ -57,45 +59,14 @@ async function executable(pid) {
|
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
if (process.platform === "win32") {
|
|
60
|
-
|
|
61
|
-
OpenProcess: {
|
|
62
|
-
args: [
|
|
63
|
-
FFIType.u32,
|
|
64
|
-
FFIType.i32,
|
|
65
|
-
FFIType.u32
|
|
66
|
-
],
|
|
67
|
-
returns: FFIType.ptr
|
|
68
|
-
},
|
|
69
|
-
QueryFullProcessImageNameW: {
|
|
70
|
-
args: [
|
|
71
|
-
FFIType.ptr,
|
|
72
|
-
FFIType.u32,
|
|
73
|
-
FFIType.ptr,
|
|
74
|
-
FFIType.ptr
|
|
75
|
-
],
|
|
76
|
-
returns: FFIType.i32
|
|
77
|
-
},
|
|
78
|
-
CloseHandle: {
|
|
79
|
-
args: [FFIType.ptr],
|
|
80
|
-
returns: FFIType.i32
|
|
81
|
-
}
|
|
82
|
-
});
|
|
62
|
+
let image;
|
|
83
63
|
try {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const buffer = Buffer.alloc(65536), length = Buffer.alloc(4);
|
|
88
|
-
length.writeUInt32LE(32768);
|
|
89
|
-
if (!library.symbols.QueryFullProcessImageNameW(handle, 0, ptr(buffer), ptr(length))) throw new Error("Cannot inspect update process");
|
|
90
|
-
const count = length.readUInt32LE();
|
|
91
|
-
if (!count || count >= 32768) throw new Error("Invalid update process path");
|
|
92
|
-
return await realpath(buffer.subarray(0, count * 2).toString("utf16le"));
|
|
93
|
-
} finally {
|
|
94
|
-
library.symbols.CloseHandle(handle);
|
|
95
|
-
}
|
|
96
|
-
} finally {
|
|
97
|
-
library.close();
|
|
64
|
+
image = windowsProcessImage(pid, { requireRunning: false });
|
|
65
|
+
} catch (error) {
|
|
66
|
+
throw new Error("Cannot inspect update process", { cause: error });
|
|
98
67
|
}
|
|
68
|
+
if (image === "missing") throw new Error("Cannot open update process");
|
|
69
|
+
return realpath(image);
|
|
99
70
|
}
|
|
100
71
|
throw new Error("Unsupported update process platform");
|
|
101
72
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { errorCode } from "../app/value-guards.js";
|
|
1
2
|
// src/updates/update-process-liveness.ts
|
|
2
3
|
/** Only ESRCH proves a recorded process is absent; inspection errors fail closed. */
|
|
3
4
|
function updateProcessMayBeAlive(pid) {
|
|
@@ -5,7 +6,7 @@ function updateProcessMayBeAlive(pid) {
|
|
|
5
6
|
process.kill(pid, 0);
|
|
6
7
|
return true;
|
|
7
8
|
} catch (error) {
|
|
8
|
-
return error
|
|
9
|
+
return errorCode(error) !== "ESRCH";
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
12
|
export { updateProcessMayBeAlive };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { UUID_SOURCE, errorCode, isUuid } from "../app/value-guards.js";
|
|
2
|
+
import { renameExclusive } from "../native/native-rename.js";
|
|
1
3
|
import { verifyReleaseDescriptor } from "./signed-release.js";
|
|
2
|
-
import { renameUpdateExclusive } from "./update-exclusive-rename.js";
|
|
3
4
|
import { tryAcquireUpdateLock } from "./update-lock.js";
|
|
4
5
|
import { UpdateLockBusyError, acquireUpdateLock, readUpdateStageState, syncUpdateStageDirectory, writeUpdateStageState, writeUpdateStageStateDurably } from "./update-state-store.js";
|
|
5
6
|
import { readUpdateTreeDigest, readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeDigest, sameUpdateTreeIdentity, syncUpdateTreeParent, updateStagingFor } from "./update-swap.js";
|
|
@@ -11,12 +12,12 @@ import { updateProcessMayBeAlive } from "./update-process-liveness.js";
|
|
|
11
12
|
import { acquireRetainedUpdateTrees, acquireRetainedUpdateTreesWhileLocked, reconcileRetirementCleanupMarkerWhileLocked, retireCompletedUpdateWhileLocked } from "./update-retirement.js";
|
|
12
13
|
import { lstat, open, readFile, readdir, realpath, rm, rmdir, unlink } from "node:fs/promises";
|
|
13
14
|
import { join } from "node:path";
|
|
14
|
-
import { constants as constants$1 } from "node:fs";
|
|
15
15
|
import { randomUUID } from "node:crypto";
|
|
16
|
+
import { constants as constants$1 } from "node:fs";
|
|
16
17
|
// src/updates/update-resume.ts
|
|
17
18
|
async function exists(path) {
|
|
18
19
|
return lstat(path).then(() => true, (error) => {
|
|
19
|
-
if (error
|
|
20
|
+
if (errorCode(error) === "ENOENT") return false;
|
|
20
21
|
throw error;
|
|
21
22
|
});
|
|
22
23
|
}
|
|
@@ -81,13 +82,13 @@ async function recoverLegacyHandoff(options) {
|
|
|
81
82
|
if (!targetExists && oldExists) {
|
|
82
83
|
const oldInfo = await lstat(old);
|
|
83
84
|
if (!oldInfo.isDirectory() || oldInfo.isSymbolicLink() || await readUpdateTreeVersion(old) !== currentVersion) return { status: "recovery-required" };
|
|
84
|
-
|
|
85
|
+
renameExclusive(old, target);
|
|
85
86
|
} else if (targetExists && !oldExists) {
|
|
86
87
|
const targetInfo = await lstat(target);
|
|
87
88
|
if (!targetInfo.isDirectory() || targetInfo.isSymbolicLink() || await readUpdateTreeVersion(target) !== currentVersion) return { status: "recovery-required" };
|
|
88
89
|
} else return { status: "recovery-required" };
|
|
89
90
|
const archived = `${staging}.legacy-${randomUUID()}`;
|
|
90
|
-
|
|
91
|
+
renameExclusive(staging, archived);
|
|
91
92
|
return { status: "not-applied" };
|
|
92
93
|
}
|
|
93
94
|
async function resetToStaged(staging, state) {
|
|
@@ -135,7 +136,7 @@ async function reconcileSwap(target, staging, state) {
|
|
|
135
136
|
const [oldInfo, candidateInfo] = await Promise.all([lstat(old), lstat(candidate)]);
|
|
136
137
|
const [oldIdentity, candidateIdentity] = await Promise.all([readUpdateTreeIdentity(old), readUpdateTreeIdentity(candidate)]);
|
|
137
138
|
if (!oldInfo.isDirectory() || oldInfo.isSymbolicLink() || !candidateInfo.isDirectory() || candidateInfo.isSymbolicLink() || !oldIdentity || !candidateIdentity || !sameUpdateTreeIdentity(candidateIdentity, state.candidateTreeIdentity) || sameUpdateTreeIdentity(oldIdentity, candidateIdentity) || state.previousTreeIdentity && !sameUpdateTreeIdentity(oldIdentity, state.previousTreeIdentity) || await readUpdateTreeVersion(old) !== state.previousVersion || await readUpdateTreeVersion(candidate) !== state.version || state.candidateTreeDigest !== void 0 && !sameUpdateTreeDigest(await readTreeDigestForProof(candidate), state.candidateTreeDigest)) return void 0;
|
|
138
|
-
|
|
139
|
+
renameExclusive(old, target);
|
|
139
140
|
return resetToStaged(staging, state);
|
|
140
141
|
} catch {
|
|
141
142
|
return;
|
|
@@ -172,7 +173,7 @@ async function recoverStagedCandidate(options) {
|
|
|
172
173
|
try {
|
|
173
174
|
info = await lstat(candidate);
|
|
174
175
|
} catch (error) {
|
|
175
|
-
if (error
|
|
176
|
+
if (errorCode(error) === "ENOENT") return { status: "recovery-required" };
|
|
176
177
|
throw error;
|
|
177
178
|
}
|
|
178
179
|
if (!info.isDirectory() || info.isSymbolicLink()) return { status: "recovery-required" };
|
|
@@ -330,7 +331,6 @@ async function resumeLocked(options) {
|
|
|
330
331
|
}
|
|
331
332
|
throw new Error("Invalid update staging phase");
|
|
332
333
|
}
|
|
333
|
-
var recoveryUuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
334
334
|
var recoveryStagingEntries = /* @__PURE__ */ new Set([
|
|
335
335
|
"candidate",
|
|
336
336
|
"helper",
|
|
@@ -351,7 +351,7 @@ async function readOptionalRecoveryFile(path, maxBytes) {
|
|
|
351
351
|
try {
|
|
352
352
|
info = await lstat(path);
|
|
353
353
|
} catch (error) {
|
|
354
|
-
if (error
|
|
354
|
+
if (errorCode(error) === "ENOENT") return void 0;
|
|
355
355
|
throw error;
|
|
356
356
|
}
|
|
357
357
|
if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > maxBytes) throw new Error("Invalid schema-3 helper recovery artifact");
|
|
@@ -366,7 +366,7 @@ async function readOptionalRecoveryFile(path, maxBytes) {
|
|
|
366
366
|
}
|
|
367
367
|
async function recoveryInventoryIsKnown(staging, state) {
|
|
368
368
|
const names = await readdir(staging);
|
|
369
|
-
const stateTemporary =
|
|
369
|
+
const stateTemporary = stateTemporaryPattern(state.generation);
|
|
370
370
|
for (const name of names) {
|
|
371
371
|
if (recoveryStagingEntries.has(name)) continue;
|
|
372
372
|
if (!stateTemporary.test(name)) return false;
|
|
@@ -387,9 +387,13 @@ async function recoveryInventoryIsKnown(staging, state) {
|
|
|
387
387
|
}
|
|
388
388
|
return true;
|
|
389
389
|
}
|
|
390
|
+
/** The temporary names `writeUpdateStageState` leaves for one generation's state file. */
|
|
391
|
+
function stateTemporaryPattern(generation) {
|
|
392
|
+
return new RegExp(`^\\.state-${generation}-${UUID_SOURCE}\\.tmp$`, "i");
|
|
393
|
+
}
|
|
390
394
|
async function isCanonicalRecoveryStaging(staging) {
|
|
391
395
|
const info = await lstat(staging).catch((error) => {
|
|
392
|
-
if (error
|
|
396
|
+
if (errorCode(error) === "ENOENT") return void 0;
|
|
393
397
|
throw error;
|
|
394
398
|
});
|
|
395
399
|
return Boolean(info && info.isDirectory() && !info.isSymbolicLink() && await realpath(staging) === staging);
|
|
@@ -403,7 +407,7 @@ async function helperDirectoryIsKnown(staging, state, gate, requestMayBeAbsent)
|
|
|
403
407
|
try {
|
|
404
408
|
entries = await readdir(helper);
|
|
405
409
|
} catch (error) {
|
|
406
|
-
if (error
|
|
410
|
+
if (errorCode(error) === "ENOENT") return requestMayBeAbsent;
|
|
407
411
|
throw error;
|
|
408
412
|
}
|
|
409
413
|
const copiedFiles = /* @__PURE__ */ new Set();
|
|
@@ -416,7 +420,7 @@ async function helperDirectoryIsKnown(staging, state, gate, requestMayBeAbsent)
|
|
|
416
420
|
continue;
|
|
417
421
|
}
|
|
418
422
|
const match = /^\.(helper-ready|cancel\.json|cancel-ack\.json)\.([0-9a-f-]{36})\.tmp$/i.exec(name);
|
|
419
|
-
if (!match || !
|
|
423
|
+
if (!match || !isUuid(match[2])) return false;
|
|
420
424
|
let text;
|
|
421
425
|
try {
|
|
422
426
|
text = await readOptionalRecoveryFile(path, 1024);
|
|
@@ -558,10 +562,10 @@ async function schema3TreeLayout(target, staging, state) {
|
|
|
558
562
|
if (!state.candidateTreeIdentity || !state.candidateTreeDigest || !state.previousTreeIdentity) return void 0;
|
|
559
563
|
const candidate = join(staging, "candidate");
|
|
560
564
|
const [targetInfo, candidateInfo] = await Promise.all([lstat(target).catch((error) => {
|
|
561
|
-
if (error
|
|
565
|
+
if (errorCode(error) === "ENOENT") return void 0;
|
|
562
566
|
throw error;
|
|
563
567
|
}), lstat(candidate).catch((error) => {
|
|
564
|
-
if (error
|
|
568
|
+
if (errorCode(error) === "ENOENT") return void 0;
|
|
565
569
|
throw error;
|
|
566
570
|
})]);
|
|
567
571
|
if (!targetInfo || !targetInfo.isDirectory() || targetInfo.isSymbolicLink() || !candidateInfo || !candidateInfo.isDirectory() || candidateInfo.isSymbolicLink()) return void 0;
|
|
@@ -581,7 +585,7 @@ function schema3JournalMatchesGate(state, gate) {
|
|
|
581
585
|
"swapping",
|
|
582
586
|
"completed",
|
|
583
587
|
"staged"
|
|
584
|
-
].includes(state.phase) && state.generation === gate.generation && state.version === gate.version && state.launchGateOwner === gate.owner && typeof state.helperOwner === "string" &&
|
|
588
|
+
].includes(state.phase) && state.generation === gate.generation && state.version === gate.version && state.launchGateOwner === gate.owner && typeof state.helperOwner === "string" && isUuid(state.helperOwner) && Number.isSafeInteger(state.helperPid) && (state.helperPid ?? 0) >= 2 && isUuid(state.generation) && state.version !== state.previousVersion && state.candidateTreeIdentity !== void 0 && state.candidateTreeDigest !== void 0 && state.previousTreeIdentity !== void 0);
|
|
585
589
|
}
|
|
586
590
|
async function removeSchema3HelperArtifacts(staging) {
|
|
587
591
|
for (const name of [
|
|
@@ -593,7 +597,7 @@ async function removeSchema3HelperArtifacts(staging) {
|
|
|
593
597
|
]) await rm(join(staging, name), { force: true });
|
|
594
598
|
const state = await readUpdateStageState(staging);
|
|
595
599
|
if (!state) throw new Error("Schema-3 recovery journal disappeared");
|
|
596
|
-
const stateTemporary =
|
|
600
|
+
const stateTemporary = stateTemporaryPattern(state.generation);
|
|
597
601
|
for (const name of await readdir(staging)) {
|
|
598
602
|
if (!stateTemporary.test(name)) continue;
|
|
599
603
|
const path = join(staging, name);
|
|
@@ -608,7 +612,7 @@ async function removeSchema3HelperArtifacts(staging) {
|
|
|
608
612
|
}
|
|
609
613
|
async function finalizationTemporaries(staging, state) {
|
|
610
614
|
const names = await readdir(staging);
|
|
611
|
-
const stateTemporary =
|
|
615
|
+
const stateTemporary = stateTemporaryPattern(state.generation);
|
|
612
616
|
const temporaryNames = [];
|
|
613
617
|
for (const name of names) {
|
|
614
618
|
if (name === "candidate" || name === "state.json") {
|
|
@@ -637,10 +641,10 @@ async function ownerlessStagedTreeMatches(target, staging, state) {
|
|
|
637
641
|
if (!state.candidateTreeIdentity || !state.candidateTreeDigest) return false;
|
|
638
642
|
const candidate = join(staging, "candidate");
|
|
639
643
|
const [targetInfo, candidateInfo] = await Promise.all([lstat(target).catch((error) => {
|
|
640
|
-
if (error
|
|
644
|
+
if (errorCode(error) === "ENOENT") return void 0;
|
|
641
645
|
throw error;
|
|
642
646
|
}), lstat(candidate).catch((error) => {
|
|
643
|
-
if (error
|
|
647
|
+
if (errorCode(error) === "ENOENT") return void 0;
|
|
644
648
|
throw error;
|
|
645
649
|
})]);
|
|
646
650
|
if (!targetInfo || !targetInfo.isDirectory() || targetInfo.isSymbolicLink() || !candidateInfo || !candidateInfo.isDirectory() || candidateInfo.isSymbolicLink()) return false;
|
|
@@ -703,7 +707,7 @@ async function finalizeClearedSchema3StagedOwner(target, staging, trust) {
|
|
|
703
707
|
if (!helper) return "helper-live";
|
|
704
708
|
await syncUpdateTreeParent(target);
|
|
705
709
|
if (!await lstat(staging).catch((error) => {
|
|
706
|
-
if (error
|
|
710
|
+
if (errorCode(error) === "ENOENT") return void 0;
|
|
707
711
|
throw error;
|
|
708
712
|
})) return "absent";
|
|
709
713
|
if (!await isCanonicalRecoveryStaging(staging)) return "unreconciled";
|
|
@@ -722,7 +726,7 @@ async function finalizeClearedSchema3StagedOwner(target, staging, trust) {
|
|
|
722
726
|
await syncUpdateStageDirectory(staging);
|
|
723
727
|
return "absent";
|
|
724
728
|
}
|
|
725
|
-
if (!
|
|
729
|
+
if (!isUuid(state.generation) || !isUuid(state.launchGateOwner) || !isUuid(state.helperOwner ?? "") || !Number.isSafeInteger(state.helperPid) || (state.helperPid ?? 0) < 2) return "unreconciled";
|
|
726
730
|
const verified = state.signedRelease ? verifyReleaseDescriptor(state.signedRelease, trust) : { ok: false };
|
|
727
731
|
if (!verified.ok || verified.descriptor.version !== state.version) return "unreconciled";
|
|
728
732
|
const temporaries = await finalizationTemporaries(staging, state);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { errorCode } from "../app/value-guards.js";
|
|
2
|
+
import { isCanonicalPath } from "../native/canonical-path.js";
|
|
1
3
|
import { link, lstat, open, unlink, writeFile } from "node:fs/promises";
|
|
2
|
-
import { basename, dirname,
|
|
3
|
-
import { constants as constants$1 } from "node:fs";
|
|
4
|
+
import { basename, dirname, join } from "node:path";
|
|
4
5
|
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { constants as constants$1 } from "node:fs";
|
|
5
7
|
// src/updates/update-retention-marker.ts
|
|
6
8
|
/** Compare all fields that bind an intent to its retained and installed trees. */
|
|
7
9
|
function sameRetentionIntent(left, right) {
|
|
@@ -20,7 +22,7 @@ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]
|
|
|
20
22
|
var IDENTITY_COMPONENT = /^[1-9]\d{0,19}$/;
|
|
21
23
|
var MAX_MARKER_BYTES = 2048;
|
|
22
24
|
function assertCanonicalTarget(target) {
|
|
23
|
-
if (
|
|
25
|
+
if (!isCanonicalPath(target)) throw new Error("Invalid update retention target");
|
|
24
26
|
}
|
|
25
27
|
function assertGeneration(generation) {
|
|
26
28
|
if (typeof generation !== "string" || !UUID.test(generation)) throw new Error("Invalid update retention generation");
|
|
@@ -133,7 +135,7 @@ async function readUpdateRetentionIntentFile(path, target, generation) {
|
|
|
133
135
|
try {
|
|
134
136
|
pathInfo = await lstat(path, { bigint: true });
|
|
135
137
|
} catch (error) {
|
|
136
|
-
if (error
|
|
138
|
+
if (errorCode(error) === "ENOENT") return void 0;
|
|
137
139
|
throw error;
|
|
138
140
|
}
|
|
139
141
|
if (!pathInfo.isFile() || pathInfo.isSymbolicLink() || pathInfo.size < 1n || pathInfo.size > BigInt(MAX_MARKER_BYTES)) throw new Error("Invalid update retention intent file");
|
|
@@ -141,7 +143,7 @@ async function readUpdateRetentionIntentFile(path, target, generation) {
|
|
|
141
143
|
try {
|
|
142
144
|
file = await open(path, constants$1.O_RDONLY | (constants$1.O_NOFOLLOW ?? 0) | (constants$1.O_NONBLOCK ?? 0));
|
|
143
145
|
} catch (error) {
|
|
144
|
-
if (error
|
|
146
|
+
if (errorCode(error) === "ENOENT") throw new Error("Update retention intent disappeared during inspection", { cause: error });
|
|
145
147
|
throw error;
|
|
146
148
|
}
|
|
147
149
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { isUuid } from "../app/value-guards.js";
|
|
1
2
|
// src/updates/update-retention-plan.ts
|
|
2
|
-
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
3
3
|
/** Canonical key for validated device/inode pairs used in retention inventories. */
|
|
4
4
|
function retentionIdentityKey(identity) {
|
|
5
5
|
if (!identity || typeof identity.device !== "string" || !/^[1-9]\d{0,19}$/.test(identity.device) || typeof identity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(identity.inode)) return void 0;
|
|
@@ -25,7 +25,7 @@ function planUpdateRetention(current, generations) {
|
|
|
25
25
|
const seenPrevious = /* @__PURE__ */ new Set();
|
|
26
26
|
const seenGenerations = /* @__PURE__ */ new Set();
|
|
27
27
|
for (const item of generations) {
|
|
28
|
-
if (!item || !
|
|
28
|
+
if (!item || !isUuid(item.generation) || typeof item.healthy !== "boolean") return fail;
|
|
29
29
|
const installed = retentionIdentityKey(item.installed);
|
|
30
30
|
const previous = retentionIdentityKey(item.previous);
|
|
31
31
|
if (!installed || !previous || installed === previous || byInstalled.has(installed) || seenPrevious.has(previous) || seenGenerations.has(item.generation.toLowerCase())) return fail;
|