@adea-ai/app-framework 0.36.1 → 0.37.1
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 +2 -0
- package/dist/appearance/appearance-host.js +2 -1
- package/dist/appearance/custom-theme-import.js +3 -1
- package/dist/appearance/custom-theme-library.d.ts +6 -185
- package/dist/appearance/custom-theme-library.js +3 -621
- package/dist/appearance/theme-library-mutation.d.ts +42 -0
- package/dist/appearance/theme-library-mutation.js +172 -0
- package/dist/appearance/theme-library-schema.d.ts +108 -0
- package/dist/appearance/theme-library-schema.js +189 -0
- package/dist/appearance/theme-library-store.d.ts +61 -0
- package/dist/appearance/theme-library-store.js +268 -0
- package/dist/appearance/theme-record-adapter.js +3 -1
- package/dist/appearance/theme-registry.js +2 -1
- package/dist/appearance/window-surface.d.ts +19 -0
- package/dist/appearance/window-surface.js +68 -1
- package/dist/cli/update-helper-cli.js +1 -1
- package/dist/cli/windows-installer-build-cli.d.ts +2 -0
- package/dist/cli/windows-installer-build-cli.js +14 -0
- package/dist/desktop/desktop-client.d.ts +1 -1
- package/dist/framework-source.json +1 -1
- package/dist/installer/installed-payload.js +2 -2
- package/dist/installer/{installer-archive.js → installer-archive-members.js} +2 -2
- package/dist/installer/installer-extraction.js +2 -2
- package/dist/installer/installer-fetch-guard.d.ts +1 -1
- package/dist/installer/installer-identity.js +2 -2
- package/dist/installer/installer-observation.d.ts +1 -1
- package/dist/installer/installer-observation.js +2 -2
- package/dist/installer/installer-upgrade-command.d.ts +2 -2
- package/dist/installer/installer-upgrade-command.js +5 -5
- package/dist/installer/linux-process-group.js +1 -1
- package/dist/installer/upgrade-asset-download.d.ts +1 -1
- package/dist/installer/upgrade-asset-download.js +2 -2
- package/dist/native/installer-archive.d.ts +42 -0
- package/dist/native/installer-archive.js +172 -0
- package/dist/native/posix-tree-removal.d.ts +1 -1
- package/dist/native/window-surface-store.d.ts +16 -0
- package/dist/native/window-surface-store.js +69 -0
- package/dist/native/windows-extractor-build.d.ts +95 -0
- package/dist/native/windows-extractor-build.js +326 -0
- package/dist/release/feed-release-cut.d.ts +1 -1
- package/dist/release/feed-state.d.ts +2 -2
- package/dist/release/feed-state.js +3 -3
- package/dist/release/github-release-cut.js +1 -1
- package/dist/release/github-release-promotion.js +1 -1
- package/dist/release/github-release-publisher.js +1 -1
- package/dist/release/github-release-qualification.js +1 -1
- package/dist/release/local-release.d.ts +2 -2
- package/dist/release/local-release.js +3 -3
- package/dist/release/release-artifact.d.ts +1 -1
- package/dist/release/release-artifact.js +2 -2
- package/dist/release/release-assets-plan.js +1 -1
- package/dist/release/release-config.d.ts +1 -1
- package/dist/release/release-config.js +1 -1
- package/dist/release/release-descriptor-staging.js +3 -3
- package/dist/release/release-finalize.js +1 -1
- package/dist/release/release-promotion.js +1 -1
- package/dist/release/release-publication.d.ts +1 -1
- package/dist/release/release-publication.js +2 -2
- package/dist/release/release-publish-command.js +2 -2
- package/dist/update-helper.bundle.js +18 -18
- package/dist/updates/channel-update-manager.d.ts +3 -3
- package/dist/updates/channel-update-manager.js +2 -2
- package/dist/updates/desktop-updater.d.ts +10 -83
- package/dist/updates/desktop-updater.js +14 -217
- package/dist/updates/{packaged-release-config.js → feed/packaged-release-config.js} +5 -5
- package/dist/updates/{release-feed.js → feed/release-feed.js} +2 -2
- package/dist/updates/{release-location.js → feed/release-location.js} +2 -2
- package/dist/updates/{release-version.js → feed/release-version.js} +1 -1
- package/dist/updates/{signed-release.js → feed/signed-release.js} +2 -2
- package/dist/updates/{update-discovery.js → feed/update-discovery.js} +1 -1
- package/dist/updates/helper/launch-gate-recovery.d.ts +8 -0
- package/dist/updates/{update-resume.js → helper/launch-gate-recovery.js} +13 -423
- package/dist/updates/helper/resume-staging.d.ts +22 -0
- package/dist/updates/helper/resume-staging.js +180 -0
- package/dist/updates/{update-helper.d.ts → helper/update-helper.d.ts} +1 -1
- package/dist/updates/{update-helper.js → helper/update-helper.js} +9 -9
- package/dist/updates/{update-resume.d.ts → helper/update-resume.d.ts} +4 -10
- package/dist/updates/helper/update-resume.js +252 -0
- package/dist/updates/{update-shutdown.js → helper/update-shutdown.js} +2 -2
- package/dist/updates/{update-arm.d.ts → install/update-arm.d.ts} +2 -2
- package/dist/updates/{update-arm.js → install/update-arm.js} +9 -9
- package/dist/updates/{update-download-cleanup.d.ts → install/update-download-cleanup.d.ts} +1 -1
- package/dist/updates/{update-download-cleanup.js → install/update-download-cleanup.js} +3 -3
- package/dist/updates/{update-download.d.ts → install/update-download.d.ts} +2 -2
- package/dist/updates/{update-download.js → install/update-download.js} +3 -3
- package/dist/updates/{update-extraction.d.ts → install/update-extraction.d.ts} +2 -2
- package/dist/updates/{update-extraction.js → install/update-extraction.js} +6 -6
- package/dist/updates/{update-handoff-plan.d.ts → install/update-handoff-plan.d.ts} +2 -2
- package/dist/updates/{update-handoff-plan.js → install/update-handoff-plan.js} +5 -5
- package/dist/updates/{update-marker.js → install/update-marker.js} +2 -2
- package/dist/updates/{update-swap-stage.d.ts → install/update-swap-stage.d.ts} +2 -2
- package/dist/updates/{update-swap-stage.js → install/update-swap-stage.js} +7 -6
- package/dist/updates/{update-swap.d.ts → install/update-swap.d.ts} +1 -1
- package/dist/updates/{update-swap.js → install/update-swap.js} +5 -5
- package/dist/updates/install-target.d.ts +8 -0
- package/dist/updates/install-target.js +27 -0
- package/dist/updates/{launch-environment.js → launch/launch-environment.js} +1 -1
- package/dist/updates/{packaged-launch-admission.js → launch/packaged-launch-admission.js} +4 -4
- package/dist/updates/{packaged-update-startup.d.ts → launch/packaged-update-startup.d.ts} +3 -3
- package/dist/updates/{packaged-update-startup.js → launch/packaged-update-startup.js} +10 -7
- package/dist/updates/{update-launch-gate.d.ts → launch/update-launch-gate.d.ts} +1 -1
- package/dist/updates/{update-launch-gate.js → launch/update-launch-gate.js} +9 -9
- package/dist/updates/{update-launch.d.ts → launch/update-launch.d.ts} +1 -1
- package/dist/updates/{update-launch.js → launch/update-launch.js} +2 -2
- package/dist/updates/{linux-process-state.js → locks/linux-process-state.js} +1 -1
- package/dist/updates/{native-file-lock.js → locks/native-file-lock.js} +1 -1
- package/dist/updates/{stable-file.js → locks/stable-file.js} +2 -2
- package/dist/updates/{update-download-lock.js → locks/update-download-lock.js} +1 -1
- package/dist/updates/{update-generation-lease.js → locks/update-generation-lease.js} +3 -3
- package/dist/updates/{update-inherited-launch-lease.d.ts → locks/update-inherited-launch-lease.d.ts} +1 -1
- package/dist/updates/{update-inherited-launch-lease.js → locks/update-inherited-launch-lease.js} +2 -2
- package/dist/updates/{update-instance-lease.js → locks/update-instance-lease.js} +2 -2
- package/dist/updates/{update-lock.js → locks/update-lock.js} +2 -2
- package/dist/updates/{update-process-fence.js → locks/update-process-fence.js} +3 -3
- package/dist/updates/{update-process-liveness.js → locks/update-process-liveness.js} +2 -2
- package/dist/updates/retained-client-assets.d.ts +60 -0
- package/dist/updates/retained-client-assets.js +116 -0
- package/dist/updates/retention/retention-cleanup.d.ts +103 -0
- package/dist/updates/retention/retention-cleanup.js +439 -0
- package/dist/updates/retention/retention-prune-progress.d.ts +27 -0
- package/dist/updates/retention/retention-prune-progress.js +203 -0
- package/dist/updates/retention/retirement-inventory.d.ts +93 -0
- package/dist/updates/retention/retirement-inventory.js +373 -0
- package/dist/updates/retention/retirement-records.d.ts +75 -0
- package/dist/updates/retention/retirement-records.js +309 -0
- package/dist/updates/{update-retention-marker.d.ts → retention/update-retention-marker.d.ts} +1 -1
- package/dist/updates/{update-retention-marker.js → retention/update-retention-marker.js} +3 -3
- package/dist/updates/{update-retention-plan.d.ts → retention/update-retention-plan.d.ts} +1 -1
- package/dist/updates/{update-retention-plan.js → retention/update-retention-plan.js} +2 -2
- package/dist/updates/{update-retention-sync.d.ts → retention/update-retention-sync.d.ts} +1 -1
- package/dist/updates/{update-retention-sync.js → retention/update-retention-sync.js} +2 -2
- package/dist/updates/retention/update-retirement.d.ts +26 -0
- package/dist/updates/retention/update-retirement.js +205 -0
- package/dist/updates/update-adapter.js +1 -1
- package/dist/updates/update-channel-store.d.ts +1 -1
- package/dist/updates/update-channel-store.js +2 -2
- package/dist/updates/update-manager.d.ts +4 -4
- package/dist/updates/update-manager.js +5 -5
- package/dist/updates/update-services.d.ts +15 -0
- package/dist/updates/update-services.js +77 -0
- package/dist/updates/update-state-store.d.ts +2 -2
- package/dist/updates/update-state-store.js +2 -2
- package/dist/views/appearance-surface.js +3 -1
- package/package.json +42 -29
- package/src/appearance/custom-theme-library.ts +42 -956
- package/src/appearance/theme-library-mutation.ts +288 -0
- package/src/appearance/theme-library-schema.ts +347 -0
- package/src/appearance/theme-library-store.ts +379 -0
- package/src/appearance/window-surface.ts +91 -5
- package/src/updates/update-adapter.ts +1 -1
- package/templates/application/src/bun/index.ts +15 -0
- package/templates/application/src/web/main.tsx +13 -1
- package/dist/updates/update-retirement.d.ts +0 -205
- package/dist/updates/update-retirement.js +0 -1485
- /package/dist/installer/{installer-archive.d.ts → installer-archive-members.d.ts} +0 -0
- /package/dist/updates/{packaged-release-config.d.ts → feed/packaged-release-config.d.ts} +0 -0
- /package/dist/updates/{release-feed.d.ts → feed/release-feed.d.ts} +0 -0
- /package/dist/updates/{release-location.d.ts → feed/release-location.d.ts} +0 -0
- /package/dist/updates/{release-version.d.ts → feed/release-version.d.ts} +0 -0
- /package/dist/updates/{signed-release.d.ts → feed/signed-release.d.ts} +0 -0
- /package/dist/updates/{update-discovery.d.ts → feed/update-discovery.d.ts} +0 -0
- /package/dist/updates/{update-shutdown.d.ts → helper/update-shutdown.d.ts} +0 -0
- /package/dist/updates/{update-marker.d.ts → install/update-marker.d.ts} +0 -0
- /package/dist/updates/{launch-environment.d.ts → launch/launch-environment.d.ts} +0 -0
- /package/dist/updates/{packaged-launch-admission.d.ts → launch/packaged-launch-admission.d.ts} +0 -0
- /package/dist/updates/{linux-process-state.d.ts → locks/linux-process-state.d.ts} +0 -0
- /package/dist/updates/{native-file-lock.d.ts → locks/native-file-lock.d.ts} +0 -0
- /package/dist/updates/{stable-file.d.ts → locks/stable-file.d.ts} +0 -0
- /package/dist/updates/{update-download-lock.d.ts → locks/update-download-lock.d.ts} +0 -0
- /package/dist/updates/{update-generation-lease.d.ts → locks/update-generation-lease.d.ts} +0 -0
- /package/dist/updates/{update-instance-lease.d.ts → locks/update-instance-lease.d.ts} +0 -0
- /package/dist/updates/{update-lock.d.ts → locks/update-lock.d.ts} +0 -0
- /package/dist/updates/{update-process-fence.d.ts → locks/update-process-fence.d.ts} +0 -0
- /package/dist/updates/{update-process-liveness.d.ts → locks/update-process-liveness.d.ts} +0 -0
- /package/src/updates/{release-version.ts → feed/release-version.ts} +0 -0
|
@@ -1,335 +1,17 @@
|
|
|
1
|
-
import { UUID_SOURCE, errorCode, isUuid } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { acquireRetainedUpdateTrees, acquireRetainedUpdateTreesWhileLocked, reconcileRetirementCleanupMarkerWhileLocked, retireCompletedUpdateWhileLocked } from "./update-retirement.js";
|
|
13
|
-
import { lstat, open, readFile, readdir, realpath, rm, rmdir, unlink } from "node:fs/promises";
|
|
1
|
+
import { UUID_SOURCE, errorCode, isUuid } from "../../app/value-guards.js";
|
|
2
|
+
import { verifyReleaseDescriptor } from "../feed/signed-release.js";
|
|
3
|
+
import { tryAcquireUpdateLock } from "../locks/update-lock.js";
|
|
4
|
+
import { readUpdateStageState, syncUpdateStageDirectory, writeUpdateStageStateDurably } from "../update-state-store.js";
|
|
5
|
+
import { readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeDigest, sameUpdateTreeIdentity, syncUpdateTreeParent, updateStagingFor } from "../install/update-swap.js";
|
|
6
|
+
import { readUpdateMarker } from "../install/update-marker.js";
|
|
7
|
+
import { tryAcquireUpdateInstanceLease } from "../locks/update-instance-lease.js";
|
|
8
|
+
import { readUpdateLaunchGate, tryAcquireUpdateHelperLiveness, tryRecoverUpdateLaunchGate } from "../launch/update-launch-gate.js";
|
|
9
|
+
import { parseUpdateHelperRequest } from "./update-helper.js";
|
|
10
|
+
import { readTreeDigestForProof } from "./resume-staging.js";
|
|
11
|
+
import { lstat, open, readdir, realpath, rm, unlink } from "node:fs/promises";
|
|
14
12
|
import { join } from "node:path";
|
|
15
|
-
import { randomUUID } from "node:crypto";
|
|
16
13
|
import { constants as constants$1 } from "node:fs";
|
|
17
|
-
// src/updates/
|
|
18
|
-
async function exists(path) {
|
|
19
|
-
return lstat(path).then(() => true, (error) => {
|
|
20
|
-
if (errorCode(error) === "ENOENT") return false;
|
|
21
|
-
throw error;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
/** Validate the empty extraction remainder left by the legacy stage publisher. */
|
|
25
|
-
async function isLegacyExtractionRemainder(path) {
|
|
26
|
-
const info = await lstat(path);
|
|
27
|
-
if (!info.isDirectory() || info.isSymbolicLink()) return false;
|
|
28
|
-
const entries = await readdir(path);
|
|
29
|
-
if (entries.length !== 1 || entries[0] !== "payload") return false;
|
|
30
|
-
const payload = join(path, "payload");
|
|
31
|
-
const payloadInfo = await lstat(payload);
|
|
32
|
-
return payloadInfo.isDirectory() && !payloadInfo.isSymbolicLink() && (await readdir(payload)).length === 0;
|
|
33
|
-
}
|
|
34
|
-
async function readTreeDigestForProof(path) {
|
|
35
|
-
try {
|
|
36
|
-
return await readUpdateTreeDigest(path);
|
|
37
|
-
} catch {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/** Recover only layouts produced by a proven-exited legacy helper. */
|
|
42
|
-
async function recoverLegacyHandoff(options) {
|
|
43
|
-
const { target, staging, currentVersion, helperPid } = options;
|
|
44
|
-
if (!Number.isSafeInteger(helperPid) || helperPid < 2 || updateProcessMayBeAlive(helperPid)) return { status: "recovery-required" };
|
|
45
|
-
let request;
|
|
46
|
-
try {
|
|
47
|
-
const text = await readUpdateHelperRequestFile(staging);
|
|
48
|
-
if (text === void 0) return { status: "recovery-required" };
|
|
49
|
-
request = parseUpdateHelperRequest(JSON.parse(text));
|
|
50
|
-
} catch {
|
|
51
|
-
return { status: "recovery-required" };
|
|
52
|
-
}
|
|
53
|
-
const nativePlatform = process.platform === "darwin" && process.arch === "arm64" ? "macos-arm64" : process.platform === "win32" && process.arch === "x64" ? "windows-x64" : process.platform === "linux" && process.arch === "x64" ? "linux-x64" : process.platform === "linux" && process.arch === "arm64" ? "linux-arm64" : void 0;
|
|
54
|
-
if (request.schema !== 1 || request.target !== target || request.platform !== nativePlatform || request.version === currentVersion) return { status: "recovery-required" };
|
|
55
|
-
const allowed = /* @__PURE__ */ new Set([
|
|
56
|
-
"candidate",
|
|
57
|
-
"helper",
|
|
58
|
-
"helper-armed",
|
|
59
|
-
"old",
|
|
60
|
-
"request.json"
|
|
61
|
-
]);
|
|
62
|
-
for (const name of await readdir(staging)) {
|
|
63
|
-
if (allowed.has(name)) continue;
|
|
64
|
-
if (!/^framework-update-extract-[a-z0-9]{6}$/i.test(name)) return { status: "recovery-required" };
|
|
65
|
-
try {
|
|
66
|
-
if (!await isLegacyExtractionRemainder(join(staging, name))) return { status: "recovery-required" };
|
|
67
|
-
} catch {
|
|
68
|
-
return { status: "recovery-required" };
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const candidate = join(staging, "candidate");
|
|
72
|
-
const old = join(staging, "old");
|
|
73
|
-
const [targetExists, candidateExists, oldExists] = await Promise.all([
|
|
74
|
-
exists(target),
|
|
75
|
-
exists(candidate),
|
|
76
|
-
exists(old)
|
|
77
|
-
]);
|
|
78
|
-
if (!candidateExists || await readUpdateTreeVersion(candidate) !== request.version) return { status: "recovery-required" };
|
|
79
|
-
const candidateInfo = await lstat(candidate);
|
|
80
|
-
if (!candidateInfo.isDirectory() || candidateInfo.isSymbolicLink()) return { status: "recovery-required" };
|
|
81
|
-
if (!targetExists && oldExists) {
|
|
82
|
-
const oldInfo = await lstat(old);
|
|
83
|
-
if (!oldInfo.isDirectory() || oldInfo.isSymbolicLink() || await readUpdateTreeVersion(old) !== currentVersion) return { status: "recovery-required" };
|
|
84
|
-
renameExclusive(old, target);
|
|
85
|
-
} else if (targetExists && !oldExists) {
|
|
86
|
-
const targetInfo = await lstat(target);
|
|
87
|
-
if (!targetInfo.isDirectory() || targetInfo.isSymbolicLink() || await readUpdateTreeVersion(target) !== currentVersion) return { status: "recovery-required" };
|
|
88
|
-
} else return { status: "recovery-required" };
|
|
89
|
-
const archived = `${staging}.legacy-${randomUUID()}`;
|
|
90
|
-
renameExclusive(staging, archived);
|
|
91
|
-
return { status: "not-applied" };
|
|
92
|
-
}
|
|
93
|
-
async function resetToStaged(staging, state) {
|
|
94
|
-
const { helperPid: _helperPid, helperOwner: _helperOwner, previousTreeIdentity: _previousTreeIdentity, ...recoverable } = state;
|
|
95
|
-
const next = {
|
|
96
|
-
...recoverable,
|
|
97
|
-
phase: "staged"
|
|
98
|
-
};
|
|
99
|
-
await clearHelperArtifacts(staging);
|
|
100
|
-
await writeUpdateStageState(staging, next);
|
|
101
|
-
return next;
|
|
102
|
-
}
|
|
103
|
-
async function clearHelperArtifacts(staging) {
|
|
104
|
-
await rm(join(staging, "request.json"), { force: true });
|
|
105
|
-
await rm(join(staging, "helper-armed"), { force: true });
|
|
106
|
-
await rm(join(staging, "helper-ready"), { force: true });
|
|
107
|
-
await rm(join(staging, "cancel.json"), { force: true });
|
|
108
|
-
await rm(join(staging, "cancel-ack.json"), { force: true });
|
|
109
|
-
await rm(join(staging, "helper"), {
|
|
110
|
-
recursive: true,
|
|
111
|
-
force: true
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
var knownStagingEntries = /* @__PURE__ */ new Set([
|
|
115
|
-
"candidate",
|
|
116
|
-
"helper",
|
|
117
|
-
"helper-armed",
|
|
118
|
-
"helper-ready",
|
|
119
|
-
"cancel.json",
|
|
120
|
-
"cancel-ack.json",
|
|
121
|
-
"request.json",
|
|
122
|
-
"state.json"
|
|
123
|
-
]);
|
|
124
|
-
async function hasUnknownStagingEntries(staging, allowed = [], generation) {
|
|
125
|
-
const entries = await readdir(staging);
|
|
126
|
-
const stateTemporary = generation ? new RegExp(`^\\.state-${generation}-[0-9a-f-]{36}\\.tmp$`, "i") : void 0;
|
|
127
|
-
return entries.some((entry) => !knownStagingEntries.has(entry) && !allowed.includes(entry) && !(stateTemporary?.test(entry) ?? false));
|
|
128
|
-
}
|
|
129
|
-
async function reconcileSwap(target, staging, state) {
|
|
130
|
-
const candidate = join(staging, "candidate");
|
|
131
|
-
const old = join(staging, "old");
|
|
132
|
-
if (!await exists(target) && await exists(old) && await exists(candidate)) {
|
|
133
|
-
if (await hasUnknownStagingEntries(staging, ["old"], state.generation)) return void 0;
|
|
134
|
-
try {
|
|
135
|
-
const [oldInfo, candidateInfo] = await Promise.all([lstat(old), lstat(candidate)]);
|
|
136
|
-
const [oldIdentity, candidateIdentity] = await Promise.all([readUpdateTreeIdentity(old), readUpdateTreeIdentity(candidate)]);
|
|
137
|
-
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
|
-
renameExclusive(old, target);
|
|
139
|
-
return resetToStaged(staging, state);
|
|
140
|
-
} catch {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (await exists(old) || await hasUnknownStagingEntries(staging, [], state.generation) || !await exists(target) || !await exists(candidate)) return void 0;
|
|
145
|
-
try {
|
|
146
|
-
const [targetInfo, candidateInfo] = await Promise.all([lstat(target), lstat(candidate)]);
|
|
147
|
-
if (!targetInfo.isDirectory() || targetInfo.isSymbolicLink() || !candidateInfo.isDirectory() || candidateInfo.isSymbolicLink()) return void 0;
|
|
148
|
-
} catch {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const [targetVersion, candidateVersion] = await Promise.all([readUpdateTreeVersion(target), readUpdateTreeVersion(candidate)]);
|
|
152
|
-
const [targetIdentity, candidateIdentity] = await Promise.all([readUpdateTreeIdentity(target), readUpdateTreeIdentity(candidate)]);
|
|
153
|
-
if (targetVersion === state.previousVersion && candidateVersion === state.version && targetIdentity !== void 0 && candidateIdentity !== void 0 && sameUpdateTreeIdentity(candidateIdentity, state.candidateTreeIdentity) && (state.candidateTreeDigest === void 0 || sameUpdateTreeDigest(await readTreeDigestForProof(candidate), state.candidateTreeDigest)) && !sameUpdateTreeIdentity(targetIdentity, candidateIdentity) && (!state.previousTreeIdentity || sameUpdateTreeIdentity(targetIdentity, state.previousTreeIdentity))) return resetToStaged(staging, state);
|
|
154
|
-
if (targetVersion === state.version && candidateVersion === state.previousVersion && sameUpdateTreeIdentity(targetIdentity, state.candidateTreeIdentity) && (state.candidateTreeDigest === void 0 || sameUpdateTreeDigest(await readTreeDigestForProof(target), state.candidateTreeDigest)) && sameUpdateTreeIdentity(candidateIdentity, state.previousTreeIdentity)) {
|
|
155
|
-
const completed = {
|
|
156
|
-
...state,
|
|
157
|
-
phase: "completed"
|
|
158
|
-
};
|
|
159
|
-
await writeUpdateStageState(staging, completed);
|
|
160
|
-
return completed;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
async function recoverStagedCandidate(options) {
|
|
164
|
-
const { target, staging, state, trust, currentVersion } = options;
|
|
165
|
-
if (!state.candidateTreeDigest && !options.allowDigestlessLegacy) return { status: "recovery-required" };
|
|
166
|
-
if (!state.signedRelease || state.previousVersion !== currentVersion) return { status: "recovery-required" };
|
|
167
|
-
const verified = verifyReleaseDescriptor(state.signedRelease, trust);
|
|
168
|
-
if (!verified.ok || verified.descriptor.version !== state.version) return { status: "recovery-required" };
|
|
169
|
-
if (await readUpdateTreeVersion(target) !== currentVersion) return { status: "recovery-required" };
|
|
170
|
-
const candidate = join(staging, "candidate");
|
|
171
|
-
let info;
|
|
172
|
-
try {
|
|
173
|
-
info = await lstat(candidate);
|
|
174
|
-
} catch (error) {
|
|
175
|
-
if (errorCode(error) === "ENOENT") return { status: "recovery-required" };
|
|
176
|
-
throw error;
|
|
177
|
-
}
|
|
178
|
-
if (!info.isDirectory() || info.isSymbolicLink()) return { status: "recovery-required" };
|
|
179
|
-
if (await exists(join(staging, "old")) || await readUpdateTreeVersion(candidate) !== state.version || !sameUpdateTreeIdentity(await readUpdateTreeIdentity(candidate), state.candidateTreeIdentity) || state.candidateTreeDigest !== void 0 && !sameUpdateTreeDigest(await readTreeDigestForProof(candidate), state.candidateTreeDigest)) return { status: "recovery-required" };
|
|
180
|
-
return {
|
|
181
|
-
status: "staged",
|
|
182
|
-
version: state.version,
|
|
183
|
-
channel: verified.descriptor.channel
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
async function resumeLocked(options) {
|
|
187
|
-
const { target, staging, trust, currentVersion } = options;
|
|
188
|
-
const launchGate = await readUpdateLaunchGate(target);
|
|
189
|
-
if (!await exists(staging)) {
|
|
190
|
-
if (launchGate) return { status: "recovery-required" };
|
|
191
|
-
const cleanup = await reconcileRetirementCleanupMarkerWhileLocked({
|
|
192
|
-
target,
|
|
193
|
-
staging,
|
|
194
|
-
currentVersion
|
|
195
|
-
});
|
|
196
|
-
return cleanup === "none" ? { status: "none" } : cleanup === "updated" ? {
|
|
197
|
-
status: "updated",
|
|
198
|
-
version: currentVersion
|
|
199
|
-
} : { status: "recovery-required" };
|
|
200
|
-
}
|
|
201
|
-
const info = await lstat(staging);
|
|
202
|
-
if (!info.isDirectory() || info.isSymbolicLink()) throw new Error("Unexpected update staging entry");
|
|
203
|
-
let state = await readUpdateStageState(staging);
|
|
204
|
-
if (!state) {
|
|
205
|
-
if (launchGate) return { status: "recovery-required" };
|
|
206
|
-
const cleanup = await reconcileRetirementCleanupMarkerWhileLocked({
|
|
207
|
-
target,
|
|
208
|
-
staging,
|
|
209
|
-
currentVersion
|
|
210
|
-
});
|
|
211
|
-
if (cleanup !== "none") return cleanup === "updated" ? {
|
|
212
|
-
status: "updated",
|
|
213
|
-
version: currentVersion
|
|
214
|
-
} : { status: "recovery-required" };
|
|
215
|
-
const helper = Number(await readFile(join(staging, "helper-armed"), "utf8").catch(() => 0));
|
|
216
|
-
if (Number.isSafeInteger(helper) && helper > 1 && updateProcessMayBeAlive(helper)) return { status: "in-progress" };
|
|
217
|
-
const legacyVersion = await readFile(join(staging, "updated"), "utf8").catch(() => void 0);
|
|
218
|
-
if (legacyVersion && await readUpdateTreeVersion(target) === legacyVersion) {
|
|
219
|
-
const entries = await readdir(staging);
|
|
220
|
-
if (entries.length !== 1 || entries[0] !== "updated") return { status: "recovery-required" };
|
|
221
|
-
await unlink(join(staging, "updated"));
|
|
222
|
-
await rmdir(staging);
|
|
223
|
-
return {
|
|
224
|
-
status: "updated",
|
|
225
|
-
version: legacyVersion
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
if (Number.isSafeInteger(helper) && helper > 1) return recoverLegacyHandoff({
|
|
229
|
-
target,
|
|
230
|
-
staging,
|
|
231
|
-
currentVersion,
|
|
232
|
-
helperPid: helper
|
|
233
|
-
});
|
|
234
|
-
if ((await readdir(staging)).length === 0) {
|
|
235
|
-
await rmdir(staging);
|
|
236
|
-
return { status: "not-applied" };
|
|
237
|
-
}
|
|
238
|
-
return { status: "recovery-required" };
|
|
239
|
-
}
|
|
240
|
-
if (launchGate) {
|
|
241
|
-
if (state.launchGateOwner !== launchGate.owner || state.generation !== launchGate.generation || state.version !== launchGate.version) return { status: "recovery-required" };
|
|
242
|
-
if (state.helperPid && updateProcessMayBeAlive(state.helperPid)) return { status: "in-progress" };
|
|
243
|
-
return { status: "recovery-required" };
|
|
244
|
-
}
|
|
245
|
-
if (state.launchGateOwner !== void 0 && state.phase !== "completed" && state.phase !== "retiring" && state.phase !== "retired") return { status: "recovery-required" };
|
|
246
|
-
if (state.helperPid && updateProcessMayBeAlive(state.helperPid)) return { status: "in-progress" };
|
|
247
|
-
if (!state.helperPid && await hasUpdateHelperArtifacts(staging)) return { status: "recovery-required" };
|
|
248
|
-
if (state.launchGateOwner && !state.candidateTreeDigest) return { status: "recovery-required" };
|
|
249
|
-
if (state.phase === "staged") {
|
|
250
|
-
if (state.helperPid) state = await resetToStaged(staging, state);
|
|
251
|
-
return recoverStagedCandidate({
|
|
252
|
-
target,
|
|
253
|
-
staging,
|
|
254
|
-
state,
|
|
255
|
-
trust,
|
|
256
|
-
currentVersion
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
if (state.phase === "armed") {
|
|
260
|
-
state = await resetToStaged(staging, state);
|
|
261
|
-
return recoverStagedCandidate({
|
|
262
|
-
target,
|
|
263
|
-
staging,
|
|
264
|
-
state,
|
|
265
|
-
trust,
|
|
266
|
-
currentVersion,
|
|
267
|
-
allowDigestlessLegacy: true
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
if (state.phase === "swapping") {
|
|
271
|
-
const reconciled = await reconcileSwap(target, staging, state);
|
|
272
|
-
if (!reconciled) return { status: "recovery-required" };
|
|
273
|
-
state = reconciled;
|
|
274
|
-
if (state.phase === "completed") {
|
|
275
|
-
if (await readUpdateTreeVersion(target) !== state.version) return { status: "recovery-required" };
|
|
276
|
-
if (!await retireCompletedUpdateWhileLocked({
|
|
277
|
-
target,
|
|
278
|
-
staging,
|
|
279
|
-
state
|
|
280
|
-
})) return { status: "recovery-required" };
|
|
281
|
-
return {
|
|
282
|
-
status: "updated",
|
|
283
|
-
version: state.version
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
if (state.helperPid) state = await resetToStaged(staging, state);
|
|
287
|
-
return recoverStagedCandidate({
|
|
288
|
-
target,
|
|
289
|
-
staging,
|
|
290
|
-
state,
|
|
291
|
-
trust,
|
|
292
|
-
currentVersion,
|
|
293
|
-
allowDigestlessLegacy: true
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
if (state.phase === "completed") {
|
|
297
|
-
if (await readUpdateTreeVersion(target) !== state.version || !sameUpdateTreeIdentity(await readUpdateTreeIdentity(target), state.candidateTreeIdentity) || state.candidateTreeDigest !== void 0 && !sameUpdateTreeDigest(await readTreeDigestForProof(target), state.candidateTreeDigest)) return { status: "recovery-required" };
|
|
298
|
-
if (!await retireCompletedUpdateWhileLocked({
|
|
299
|
-
target,
|
|
300
|
-
staging,
|
|
301
|
-
state
|
|
302
|
-
})) return { status: "recovery-required" };
|
|
303
|
-
return {
|
|
304
|
-
status: "updated",
|
|
305
|
-
version: state.version
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
if (state.phase === "retiring" || state.phase === "retired") {
|
|
309
|
-
if (await readUpdateTreeVersion(target) !== state.version || !sameUpdateTreeIdentity(await readUpdateTreeIdentity(target), state.candidateTreeIdentity) || state.candidateTreeDigest !== void 0 && !sameUpdateTreeDigest(await readTreeDigestForProof(target), state.candidateTreeDigest)) return { status: "recovery-required" };
|
|
310
|
-
if (!await retireCompletedUpdateWhileLocked({
|
|
311
|
-
target,
|
|
312
|
-
staging,
|
|
313
|
-
state
|
|
314
|
-
})) return { status: "recovery-required" };
|
|
315
|
-
return {
|
|
316
|
-
status: "updated",
|
|
317
|
-
version: state.version
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
if (state.phase === "failed") {
|
|
321
|
-
state = await resetToStaged(staging, state);
|
|
322
|
-
return recoverStagedCandidate({
|
|
323
|
-
target,
|
|
324
|
-
staging,
|
|
325
|
-
state,
|
|
326
|
-
trust,
|
|
327
|
-
currentVersion,
|
|
328
|
-
allowDigestlessLegacy: true
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
throw new Error("Invalid update staging phase");
|
|
332
|
-
}
|
|
14
|
+
// src/updates/helper/launch-gate-recovery.ts
|
|
333
15
|
var recoveryStagingEntries = /* @__PURE__ */ new Set([
|
|
334
16
|
"candidate",
|
|
335
17
|
"helper",
|
|
@@ -758,96 +440,4 @@ async function finalizeClearedSchema3StagedOwner(target, staging, trust) {
|
|
|
758
440
|
}
|
|
759
441
|
}
|
|
760
442
|
}
|
|
761
|
-
|
|
762
|
-
* Call on app start. Reconcile only while holding the same per-install lock
|
|
763
|
-
* used by stage, helper handoff, and the swap. A valid staged candidate is
|
|
764
|
-
* retained until a helper completes or an explicit caller handles it.
|
|
765
|
-
*/
|
|
766
|
-
async function resumeUpdate(options) {
|
|
767
|
-
const staging = updateStagingFor(options.target);
|
|
768
|
-
let lock;
|
|
769
|
-
try {
|
|
770
|
-
lock = await acquireUpdateLock(options.target, 100);
|
|
771
|
-
} catch (error) {
|
|
772
|
-
if (error instanceof UpdateLockBusyError) return { status: "in-progress" };
|
|
773
|
-
throw error;
|
|
774
|
-
}
|
|
775
|
-
try {
|
|
776
|
-
return await resumeLocked({
|
|
777
|
-
target: options.target,
|
|
778
|
-
staging,
|
|
779
|
-
trust: options.trust,
|
|
780
|
-
currentVersion: options.currentVersion
|
|
781
|
-
});
|
|
782
|
-
} finally {
|
|
783
|
-
await lock.release();
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
/**
|
|
787
|
-
* Resume and acquire retained-generation leases under one install lock. This
|
|
788
|
-
* lets callers with explicit release trust serve old lazy assets alongside a
|
|
789
|
-
* validated pending staged candidate without opening a swap race.
|
|
790
|
-
*/
|
|
791
|
-
async function resumeUpdateWithRetainedTrees(options) {
|
|
792
|
-
const staging = updateStagingFor(options.target);
|
|
793
|
-
let lock;
|
|
794
|
-
try {
|
|
795
|
-
lock = await acquireUpdateLock(options.target, 100);
|
|
796
|
-
} catch (error) {
|
|
797
|
-
if (error instanceof UpdateLockBusyError) return { status: "in-progress" };
|
|
798
|
-
throw error;
|
|
799
|
-
}
|
|
800
|
-
let retained;
|
|
801
|
-
try {
|
|
802
|
-
if ((await readUpdateStageState(staging))?.phase === "armed") return { status: "recovery-required" };
|
|
803
|
-
const resumed = await resumeLocked({
|
|
804
|
-
target: options.target,
|
|
805
|
-
staging,
|
|
806
|
-
trust: options.trust,
|
|
807
|
-
currentVersion: options.currentVersion
|
|
808
|
-
});
|
|
809
|
-
if (resumed.status === "in-progress" || resumed.status === "recovery-required") return { status: resumed.status };
|
|
810
|
-
retained = await acquireRetainedUpdateTreesWhileLocked({
|
|
811
|
-
target: options.target,
|
|
812
|
-
currentVersion: resumed.status === "updated" ? resumed.version : options.currentVersion,
|
|
813
|
-
...resumed.status === "staged" ? {
|
|
814
|
-
validatedStagedVersion: resumed.version,
|
|
815
|
-
stagedTrust: options.trust
|
|
816
|
-
} : {}
|
|
817
|
-
});
|
|
818
|
-
if (retained.status === "busy") return { status: "busy" };
|
|
819
|
-
const result = {
|
|
820
|
-
status: "ready",
|
|
821
|
-
resume: resumed,
|
|
822
|
-
retained
|
|
823
|
-
};
|
|
824
|
-
const heldLock = lock;
|
|
825
|
-
lock = void 0;
|
|
826
|
-
try {
|
|
827
|
-
await heldLock.release();
|
|
828
|
-
} catch (error) {
|
|
829
|
-
if (retained.status === "acquired") {
|
|
830
|
-
const acquired = retained;
|
|
831
|
-
retained = void 0;
|
|
832
|
-
try {
|
|
833
|
-
await acquired.release();
|
|
834
|
-
} catch (releaseError) {
|
|
835
|
-
throw new AggregateError([error, releaseError], "Update lock and retained tree leases failed to release", { cause: releaseError });
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
throw error;
|
|
839
|
-
}
|
|
840
|
-
retained = void 0;
|
|
841
|
-
return result;
|
|
842
|
-
} catch (error) {
|
|
843
|
-
if (retained?.status === "acquired") try {
|
|
844
|
-
await retained.release();
|
|
845
|
-
} catch (releaseError) {
|
|
846
|
-
throw new AggregateError([error, releaseError], "Resume failure and retained tree leases failed to release", { cause: releaseError });
|
|
847
|
-
}
|
|
848
|
-
throw error;
|
|
849
|
-
} finally {
|
|
850
|
-
await lock?.release();
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
export { acquireRetainedUpdateTrees, recoverUpdateLaunchGate, resumeUpdate, resumeUpdateWithRetainedTrees };
|
|
443
|
+
export { recoverUpdateLaunchGate };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ReleaseTrust } from '../feed/signed-release';
|
|
2
|
+
import { type UpdateStageState } from '../update-state-store';
|
|
3
|
+
import type { UpdateResumeResult } from './update-resume';
|
|
4
|
+
export declare function exists(path: string): Promise<boolean>;
|
|
5
|
+
export declare function readTreeDigestForProof(path: string): Promise<string | undefined>;
|
|
6
|
+
/** Recover only layouts produced by a proven-exited legacy helper. */
|
|
7
|
+
export declare function recoverLegacyHandoff(options: {
|
|
8
|
+
target: string;
|
|
9
|
+
staging: string;
|
|
10
|
+
currentVersion: string;
|
|
11
|
+
helperPid: number;
|
|
12
|
+
}): Promise<UpdateResumeResult>;
|
|
13
|
+
export declare function resetToStaged(staging: string, state: UpdateStageState): Promise<UpdateStageState>;
|
|
14
|
+
export declare function reconcileSwap(target: string, staging: string, state: UpdateStageState): Promise<UpdateStageState | undefined>;
|
|
15
|
+
export declare function recoverStagedCandidate(options: {
|
|
16
|
+
target: string;
|
|
17
|
+
staging: string;
|
|
18
|
+
state: UpdateStageState;
|
|
19
|
+
trust: ReleaseTrust;
|
|
20
|
+
currentVersion: string;
|
|
21
|
+
allowDigestlessLegacy?: boolean;
|
|
22
|
+
}): Promise<UpdateResumeResult>;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { errorCode } from "../../app/value-guards.js";
|
|
2
|
+
import { renameExclusive } from "../../native/native-rename.js";
|
|
3
|
+
import { verifyReleaseDescriptor } from "../feed/signed-release.js";
|
|
4
|
+
import { readUpdateHelperRequestFile, writeUpdateStageState } from "../update-state-store.js";
|
|
5
|
+
import { readUpdateTreeDigest, readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeDigest, sameUpdateTreeIdentity } from "../install/update-swap.js";
|
|
6
|
+
import { parseUpdateHelperRequest } from "./update-helper.js";
|
|
7
|
+
import { updateProcessMayBeAlive } from "../locks/update-process-liveness.js";
|
|
8
|
+
import { lstat, readdir, rm } from "node:fs/promises";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { randomUUID } from "node:crypto";
|
|
11
|
+
// src/updates/helper/resume-staging.ts
|
|
12
|
+
async function exists(path) {
|
|
13
|
+
return lstat(path).then(() => true, (error) => {
|
|
14
|
+
if (errorCode(error) === "ENOENT") return false;
|
|
15
|
+
throw error;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** Validate the empty extraction remainder left by the legacy stage publisher. */
|
|
19
|
+
async function isLegacyExtractionRemainder(path) {
|
|
20
|
+
const info = await lstat(path);
|
|
21
|
+
if (!info.isDirectory() || info.isSymbolicLink()) return false;
|
|
22
|
+
const entries = await readdir(path);
|
|
23
|
+
if (entries.length !== 1 || entries[0] !== "payload") return false;
|
|
24
|
+
const payload = join(path, "payload");
|
|
25
|
+
const payloadInfo = await lstat(payload);
|
|
26
|
+
return payloadInfo.isDirectory() && !payloadInfo.isSymbolicLink() && (await readdir(payload)).length === 0;
|
|
27
|
+
}
|
|
28
|
+
async function readTreeDigestForProof(path) {
|
|
29
|
+
try {
|
|
30
|
+
return await readUpdateTreeDigest(path);
|
|
31
|
+
} catch {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Recover only layouts produced by a proven-exited legacy helper. */
|
|
36
|
+
async function recoverLegacyHandoff(options) {
|
|
37
|
+
const { target, staging, currentVersion, helperPid } = options;
|
|
38
|
+
if (!Number.isSafeInteger(helperPid) || helperPid < 2 || updateProcessMayBeAlive(helperPid)) return { status: "recovery-required" };
|
|
39
|
+
let request;
|
|
40
|
+
try {
|
|
41
|
+
const text = await readUpdateHelperRequestFile(staging);
|
|
42
|
+
if (text === void 0) return { status: "recovery-required" };
|
|
43
|
+
request = parseUpdateHelperRequest(JSON.parse(text));
|
|
44
|
+
} catch {
|
|
45
|
+
return { status: "recovery-required" };
|
|
46
|
+
}
|
|
47
|
+
const nativePlatform = process.platform === "darwin" && process.arch === "arm64" ? "macos-arm64" : process.platform === "win32" && process.arch === "x64" ? "windows-x64" : process.platform === "linux" && process.arch === "x64" ? "linux-x64" : process.platform === "linux" && process.arch === "arm64" ? "linux-arm64" : void 0;
|
|
48
|
+
if (request.schema !== 1 || request.target !== target || request.platform !== nativePlatform || request.version === currentVersion) return { status: "recovery-required" };
|
|
49
|
+
const allowed = /* @__PURE__ */ new Set([
|
|
50
|
+
"candidate",
|
|
51
|
+
"helper",
|
|
52
|
+
"helper-armed",
|
|
53
|
+
"old",
|
|
54
|
+
"request.json"
|
|
55
|
+
]);
|
|
56
|
+
for (const name of await readdir(staging)) {
|
|
57
|
+
if (allowed.has(name)) continue;
|
|
58
|
+
if (!/^framework-update-extract-[a-z0-9]{6}$/i.test(name)) return { status: "recovery-required" };
|
|
59
|
+
try {
|
|
60
|
+
if (!await isLegacyExtractionRemainder(join(staging, name))) return { status: "recovery-required" };
|
|
61
|
+
} catch {
|
|
62
|
+
return { status: "recovery-required" };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const candidate = join(staging, "candidate");
|
|
66
|
+
const old = join(staging, "old");
|
|
67
|
+
const [targetExists, candidateExists, oldExists] = await Promise.all([
|
|
68
|
+
exists(target),
|
|
69
|
+
exists(candidate),
|
|
70
|
+
exists(old)
|
|
71
|
+
]);
|
|
72
|
+
if (!candidateExists || await readUpdateTreeVersion(candidate) !== request.version) return { status: "recovery-required" };
|
|
73
|
+
const candidateInfo = await lstat(candidate);
|
|
74
|
+
if (!candidateInfo.isDirectory() || candidateInfo.isSymbolicLink()) return { status: "recovery-required" };
|
|
75
|
+
if (!targetExists && oldExists) {
|
|
76
|
+
const oldInfo = await lstat(old);
|
|
77
|
+
if (!oldInfo.isDirectory() || oldInfo.isSymbolicLink() || await readUpdateTreeVersion(old) !== currentVersion) return { status: "recovery-required" };
|
|
78
|
+
renameExclusive(old, target);
|
|
79
|
+
} else if (targetExists && !oldExists) {
|
|
80
|
+
const targetInfo = await lstat(target);
|
|
81
|
+
if (!targetInfo.isDirectory() || targetInfo.isSymbolicLink() || await readUpdateTreeVersion(target) !== currentVersion) return { status: "recovery-required" };
|
|
82
|
+
} else return { status: "recovery-required" };
|
|
83
|
+
const archived = `${staging}.legacy-${randomUUID()}`;
|
|
84
|
+
renameExclusive(staging, archived);
|
|
85
|
+
return { status: "not-applied" };
|
|
86
|
+
}
|
|
87
|
+
async function resetToStaged(staging, state) {
|
|
88
|
+
const { helperPid: _helperPid, helperOwner: _helperOwner, previousTreeIdentity: _previousTreeIdentity, ...recoverable } = state;
|
|
89
|
+
const next = {
|
|
90
|
+
...recoverable,
|
|
91
|
+
phase: "staged"
|
|
92
|
+
};
|
|
93
|
+
await clearHelperArtifacts(staging);
|
|
94
|
+
await writeUpdateStageState(staging, next);
|
|
95
|
+
return next;
|
|
96
|
+
}
|
|
97
|
+
async function clearHelperArtifacts(staging) {
|
|
98
|
+
await rm(join(staging, "request.json"), { force: true });
|
|
99
|
+
await rm(join(staging, "helper-armed"), { force: true });
|
|
100
|
+
await rm(join(staging, "helper-ready"), { force: true });
|
|
101
|
+
await rm(join(staging, "cancel.json"), { force: true });
|
|
102
|
+
await rm(join(staging, "cancel-ack.json"), { force: true });
|
|
103
|
+
await rm(join(staging, "helper"), {
|
|
104
|
+
recursive: true,
|
|
105
|
+
force: true
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
var knownStagingEntries = /* @__PURE__ */ new Set([
|
|
109
|
+
"candidate",
|
|
110
|
+
"helper",
|
|
111
|
+
"helper-armed",
|
|
112
|
+
"helper-ready",
|
|
113
|
+
"cancel.json",
|
|
114
|
+
"cancel-ack.json",
|
|
115
|
+
"request.json",
|
|
116
|
+
"state.json"
|
|
117
|
+
]);
|
|
118
|
+
async function hasUnknownStagingEntries(staging, allowed = [], generation) {
|
|
119
|
+
const entries = await readdir(staging);
|
|
120
|
+
const stateTemporary = generation ? new RegExp(`^\\.state-${generation}-[0-9a-f-]{36}\\.tmp$`, "i") : void 0;
|
|
121
|
+
return entries.some((entry) => !knownStagingEntries.has(entry) && !allowed.includes(entry) && !(stateTemporary?.test(entry) ?? false));
|
|
122
|
+
}
|
|
123
|
+
async function reconcileSwap(target, staging, state) {
|
|
124
|
+
const candidate = join(staging, "candidate");
|
|
125
|
+
const old = join(staging, "old");
|
|
126
|
+
if (!await exists(target) && await exists(old) && await exists(candidate)) {
|
|
127
|
+
if (await hasUnknownStagingEntries(staging, ["old"], state.generation)) return void 0;
|
|
128
|
+
try {
|
|
129
|
+
const [oldInfo, candidateInfo] = await Promise.all([lstat(old), lstat(candidate)]);
|
|
130
|
+
const [oldIdentity, candidateIdentity] = await Promise.all([readUpdateTreeIdentity(old), readUpdateTreeIdentity(candidate)]);
|
|
131
|
+
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;
|
|
132
|
+
renameExclusive(old, target);
|
|
133
|
+
return resetToStaged(staging, state);
|
|
134
|
+
} catch {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (await exists(old) || await hasUnknownStagingEntries(staging, [], state.generation) || !await exists(target) || !await exists(candidate)) return void 0;
|
|
139
|
+
try {
|
|
140
|
+
const [targetInfo, candidateInfo] = await Promise.all([lstat(target), lstat(candidate)]);
|
|
141
|
+
if (!targetInfo.isDirectory() || targetInfo.isSymbolicLink() || !candidateInfo.isDirectory() || candidateInfo.isSymbolicLink()) return void 0;
|
|
142
|
+
} catch {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const [targetVersion, candidateVersion] = await Promise.all([readUpdateTreeVersion(target), readUpdateTreeVersion(candidate)]);
|
|
146
|
+
const [targetIdentity, candidateIdentity] = await Promise.all([readUpdateTreeIdentity(target), readUpdateTreeIdentity(candidate)]);
|
|
147
|
+
if (targetVersion === state.previousVersion && candidateVersion === state.version && targetIdentity !== void 0 && candidateIdentity !== void 0 && sameUpdateTreeIdentity(candidateIdentity, state.candidateTreeIdentity) && (state.candidateTreeDigest === void 0 || sameUpdateTreeDigest(await readTreeDigestForProof(candidate), state.candidateTreeDigest)) && !sameUpdateTreeIdentity(targetIdentity, candidateIdentity) && (!state.previousTreeIdentity || sameUpdateTreeIdentity(targetIdentity, state.previousTreeIdentity))) return resetToStaged(staging, state);
|
|
148
|
+
if (targetVersion === state.version && candidateVersion === state.previousVersion && sameUpdateTreeIdentity(targetIdentity, state.candidateTreeIdentity) && (state.candidateTreeDigest === void 0 || sameUpdateTreeDigest(await readTreeDigestForProof(target), state.candidateTreeDigest)) && sameUpdateTreeIdentity(candidateIdentity, state.previousTreeIdentity)) {
|
|
149
|
+
const completed = {
|
|
150
|
+
...state,
|
|
151
|
+
phase: "completed"
|
|
152
|
+
};
|
|
153
|
+
await writeUpdateStageState(staging, completed);
|
|
154
|
+
return completed;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async function recoverStagedCandidate(options) {
|
|
158
|
+
const { target, staging, state, trust, currentVersion } = options;
|
|
159
|
+
if (!state.candidateTreeDigest && !options.allowDigestlessLegacy) return { status: "recovery-required" };
|
|
160
|
+
if (!state.signedRelease || state.previousVersion !== currentVersion) return { status: "recovery-required" };
|
|
161
|
+
const verified = verifyReleaseDescriptor(state.signedRelease, trust);
|
|
162
|
+
if (!verified.ok || verified.descriptor.version !== state.version) return { status: "recovery-required" };
|
|
163
|
+
if (await readUpdateTreeVersion(target) !== currentVersion) return { status: "recovery-required" };
|
|
164
|
+
const candidate = join(staging, "candidate");
|
|
165
|
+
let info;
|
|
166
|
+
try {
|
|
167
|
+
info = await lstat(candidate);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
if (errorCode(error) === "ENOENT") return { status: "recovery-required" };
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
if (!info.isDirectory() || info.isSymbolicLink()) return { status: "recovery-required" };
|
|
173
|
+
if (await exists(join(staging, "old")) || await readUpdateTreeVersion(candidate) !== state.version || !sameUpdateTreeIdentity(await readUpdateTreeIdentity(candidate), state.candidateTreeIdentity) || state.candidateTreeDigest !== void 0 && !sameUpdateTreeDigest(await readTreeDigestForProof(candidate), state.candidateTreeDigest)) return { status: "recovery-required" };
|
|
174
|
+
return {
|
|
175
|
+
status: "staged",
|
|
176
|
+
version: state.version,
|
|
177
|
+
channel: verified.descriptor.channel
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
export { exists, readTreeDigestForProof, reconcileSwap, recoverLegacyHandoff, recoverStagedCandidate, resetToStaged };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InstallerPlatform } from '
|
|
1
|
+
import type { InstallerPlatform } from '../../installer/installer-layout';
|
|
2
2
|
/** Everything the post-exit helper needs, written by the app into its private staging directory. */
|
|
3
3
|
export type UpdateHelperRequest = Readonly<{
|
|
4
4
|
schema: 1 | 2 | 3;
|