@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
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { errorCode, isUuid } from "../../app/value-guards.js";
|
|
2
|
+
import { isCanonicalPath } from "../../native/canonical-path.js";
|
|
3
|
+
import { renameExclusive } from "../../native/native-rename.js";
|
|
4
|
+
import { readSmallStateFile } from "../locks/stable-file.js";
|
|
5
|
+
import { readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeIdentity } from "../install/update-swap.js";
|
|
6
|
+
import { lstat, readdir, writeFile } from "node:fs/promises";
|
|
7
|
+
import { basename, dirname, join } from "node:path";
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
// src/updates/retention/retirement-records.ts
|
|
10
|
+
var VERSION = /^\d+\.\d+\.\d+(?:-dev\.\d+)?$/;
|
|
11
|
+
var PUBLISHER_TEMP_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
12
|
+
function hasExactOwnKeys(value, expected) {
|
|
13
|
+
const actual = Reflect.ownKeys(value);
|
|
14
|
+
return actual.length === expected.length && actual.every((key) => typeof key === "string" && expected.includes(key));
|
|
15
|
+
}
|
|
16
|
+
/** Generation-specific retirement paths, all beside the fixed staging path. */
|
|
17
|
+
function updateRetirementPaths(target, generation) {
|
|
18
|
+
if (!isCanonicalPath(target) || !isUuid(generation)) throw new Error("Invalid update retirement identity");
|
|
19
|
+
const prefix = `.${basename(target)}.framework-retired-${generation}`;
|
|
20
|
+
const container = join(dirname(target), prefix);
|
|
21
|
+
return Object.freeze({
|
|
22
|
+
container,
|
|
23
|
+
tree: join(container, "tree"),
|
|
24
|
+
healthReceipt: join(container, "healthy.json"),
|
|
25
|
+
healthTemporaryPrefix: ".healthy-",
|
|
26
|
+
claim: join(dirname(target), `${prefix}.claim.json`),
|
|
27
|
+
claimTemporaryPrefix: `${prefix}.claim-`,
|
|
28
|
+
cleanupMarker: join(dirname(target), `.${basename(target)}.framework-update-cleanup.json`),
|
|
29
|
+
cleanupMarkerTemporaryPrefix: `.${basename(target)}.framework-update-cleanup-`
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async function matchesPartiallyPrunedContainer(intent, owner, paths, phase) {
|
|
33
|
+
if (intent.generation !== owner.generation.toLowerCase() || intent.target !== owner.target || !sameUpdateTreeIdentity(intent.previousTreeIdentity, owner.previousTreeIdentity)) return false;
|
|
34
|
+
const containerInfo = await pathInfo(paths.container);
|
|
35
|
+
if (!containerInfo) return phase === "empty" && !await pathInfo(paths.tree);
|
|
36
|
+
if (!containerInfo.isDirectory() || containerInfo.isSymbolicLink()) return false;
|
|
37
|
+
const entries = await readdir(paths.container);
|
|
38
|
+
const treeInfo = await pathInfo(paths.tree);
|
|
39
|
+
const healthInfo = await pathInfo(paths.healthReceipt);
|
|
40
|
+
const allowed = /* @__PURE__ */ new Set([...treeInfo ? ["tree"] : [], ...healthInfo ? ["healthy.json"] : []]);
|
|
41
|
+
if (entries.length !== allowed.size || entries.some((name) => !allowed.has(name))) return false;
|
|
42
|
+
if (!treeInfo) return phase === "empty";
|
|
43
|
+
if (!treeInfo.isDirectory() || treeInfo.isSymbolicLink() || !await samePathTreeIdentity(paths.tree, intent.previousTreeIdentity)) return false;
|
|
44
|
+
if (phase === "empty") return (await readdir(paths.tree)).length === 0;
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
async function samePathTreeIdentity(path, identity) {
|
|
48
|
+
try {
|
|
49
|
+
return sameUpdateTreeIdentity(await readUpdateTreeIdentity(path), identity);
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function ownerFor(target, state) {
|
|
55
|
+
if (!state.previousTreeIdentity || !state.candidateTreeIdentity) return void 0;
|
|
56
|
+
const paths = updateRetirementPaths(target, state.generation);
|
|
57
|
+
return {
|
|
58
|
+
schema: 2,
|
|
59
|
+
generation: state.generation,
|
|
60
|
+
target,
|
|
61
|
+
newVersion: state.version,
|
|
62
|
+
previousVersion: state.previousVersion,
|
|
63
|
+
previousTreeIdentity: state.previousTreeIdentity,
|
|
64
|
+
newTreeIdentity: state.candidateTreeIdentity,
|
|
65
|
+
container: basename(paths.container),
|
|
66
|
+
tree: "tree"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function parseOwner(value) {
|
|
70
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
71
|
+
const record = value;
|
|
72
|
+
const identity = record.previousTreeIdentity;
|
|
73
|
+
const newTreeIdentity = record.newTreeIdentity;
|
|
74
|
+
if (record.schema !== 2 || typeof record.generation !== "string" || !isUuid(record.generation) || !isCanonicalPath(record.target) || typeof record.newVersion !== "string" || !VERSION.test(record.newVersion) || typeof record.previousVersion !== "string" || !VERSION.test(record.previousVersion) || typeof identity !== "object" || identity === null || Array.isArray(identity) || !hasExactOwnKeys(identity, ["device", "inode"]) || typeof identity.device !== "string" || !/^[1-9]\d{0,19}$/.test(identity.device) || typeof identity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(identity.inode) || typeof newTreeIdentity !== "object" || newTreeIdentity === null || Array.isArray(newTreeIdentity) || !hasExactOwnKeys(newTreeIdentity, ["device", "inode"]) || typeof newTreeIdentity.device !== "string" || !/^[1-9]\d{0,19}$/.test(newTreeIdentity.device) || typeof newTreeIdentity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(newTreeIdentity.inode) || typeof record.container !== "string" || record.container !== `.${basename(record.target)}.framework-retired-${record.generation}` || record.tree !== "tree" || !hasExactOwnKeys(record, [
|
|
75
|
+
"schema",
|
|
76
|
+
"generation",
|
|
77
|
+
"target",
|
|
78
|
+
"newVersion",
|
|
79
|
+
"previousVersion",
|
|
80
|
+
"previousTreeIdentity",
|
|
81
|
+
"newTreeIdentity",
|
|
82
|
+
"container",
|
|
83
|
+
"tree"
|
|
84
|
+
])) return void 0;
|
|
85
|
+
return record;
|
|
86
|
+
}
|
|
87
|
+
function ownerMatches(actual, expected) {
|
|
88
|
+
return actual !== void 0 && actual.schema === expected.schema && actual.generation === expected.generation && actual.target === expected.target && actual.newVersion === expected.newVersion && actual.previousVersion === expected.previousVersion && actual.container === expected.container && actual.tree === expected.tree && sameUpdateTreeIdentity(actual.previousTreeIdentity, expected.previousTreeIdentity) && sameUpdateTreeIdentity(actual.newTreeIdentity, expected.newTreeIdentity);
|
|
89
|
+
}
|
|
90
|
+
function cleanupMarkerFor(target, state) {
|
|
91
|
+
const paths = updateRetirementPaths(target, state.generation);
|
|
92
|
+
return {
|
|
93
|
+
schema: 1,
|
|
94
|
+
generation: state.generation,
|
|
95
|
+
target,
|
|
96
|
+
version: state.version,
|
|
97
|
+
claim: basename(paths.claim),
|
|
98
|
+
phase: "staging-cleanup"
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function cleanupMarkerMatches(actual, expected) {
|
|
102
|
+
return actual !== void 0 && actual.schema === expected.schema && actual.generation === expected.generation && actual.target === expected.target && actual.version === expected.version && actual.claim === expected.claim && actual.phase === expected.phase;
|
|
103
|
+
}
|
|
104
|
+
function parseCleanupMarker(value) {
|
|
105
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
106
|
+
const record = value;
|
|
107
|
+
if (record.schema !== 1 || typeof record.generation !== "string" || !isUuid(record.generation) || !isCanonicalPath(record.target) || typeof record.version !== "string" || !VERSION.test(record.version) || typeof record.claim !== "string" || record.claim !== basename(updateRetirementPaths(record.target, record.generation).claim) || record.phase !== "staging-cleanup" || Object.keys(record).length !== 6) return void 0;
|
|
108
|
+
return record;
|
|
109
|
+
}
|
|
110
|
+
async function readOwner(path) {
|
|
111
|
+
try {
|
|
112
|
+
const text = await readSmallStateFile(path, 4096, "Invalid update retirement record");
|
|
113
|
+
return text === void 0 ? void 0 : parseOwner(JSON.parse(text));
|
|
114
|
+
} catch {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function parseHealthReceipt(value) {
|
|
119
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
120
|
+
const record = value;
|
|
121
|
+
const identity = record.treeIdentity;
|
|
122
|
+
if (record.schema !== 1 || typeof record.generation !== "string" || !isUuid(record.generation) || !isCanonicalPath(record.target) || typeof record.version !== "string" || !VERSION.test(record.version) || typeof identity !== "object" || identity === null || Array.isArray(identity) || !hasExactOwnKeys(identity, ["device", "inode"]) || typeof identity.device !== "string" || !/^[1-9]\d{0,19}$/.test(identity.device) || typeof identity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(identity.inode) || !hasExactOwnKeys(record, [
|
|
123
|
+
"schema",
|
|
124
|
+
"generation",
|
|
125
|
+
"target",
|
|
126
|
+
"version",
|
|
127
|
+
"treeIdentity"
|
|
128
|
+
])) return void 0;
|
|
129
|
+
return record;
|
|
130
|
+
}
|
|
131
|
+
async function readHealthReceipt(path) {
|
|
132
|
+
try {
|
|
133
|
+
const text = await readSmallStateFile(path, 4096, "Invalid update retirement record");
|
|
134
|
+
return text === void 0 ? void 0 : parseHealthReceipt(JSON.parse(text));
|
|
135
|
+
} catch {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function healthReceiptFor(owner) {
|
|
140
|
+
return {
|
|
141
|
+
schema: 1,
|
|
142
|
+
generation: owner.generation,
|
|
143
|
+
target: owner.target,
|
|
144
|
+
version: owner.newVersion,
|
|
145
|
+
treeIdentity: owner.newTreeIdentity
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function healthReceiptMatches(actual, expected) {
|
|
149
|
+
return actual !== void 0 && actual.schema === expected.schema && actual.generation === expected.generation && actual.target === expected.target && actual.version === expected.version && sameUpdateTreeIdentity(actual.treeIdentity, expected.treeIdentity);
|
|
150
|
+
}
|
|
151
|
+
async function readCleanupMarker(path) {
|
|
152
|
+
try {
|
|
153
|
+
const text = await readSmallStateFile(path, 4096, "Invalid update retirement record");
|
|
154
|
+
return text === void 0 ? void 0 : parseCleanupMarker(JSON.parse(text));
|
|
155
|
+
} catch {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function pathInfo(path) {
|
|
160
|
+
try {
|
|
161
|
+
return await lstat(path);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (errorCode(error) === "ENOENT") return void 0;
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async function matchesOldTree(path, state) {
|
|
168
|
+
if (!state.previousTreeIdentity) return false;
|
|
169
|
+
try {
|
|
170
|
+
const info = await lstat(path);
|
|
171
|
+
return info.isDirectory() && !info.isSymbolicLink() && await readUpdateTreeVersion(path) === state.previousVersion && sameUpdateTreeIdentity(await readUpdateTreeIdentity(path), state.previousTreeIdentity);
|
|
172
|
+
} catch {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function isMatchingClaimTemporary(name, paths) {
|
|
177
|
+
if (!name.startsWith(paths.claimTemporaryPrefix) || !name.endsWith(".tmp")) return false;
|
|
178
|
+
return isUuid(name.slice(paths.claimTemporaryPrefix.length, -4));
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Publish the generation claim from a complete private temporary using an
|
|
182
|
+
* exclusive rename. A valid interrupted temporary can be promoted on retry;
|
|
183
|
+
* malformed or colliding files are preserved and never treated as ownership.
|
|
184
|
+
*/
|
|
185
|
+
async function ensureClaim(target, state) {
|
|
186
|
+
const expected = ownerFor(target, state);
|
|
187
|
+
if (!expected) return false;
|
|
188
|
+
const paths = updateRetirementPaths(target, state.generation);
|
|
189
|
+
if (await pathInfo(paths.claim)) return ownerMatches(await readOwner(paths.claim), expected);
|
|
190
|
+
let entries;
|
|
191
|
+
try {
|
|
192
|
+
entries = await readdir(dirname(target));
|
|
193
|
+
} catch {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
const temporaryNames = entries.filter((name) => isMatchingClaimTemporary(name, paths));
|
|
197
|
+
for (const name of temporaryNames) {
|
|
198
|
+
const temporary = join(dirname(target), name);
|
|
199
|
+
const info = await pathInfo(temporary);
|
|
200
|
+
if (!info || !info.isFile() || info.isSymbolicLink()) continue;
|
|
201
|
+
if (!ownerMatches(await readOwner(temporary), expected)) continue;
|
|
202
|
+
try {
|
|
203
|
+
renameExclusive(temporary, paths.claim);
|
|
204
|
+
} catch {
|
|
205
|
+
return ownerMatches(await readOwner(paths.claim), expected);
|
|
206
|
+
}
|
|
207
|
+
return ownerMatches(await readOwner(paths.claim), expected);
|
|
208
|
+
}
|
|
209
|
+
const temporary = join(dirname(target), `${paths.claimTemporaryPrefix}${randomUUID()}.tmp`);
|
|
210
|
+
try {
|
|
211
|
+
await writeFile(temporary, JSON.stringify(expected) + "\n", {
|
|
212
|
+
flag: "wx",
|
|
213
|
+
mode: 384
|
|
214
|
+
});
|
|
215
|
+
if (!ownerMatches(await readOwner(temporary), expected)) return false;
|
|
216
|
+
renameExclusive(temporary, paths.claim);
|
|
217
|
+
} catch {
|
|
218
|
+
return ownerMatches(await readOwner(paths.claim), expected);
|
|
219
|
+
}
|
|
220
|
+
return ownerMatches(await readOwner(paths.claim), expected);
|
|
221
|
+
}
|
|
222
|
+
function isMatchingCleanupTemporary(name, paths) {
|
|
223
|
+
if (!name.startsWith(paths.cleanupMarkerTemporaryPrefix) || !name.endsWith(".tmp")) return false;
|
|
224
|
+
return isUuid(name.slice(paths.cleanupMarkerTemporaryPrefix.length, -4));
|
|
225
|
+
}
|
|
226
|
+
async function ensureCleanupMarker(target, state) {
|
|
227
|
+
const expected = cleanupMarkerFor(target, state);
|
|
228
|
+
const paths = updateRetirementPaths(target, state.generation);
|
|
229
|
+
if (await pathInfo(paths.cleanupMarker)) return cleanupMarkerMatches(await readCleanupMarker(paths.cleanupMarker), expected);
|
|
230
|
+
let entries;
|
|
231
|
+
try {
|
|
232
|
+
entries = await readdir(dirname(target));
|
|
233
|
+
} catch {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
for (const name of entries.filter((entry) => isMatchingCleanupTemporary(entry, paths))) {
|
|
237
|
+
const temporary = join(dirname(target), name);
|
|
238
|
+
const info = await pathInfo(temporary);
|
|
239
|
+
if (!info?.isFile() || info.isSymbolicLink()) continue;
|
|
240
|
+
if (!cleanupMarkerMatches(await readCleanupMarker(temporary), expected)) continue;
|
|
241
|
+
try {
|
|
242
|
+
renameExclusive(temporary, paths.cleanupMarker);
|
|
243
|
+
} catch {
|
|
244
|
+
return cleanupMarkerMatches(await readCleanupMarker(paths.cleanupMarker), expected);
|
|
245
|
+
}
|
|
246
|
+
return cleanupMarkerMatches(await readCleanupMarker(paths.cleanupMarker), expected);
|
|
247
|
+
}
|
|
248
|
+
const temporary = join(dirname(target), `${paths.cleanupMarkerTemporaryPrefix}${randomUUID()}.tmp`);
|
|
249
|
+
try {
|
|
250
|
+
await writeFile(temporary, JSON.stringify(expected) + "\n", {
|
|
251
|
+
flag: "wx",
|
|
252
|
+
mode: 384
|
|
253
|
+
});
|
|
254
|
+
if (!cleanupMarkerMatches(await readCleanupMarker(temporary), expected)) return false;
|
|
255
|
+
renameExclusive(temporary, paths.cleanupMarker);
|
|
256
|
+
} catch {
|
|
257
|
+
return cleanupMarkerMatches(await readCleanupMarker(paths.cleanupMarker), expected);
|
|
258
|
+
}
|
|
259
|
+
return cleanupMarkerMatches(await readCleanupMarker(paths.cleanupMarker), expected);
|
|
260
|
+
}
|
|
261
|
+
async function matchesOwnedTree(path, owner) {
|
|
262
|
+
try {
|
|
263
|
+
const info = await lstat(path);
|
|
264
|
+
return info.isDirectory() && !info.isSymbolicLink() && await readUpdateTreeVersion(path) === owner.previousVersion && sameUpdateTreeIdentity(await readUpdateTreeIdentity(path), owner.previousTreeIdentity);
|
|
265
|
+
} catch {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async function matchesInstalledTree(path, owner) {
|
|
270
|
+
try {
|
|
271
|
+
const info = await lstat(path);
|
|
272
|
+
return info.isDirectory() && !info.isSymbolicLink() && await readUpdateTreeVersion(path) === owner.newVersion && sameUpdateTreeIdentity(await readUpdateTreeIdentity(path), owner.newTreeIdentity);
|
|
273
|
+
} catch {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function isMatchingHealthTemporary(name) {
|
|
278
|
+
return name.startsWith(".healthy-") && name.endsWith(".tmp") && isUuid(name.slice(9, -4));
|
|
279
|
+
}
|
|
280
|
+
async function validRetirementContainer(owner, paths, allowHealthTemporaries = true, pruneProgress) {
|
|
281
|
+
const info = await pathInfo(paths.container);
|
|
282
|
+
if (!info?.isDirectory() || info.isSymbolicLink()) return false;
|
|
283
|
+
if (pruneProgress) {
|
|
284
|
+
if (!await matchesPartiallyPrunedContainer(pruneProgress.intent, owner, paths, pruneProgress.phase)) return false;
|
|
285
|
+
} else if (!await matchesOwnedTree(paths.tree, owner)) return false;
|
|
286
|
+
const entries = await readdir(paths.container);
|
|
287
|
+
if (entries.some((name) => name !== "tree" && name !== "healthy.json" && !isMatchingHealthTemporary(name))) return false;
|
|
288
|
+
if (!allowHealthTemporaries && entries.some(isMatchingHealthTemporary)) return false;
|
|
289
|
+
const receiptInfo = await pathInfo(paths.healthReceipt);
|
|
290
|
+
if (receiptInfo) {
|
|
291
|
+
const receipt = await readHealthReceipt(paths.healthReceipt);
|
|
292
|
+
if (!receiptInfo.isFile() || receiptInfo.isSymbolicLink() || !receipt) return false;
|
|
293
|
+
if (!healthReceiptMatches(receipt, healthReceiptFor(owner))) return false;
|
|
294
|
+
}
|
|
295
|
+
for (const name of entries.filter(isMatchingHealthTemporary)) {
|
|
296
|
+
const temporaryInfo = await pathInfo(join(paths.container, name));
|
|
297
|
+
if (!temporaryInfo?.isFile() || temporaryInfo.isSymbolicLink() || temporaryInfo.size > 4096) return false;
|
|
298
|
+
const receipt = await readHealthReceipt(join(paths.container, name));
|
|
299
|
+
if (receipt && !healthReceiptMatches(receipt, healthReceiptFor(owner))) return false;
|
|
300
|
+
}
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
function generationFromClaimName(name, target) {
|
|
304
|
+
const prefix = `.${basename(target)}.framework-retired-`;
|
|
305
|
+
if (!name.startsWith(prefix) || !name.endsWith(".claim.json")) return void 0;
|
|
306
|
+
const generation = name.slice(prefix.length, -11);
|
|
307
|
+
return isUuid(generation) ? generation : void 0;
|
|
308
|
+
}
|
|
309
|
+
export { PUBLISHER_TEMP_UUID, VERSION, cleanupMarkerMatches, ensureClaim, ensureCleanupMarker, generationFromClaimName, hasExactOwnKeys, healthReceiptFor, healthReceiptMatches, isMatchingHealthTemporary, matchesInstalledTree, matchesOldTree, matchesOwnedTree, matchesPartiallyPrunedContainer, ownerFor, ownerMatches, parseHealthReceipt, parseOwner, pathInfo, readCleanupMarker, readHealthReceipt, readOwner, samePathTreeIdentity, updateRetirementPaths, validRetirementContainer };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { errorCode } from "
|
|
2
|
-
import { isCanonicalPath } from "
|
|
1
|
+
import { errorCode } from "../../app/value-guards.js";
|
|
2
|
+
import { isCanonicalPath } from "../../native/canonical-path.js";
|
|
3
3
|
import { link, lstat, open, unlink, writeFile } from "node:fs/promises";
|
|
4
4
|
import { basename, dirname, join } from "node:path";
|
|
5
5
|
import { randomUUID } from "node:crypto";
|
|
6
6
|
import { constants as constants$1 } from "node:fs";
|
|
7
|
-
// src/updates/update-retention-marker.ts
|
|
7
|
+
// src/updates/retention/update-retention-marker.ts
|
|
8
8
|
/** Compare all fields that bind an intent to its retained and installed trees. */
|
|
9
9
|
function sameRetentionIntent(left, right) {
|
|
10
10
|
return left.schema === right.schema && left.phase === right.phase && left.target === right.target && left.generation === right.generation && left.installedGeneration === right.installedGeneration && left.previousTreeIdentity !== void 0 && right.previousTreeIdentity !== void 0 && left.installedTreeIdentity !== void 0 && right.installedTreeIdentity !== void 0 && left.previousTreeIdentity.device === right.previousTreeIdentity.device && left.previousTreeIdentity.inode === right.previousTreeIdentity.inode && left.installedTreeIdentity.device === right.installedTreeIdentity.device && left.installedTreeIdentity.inode === right.installedTreeIdentity.inode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isUuid } from "
|
|
2
|
-
// src/updates/update-retention-plan.ts
|
|
1
|
+
import { isUuid } from "../../app/value-guards.js";
|
|
2
|
+
// src/updates/retention/update-retention-plan.ts
|
|
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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type BigIntStats } from 'node:fs';
|
|
2
2
|
import { type UpdateRetentionIntent } from './update-retention-marker';
|
|
3
|
-
import type { UpdateTreeIdentity } from '
|
|
3
|
+
import type { UpdateTreeIdentity } from '../install/update-swap';
|
|
4
4
|
/** The small file-handle surface used by the persistence barrier. */
|
|
5
5
|
type UpdateRetentionSyncHandle = Readonly<{
|
|
6
6
|
fd?: number;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { syncDarwinDescriptor } from "../native/darwin-sync.js";
|
|
2
1
|
import { readUpdateRetentionIntentFile, sameRetentionIntent, updateRetentionIntentPath } from "./update-retention-marker.js";
|
|
2
|
+
import { syncDarwinDescriptor } from "../../native/darwin-sync.js";
|
|
3
3
|
import { lstat, open } from "node:fs/promises";
|
|
4
4
|
import { dirname } from "node:path";
|
|
5
5
|
import { constants as constants$1 } from "node:fs";
|
|
6
|
-
// src/updates/update-retention-sync.ts
|
|
6
|
+
// src/updates/retention/update-retention-sync.ts
|
|
7
7
|
var defaultIO = {
|
|
8
8
|
open: async (path, flags) => open(path, flags),
|
|
9
9
|
async sync(handle, kind) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type UpdateStageState } from '../update-state-store';
|
|
2
|
+
import { type UpdateHealthAcknowledgement } from './retirement-records';
|
|
3
|
+
/** Explicitly acknowledge an exact installed generation after app-owned readiness checks. */
|
|
4
|
+
export declare function acknowledgeRetiredUpdateHealthy(options: {
|
|
5
|
+
target: string;
|
|
6
|
+
acknowledgement: UpdateHealthAcknowledgement;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
/** Reconcile the exact unlink/rmdir completion boundary while holding the install lock. */
|
|
9
|
+
export declare function reconcileRetirementCleanupMarkerWhileLocked(options: {
|
|
10
|
+
target: string;
|
|
11
|
+
staging: string;
|
|
12
|
+
currentVersion: string;
|
|
13
|
+
}): Promise<'none' | 'updated' | 'recovery-required'>;
|
|
14
|
+
/**
|
|
15
|
+
* Reconcile a completed exchange while the stable per-install lock is held.
|
|
16
|
+
* The old app tree is moved without replacement into a UUID-owned container;
|
|
17
|
+
* it is never modified or deleted here. Atomic rename publication protects
|
|
18
|
+
* against process crashes, but this protocol makes no power-loss claim.
|
|
19
|
+
* Health is recorded only after an explicit host call; app-owned readiness
|
|
20
|
+
* criteria and quarantine retention/cleanup policy remain WIP.
|
|
21
|
+
*/
|
|
22
|
+
export declare function retireCompletedUpdateWhileLocked(options: {
|
|
23
|
+
target: string;
|
|
24
|
+
staging: string;
|
|
25
|
+
state: UpdateStageState;
|
|
26
|
+
}): Promise<boolean>;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { isUuid } from "../../app/value-guards.js";
|
|
2
|
+
import { renameExclusive } from "../../native/native-rename.js";
|
|
3
|
+
import { readUpdateStageState, withUpdateLock, writeUpdateStageState } from "../update-state-store.js";
|
|
4
|
+
import { readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeIdentity, updateStagingFor } from "../install/update-swap.js";
|
|
5
|
+
import { VERSION, cleanupMarkerMatches, ensureClaim, ensureCleanupMarker, healthReceiptFor, healthReceiptMatches, isMatchingHealthTemporary, matchesInstalledTree, matchesOldTree, matchesOwnedTree, ownerFor, ownerMatches, pathInfo, readCleanupMarker, readHealthReceipt, readOwner, updateRetirementPaths, validRetirementContainer } from "./retirement-records.js";
|
|
6
|
+
import { lstat, mkdir, readdir, rm, rmdir, unlink, writeFile } from "node:fs/promises";
|
|
7
|
+
import { basename, dirname, join } from "node:path";
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
// src/updates/retention/update-retirement.ts
|
|
10
|
+
async function acknowledgeUpdateHealthWhileLocked(target, token) {
|
|
11
|
+
if (typeof token !== "object" || token === null || !isUuid(token.generation) || typeof token.version !== "string" || !VERSION.test(token.version)) return false;
|
|
12
|
+
const paths = updateRetirementPaths(target, token.generation);
|
|
13
|
+
const claimInfo = await pathInfo(paths.claim);
|
|
14
|
+
const owner = await readOwner(paths.claim);
|
|
15
|
+
if (!claimInfo?.isFile() || claimInfo.isSymbolicLink() || !owner || owner.target !== target || owner.generation !== token.generation || owner.newVersion !== token.version || !await matchesInstalledTree(target, owner) || !await validRetirementContainer(owner, paths)) return false;
|
|
16
|
+
const expected = healthReceiptFor(owner);
|
|
17
|
+
if (await pathInfo(paths.healthReceipt)) return healthReceiptMatches(await readHealthReceipt(paths.healthReceipt), expected);
|
|
18
|
+
const entries = await readdir(paths.container);
|
|
19
|
+
for (const name of entries.filter(isMatchingHealthTemporary)) {
|
|
20
|
+
const temporary = join(paths.container, name);
|
|
21
|
+
const receipt = await readHealthReceipt(temporary);
|
|
22
|
+
if (!receipt) continue;
|
|
23
|
+
if (!healthReceiptMatches(receipt, expected)) return false;
|
|
24
|
+
try {
|
|
25
|
+
renameExclusive(temporary, paths.healthReceipt);
|
|
26
|
+
} catch {
|
|
27
|
+
return healthReceiptMatches(await readHealthReceipt(paths.healthReceipt), expected);
|
|
28
|
+
}
|
|
29
|
+
return healthReceiptMatches(await readHealthReceipt(paths.healthReceipt), expected) && await matchesInstalledTree(target, owner);
|
|
30
|
+
}
|
|
31
|
+
const temporary = join(paths.container, `${paths.healthTemporaryPrefix}${randomUUID()}.tmp`);
|
|
32
|
+
try {
|
|
33
|
+
await writeFile(temporary, JSON.stringify(expected) + "\n", {
|
|
34
|
+
flag: "wx",
|
|
35
|
+
mode: 384
|
|
36
|
+
});
|
|
37
|
+
if (!healthReceiptMatches(await readHealthReceipt(temporary), expected)) return false;
|
|
38
|
+
renameExclusive(temporary, paths.healthReceipt);
|
|
39
|
+
} catch {
|
|
40
|
+
return healthReceiptMatches(await readHealthReceipt(paths.healthReceipt), expected);
|
|
41
|
+
}
|
|
42
|
+
return healthReceiptMatches(await readHealthReceipt(paths.healthReceipt), expected) && await matchesInstalledTree(target, owner) && await matchesOwnedTree(paths.tree, owner);
|
|
43
|
+
}
|
|
44
|
+
/** Explicitly acknowledge an exact installed generation after app-owned readiness checks. */
|
|
45
|
+
async function acknowledgeRetiredUpdateHealthy(options) {
|
|
46
|
+
if (!await withUpdateLock(options.target, () => acknowledgeUpdateHealthWhileLocked(options.target, options.acknowledgement))) throw new Error("The update health acknowledgement did not match the installed generation");
|
|
47
|
+
}
|
|
48
|
+
/** Reconcile the exact unlink/rmdir completion boundary while holding the install lock. */
|
|
49
|
+
async function reconcileRetirementCleanupMarkerWhileLocked(options) {
|
|
50
|
+
const { target, staging, currentVersion } = options;
|
|
51
|
+
const markerPath = join(dirname(target), `.${basename(target)}.framework-update-cleanup.json`);
|
|
52
|
+
if (!await pathInfo(markerPath)) return "none";
|
|
53
|
+
const marker = await readCleanupMarker(markerPath);
|
|
54
|
+
if (!marker || marker.target !== target || marker.version !== currentVersion) return "recovery-required";
|
|
55
|
+
const targetInfo = await pathInfo(target);
|
|
56
|
+
if (!targetInfo?.isDirectory() || targetInfo.isSymbolicLink() || await readUpdateTreeVersion(target) !== marker.version) return "recovery-required";
|
|
57
|
+
const paths = updateRetirementPaths(target, marker.generation);
|
|
58
|
+
const owner = await readOwner(paths.claim);
|
|
59
|
+
if (!owner || owner.target !== target || owner.generation !== marker.generation || owner.newVersion !== marker.version || marker.claim !== basename(paths.claim) || !await matchesOwnedTree(paths.tree, owner)) return "recovery-required";
|
|
60
|
+
const containerInfo = await pathInfo(paths.container);
|
|
61
|
+
if (!containerInfo?.isDirectory() || containerInfo.isSymbolicLink()) return "recovery-required";
|
|
62
|
+
const containerEntries = await readdir(paths.container);
|
|
63
|
+
if (containerEntries.length !== 1 || containerEntries[0] !== "tree") return "recovery-required";
|
|
64
|
+
const stagingInfo = await pathInfo(staging);
|
|
65
|
+
if (stagingInfo) {
|
|
66
|
+
if (!stagingInfo.isDirectory() || stagingInfo.isSymbolicLink()) return "recovery-required";
|
|
67
|
+
if ((await readdir(staging)).length !== 0) return "recovery-required";
|
|
68
|
+
await rmdir(staging);
|
|
69
|
+
}
|
|
70
|
+
const currentMarker = await readCleanupMarker(markerPath);
|
|
71
|
+
if (!cleanupMarkerMatches(currentMarker, marker)) return "recovery-required";
|
|
72
|
+
await unlink(markerPath);
|
|
73
|
+
return "updated";
|
|
74
|
+
}
|
|
75
|
+
async function knownStagingEntriesOnly(staging, generation) {
|
|
76
|
+
const known = /* @__PURE__ */ new Set([
|
|
77
|
+
"candidate",
|
|
78
|
+
"helper",
|
|
79
|
+
"helper-armed",
|
|
80
|
+
"helper-ready",
|
|
81
|
+
"cancel.json",
|
|
82
|
+
"cancel-ack.json",
|
|
83
|
+
"request.json",
|
|
84
|
+
"state.json"
|
|
85
|
+
]);
|
|
86
|
+
const stateTemporary = new RegExp(`^\\.state-${generation}-[0-9a-f-]{36}\\.tmp$`, "i");
|
|
87
|
+
return (await readdir(staging)).every((name) => known.has(name) || stateTemporary.test(name));
|
|
88
|
+
}
|
|
89
|
+
async function removeKnownStateTemporaries(staging, generation) {
|
|
90
|
+
const stateTemporary = new RegExp(`^\\.state-${generation}-[0-9a-f-]{36}\\.tmp$`, "i");
|
|
91
|
+
for (const name of await readdir(staging)) {
|
|
92
|
+
if (!stateTemporary.test(name)) continue;
|
|
93
|
+
const path = join(staging, name);
|
|
94
|
+
const info = await pathInfo(path);
|
|
95
|
+
if (!info || !info.isFile() || info.isSymbolicLink()) return false;
|
|
96
|
+
await unlink(path);
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
async function cleanupRetiredStaging(target, staging, state) {
|
|
101
|
+
if (!await knownStagingEntriesOnly(staging, state.generation)) return false;
|
|
102
|
+
if (await pathInfo(join(staging, "candidate"))) return false;
|
|
103
|
+
await rm(join(staging, "request.json"), { force: true });
|
|
104
|
+
await rm(join(staging, "helper-armed"), { force: true });
|
|
105
|
+
await rm(join(staging, "helper-ready"), { force: true });
|
|
106
|
+
await rm(join(staging, "cancel.json"), { force: true });
|
|
107
|
+
await rm(join(staging, "cancel-ack.json"), { force: true });
|
|
108
|
+
await rm(join(staging, "helper"), {
|
|
109
|
+
recursive: true,
|
|
110
|
+
force: true
|
|
111
|
+
});
|
|
112
|
+
if (!await removeKnownStateTemporaries(staging, state.generation)) return false;
|
|
113
|
+
const current = await readUpdateStageState(staging);
|
|
114
|
+
if (!current || current.generation !== state.generation || current.phase !== "retired") return false;
|
|
115
|
+
const entries = await readdir(staging);
|
|
116
|
+
if (entries.length !== 1 || entries[0] !== "state.json") return false;
|
|
117
|
+
if (!await ensureCleanupMarker(target, state)) return false;
|
|
118
|
+
await unlink(join(staging, "state.json"));
|
|
119
|
+
await rmdir(staging);
|
|
120
|
+
return await reconcileRetirementCleanupMarkerWhileLocked({
|
|
121
|
+
target,
|
|
122
|
+
staging,
|
|
123
|
+
currentVersion: state.version
|
|
124
|
+
}) === "updated";
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Reconcile a completed exchange while the stable per-install lock is held.
|
|
128
|
+
* The old app tree is moved without replacement into a UUID-owned container;
|
|
129
|
+
* it is never modified or deleted here. Atomic rename publication protects
|
|
130
|
+
* against process crashes, but this protocol makes no power-loss claim.
|
|
131
|
+
* Health is recorded only after an explicit host call; app-owned readiness
|
|
132
|
+
* criteria and quarantine retention/cleanup policy remain WIP.
|
|
133
|
+
*/
|
|
134
|
+
async function retireCompletedUpdateWhileLocked(options) {
|
|
135
|
+
const { target, staging } = options;
|
|
136
|
+
let state = options.state;
|
|
137
|
+
if (updateStagingFor(target) !== staging || ![
|
|
138
|
+
"completed",
|
|
139
|
+
"retiring",
|
|
140
|
+
"retired"
|
|
141
|
+
].includes(state.phase) || state.phase !== "completed" && !state.previousTreeIdentity) return false;
|
|
142
|
+
try {
|
|
143
|
+
const targetInfo = await lstat(target);
|
|
144
|
+
if (!targetInfo.isDirectory() || targetInfo.isSymbolicLink() || await readUpdateTreeVersion(target) !== state.version) return false;
|
|
145
|
+
} catch {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
if (!state.candidateTreeIdentity || !sameUpdateTreeIdentity(await readUpdateTreeIdentity(target), state.candidateTreeIdentity)) return false;
|
|
149
|
+
const paths = updateRetirementPaths(target, state.generation);
|
|
150
|
+
if (state.phase === "completed") {
|
|
151
|
+
if (!await matchesOldTree(join(staging, "candidate"), state) || await pathInfo(paths.container) || await pathInfo(paths.claim)) return false;
|
|
152
|
+
state = {
|
|
153
|
+
...state,
|
|
154
|
+
phase: "retiring"
|
|
155
|
+
};
|
|
156
|
+
await writeUpdateStageState(staging, state);
|
|
157
|
+
}
|
|
158
|
+
if (state.phase === "retiring") {
|
|
159
|
+
const candidate = join(staging, "candidate");
|
|
160
|
+
const candidateInfo = await pathInfo(candidate);
|
|
161
|
+
const containerInfo = await pathInfo(paths.container);
|
|
162
|
+
const treeInfo = await pathInfo(paths.tree);
|
|
163
|
+
if (candidateInfo && !await matchesOldTree(candidate, state)) return false;
|
|
164
|
+
if (treeInfo && !await matchesOldTree(paths.tree, state)) return false;
|
|
165
|
+
if (candidateInfo && treeInfo) return false;
|
|
166
|
+
if (!candidateInfo && !treeInfo) return false;
|
|
167
|
+
const claimInfo = await pathInfo(paths.claim);
|
|
168
|
+
if (containerInfo && !claimInfo) return false;
|
|
169
|
+
if (!containerInfo && candidateInfo && !claimInfo && !await ensureClaim(target, state)) return false;
|
|
170
|
+
const expectedOwner = ownerFor(target, state);
|
|
171
|
+
if (claimInfo && (!expectedOwner || !await ownerMatches(await readOwner(paths.claim), expectedOwner))) return false;
|
|
172
|
+
if (!claimInfo && (!expectedOwner || !await ownerMatches(await readOwner(paths.claim), expectedOwner))) return false;
|
|
173
|
+
if (!containerInfo) try {
|
|
174
|
+
await mkdir(paths.container, { mode: 448 });
|
|
175
|
+
} catch {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
const currentContainer = await pathInfo(paths.container);
|
|
179
|
+
if (!currentContainer?.isDirectory() || currentContainer.isSymbolicLink()) return false;
|
|
180
|
+
const entries = await readdir(paths.container);
|
|
181
|
+
if (candidateInfo) {
|
|
182
|
+
if (entries.length !== 0) return false;
|
|
183
|
+
try {
|
|
184
|
+
renameExclusive(candidate, paths.tree);
|
|
185
|
+
} catch {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
} else if (entries.length !== 1 || entries[0] !== "tree") return false;
|
|
189
|
+
if (!await matchesOldTree(paths.tree, state)) return false;
|
|
190
|
+
state = {
|
|
191
|
+
...state,
|
|
192
|
+
phase: "retired"
|
|
193
|
+
};
|
|
194
|
+
await writeUpdateStageState(staging, state);
|
|
195
|
+
}
|
|
196
|
+
if (state.phase !== "retired") return false;
|
|
197
|
+
const owner = ownerFor(target, state);
|
|
198
|
+
if (!owner || !await ownerMatches(await readOwner(paths.claim), owner) || !await matchesInstalledTree(target, owner) || await pathInfo(join(staging, "candidate")) || !await matchesOldTree(paths.tree, state)) return false;
|
|
199
|
+
const finalContainer = await pathInfo(paths.container);
|
|
200
|
+
if (!finalContainer?.isDirectory() || finalContainer.isSymbolicLink()) return false;
|
|
201
|
+
const finalEntries = await readdir(paths.container);
|
|
202
|
+
if (finalEntries.length !== 1 || finalEntries[0] !== "tree") return false;
|
|
203
|
+
return cleanupRetiredStaging(target, staging, state);
|
|
204
|
+
}
|
|
205
|
+
export { acknowledgeRetiredUpdateHealthy, reconcileRetirementCleanupMarkerWhileLocked, retireCompletedUpdateWhileLocked };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type UpdateChannel } from './release-version';
|
|
1
|
+
import { type UpdateChannel } from './feed/release-version';
|
|
2
2
|
/** Persist one app-owned update channel; the caller must supply a private state directory. */
|
|
3
3
|
export declare function createUpdateChannelStore(directory: string): {
|
|
4
4
|
read: () => Promise<UpdateChannel>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { isUpdateChannel } from "./release-version.js";
|
|
1
|
+
import { isUpdateChannel } from "./feed/release-version.js";
|
|
2
2
|
import { errorCode } from "../app/value-guards.js";
|
|
3
3
|
import { isCanonicalPath } from "../native/canonical-path.js";
|
|
4
4
|
import { createSerialQueue } from "../app/serial-queue.js";
|
|
5
|
-
import { openUnchangedFile, sameFile } from "./stable-file.js";
|
|
5
|
+
import { openUnchangedFile, sameFile } from "./locks/stable-file.js";
|
|
6
6
|
import { lstat, open, realpath, rename, unlink } from "node:fs/promises";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { randomUUID } from "node:crypto";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { discoverSignedRelease } from './update-discovery';
|
|
2
|
-
import { downloadVerifiedRelease } from './update-download';
|
|
3
|
-
import { type ReleaseTrust, type VerifiedRelease } from './signed-release';
|
|
4
|
-
import type { FetchFunction } from './release-location';
|
|
1
|
+
import { discoverSignedRelease } from './feed/update-discovery';
|
|
2
|
+
import { downloadVerifiedRelease } from './install/update-download';
|
|
3
|
+
import { type ReleaseTrust, type VerifiedRelease } from './feed/signed-release';
|
|
4
|
+
import type { FetchFunction } from './feed/release-location';
|
|
5
5
|
type Phase = 'idle' | 'checking' | 'current' | 'available' | 'downloading' | 'staging' | 'staged' | 'failed';
|
|
6
6
|
type State = Readonly<{
|
|
7
7
|
phase: Phase;
|