@adea-ai/app-framework 0.39.3 → 0.39.4
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 +158 -52
- package/dist/app/application.d.ts +0 -1
- package/dist/app/application.js +8 -6
- package/dist/app/create-application.js +3 -11
- package/dist/app/service-registry.d.ts +0 -1
- package/dist/app/service-registry.js +3 -3
- package/dist/app/value-guards.d.ts +2 -0
- package/dist/app/value-guards.js +6 -1
- package/dist/appearance/appearance-host.d.ts +1 -1
- package/dist/appearance/appearance-host.js +11 -2
- package/dist/appearance/appearance-preferences.d.ts +0 -1
- package/dist/appearance/custom-theme-import.d.ts +8 -2
- package/dist/appearance/custom-theme-import.js +58 -23
- package/dist/appearance/custom-theme-library.d.ts +3 -3
- package/dist/appearance/custom-theme-library.js +3 -3
- package/dist/appearance/theme-file-importer.d.ts +1 -1
- package/dist/appearance/theme-file-importer.js +2 -1
- package/dist/appearance/theme-library-mutation.d.ts +7 -0
- package/dist/appearance/theme-library-mutation.js +10 -2
- package/dist/appearance/theme-library-store.d.ts +17 -13
- package/dist/appearance/theme-library-store.js +35 -22
- package/dist/appearance/theme-record-adapter.js +1 -2
- package/dist/appearance/theme-registry.js +0 -1
- package/dist/cli/cli-runner.d.ts +3 -2
- package/dist/cli/cli-runner.js +5 -10
- package/dist/cli/release-assets-plan-cli.js +2 -2
- package/dist/cli/release-cut-cli.js +2 -3
- package/dist/cli/release-descriptor-staging-cli.js +2 -2
- package/dist/cli/release-finalize-cli.js +3 -3
- package/dist/cli/release-promote-cli.js +2 -2
- package/dist/cli/release-publish-cli.js +2 -2
- package/dist/cli/release-sign-cli.js +2 -1
- package/dist/cli/release-step-cli.js +2 -2
- package/dist/desktop/channel-proof.js +27 -11
- package/dist/desktop/client-assets.d.ts +6 -1
- package/dist/desktop/client-assets.js +16 -3
- package/dist/desktop/client-dev-proxy.d.ts +0 -2
- package/dist/desktop/client-dev-proxy.js +2 -2
- package/dist/desktop/desktop-client.js +2 -1
- package/dist/desktop/desktop-gateway.js +24 -82
- package/dist/desktop/desktop-host-websocket.d.ts +5 -1
- package/dist/desktop/desktop-host-websocket.js +9 -7
- package/dist/desktop/desktop-host.d.ts +5 -0
- package/dist/desktop/desktop-host.js +3 -0
- package/dist/desktop/desktop-stream.js +5 -10
- package/dist/desktop/typed-array-intrinsics.d.ts +6 -0
- package/dist/desktop/typed-array-intrinsics.js +13 -1
- package/dist/developer-app/developer-app.d.ts +1 -1
- package/dist/developer-app/developer-app.js +26 -13
- package/dist/framework-source.json +1 -1
- package/dist/installer/command-artifact.d.ts +1 -0
- package/dist/installer/command-artifact.js +47 -27
- package/dist/installer/installed-payload.js +3 -1
- package/dist/installer/installer-ci-bootstrap.js +5 -6
- package/dist/installer/installer-ci-preflight.js +3 -3
- package/dist/installer/installer-identity.d.ts +0 -22
- package/dist/installer/installer-identity.js +3 -53
- package/dist/installer/installer-image-mount.d.ts +0 -1
- package/dist/installer/installer-image-mount.js +1 -1
- package/dist/installer/installer-observation.d.ts +5 -5
- package/dist/installer/installer-observation.js +32 -47
- package/dist/installer/installer-process-cleanup.js +2 -2
- package/dist/installer/installer-renderer-evidence.js +7 -28
- package/dist/installer/installer-upgrade-command.js +8 -20
- package/dist/installer/installer-worker-guard.js +3 -3
- package/dist/native/cef-helper.js +4 -4
- package/dist/native/desktop-build.d.ts +0 -3
- package/dist/native/desktop-build.js +2 -2
- package/dist/native/electrobun-source-patch.d.ts +4 -0
- package/dist/native/electrobun-source-patch.js +5 -1
- package/dist/native/native-utilities.js +4 -3
- package/dist/native/pinned-download.d.ts +16 -0
- package/dist/native/pinned-download.js +42 -0
- package/dist/native/posix-launcher-build.js +15 -35
- package/dist/native/posix-tree-removal.js +21 -33
- package/dist/native/sidecar-services.d.ts +0 -2
- package/dist/native/sidecar-services.js +1 -1
- package/dist/native/sidecar.d.ts +3 -0
- package/dist/native/sidecar.js +15 -2
- package/dist/native/window-surface-store.js +3 -3
- package/dist/native/windows-extractor-build.d.ts +6 -16
- package/dist/native/windows-extractor-build.js +11 -14
- package/dist/release/feed-release-cut.d.ts +2 -6
- package/dist/release/feed-release-cut.js +5 -93
- package/dist/release/feed-state.js +1 -5
- package/dist/release/github-release-cut.js +5 -66
- package/dist/release/github-release-provenance.d.ts +2 -0
- package/dist/release/github-release-provenance.js +4 -7
- package/dist/release/github-release-publisher.js +2 -2
- package/dist/release/github-release-qualification.js +3 -3
- package/dist/release/local-release.d.ts +3 -3
- package/dist/release/local-release.js +12 -23
- package/dist/release/qualification-run.js +1 -1
- package/dist/release/release-assets-plan.js +1 -1
- package/dist/release/release-config.d.ts +7 -15
- package/dist/release/release-config.js +25 -29
- package/dist/release/release-cut-command.d.ts +1 -1
- package/dist/release/release-cut-command.js +1 -1
- package/dist/release/release-cut.d.ts +5 -32
- package/dist/release/release-cut.js +9 -55
- package/dist/release/release-descriptor-staging.js +3 -8
- package/dist/release/release-promotion.js +2 -1
- package/dist/release/release-publish-command.js +5 -15
- package/dist/release/release-qualification.js +1 -1
- package/dist/shared/bounded-body.d.ts +33 -0
- package/dist/shared/bounded-body.js +102 -0
- package/dist/shared/file-system.d.ts +12 -0
- package/dist/shared/file-system.js +40 -0
- package/dist/shell/app-shell.js +29 -14
- package/dist/shell/app-utilities.d.ts +2 -1
- package/dist/shell/app-utilities.js +2 -1
- package/dist/shell/application-menu.d.ts +1 -1
- package/dist/shell/application-menu.js +7 -3
- package/dist/shell/poll.d.ts +27 -0
- package/dist/shell/poll.js +88 -0
- package/dist/update-helper.bundle.js +268 -144
- package/dist/updates/channel-update-manager.js +0 -1
- package/dist/updates/desktop-updater.d.ts +9 -0
- package/dist/updates/desktop-updater.js +103 -50
- package/dist/updates/feed/release-feed.d.ts +7 -4
- package/dist/updates/feed/release-feed.js +3 -7
- package/dist/updates/feed/release-location.js +6 -26
- package/dist/updates/feed/release-version.d.ts +7 -2
- package/dist/updates/feed/release-version.js +9 -2
- package/dist/updates/feed/signed-release.d.ts +1 -1
- package/dist/updates/feed/signed-release.js +2 -2
- package/dist/updates/feed/update-discovery.js +2 -6
- package/dist/updates/helper/launch-gate-recovery.js +28 -78
- package/dist/updates/helper/resume-staging.d.ts +14 -3
- package/dist/updates/helper/resume-staging.js +23 -37
- package/dist/updates/helper/update-helper.d.ts +6 -2
- package/dist/updates/helper/update-helper.js +38 -33
- package/dist/updates/helper/update-resume.js +9 -6
- package/dist/updates/install/update-extraction.js +28 -8
- package/dist/updates/install/update-handoff-plan.d.ts +0 -1
- package/dist/updates/install/update-handoff-plan.js +3 -4
- package/dist/updates/install/update-swap-stage.js +1 -6
- package/dist/updates/install/update-swap.d.ts +5 -2
- package/dist/updates/install/update-swap.js +193 -72
- package/dist/updates/launch/helper-exit-wait.d.ts +6 -0
- package/dist/updates/launch/helper-exit-wait.js +18 -0
- package/dist/updates/launch/packaged-update-startup.js +8 -6
- package/dist/updates/launch/update-launch-gate.js +7 -14
- package/dist/updates/locks/stable-file.js +4 -1
- package/dist/updates/locks/update-helper-presence.d.ts +12 -0
- package/dist/updates/locks/update-helper-presence.js +27 -0
- package/dist/updates/retention/retention-cleanup.js +10 -9
- package/dist/updates/retention/retention-maintenance.d.ts +40 -0
- package/dist/updates/retention/retention-maintenance.js +95 -0
- package/dist/updates/retention/retention-prune-progress.js +4 -5
- package/dist/updates/retention/retirement-inventory.d.ts +13 -0
- package/dist/updates/retention/retirement-inventory.js +39 -31
- package/dist/updates/retention/retirement-records.d.ts +1 -4
- package/dist/updates/retention/retirement-records.js +18 -32
- package/dist/updates/retention/update-retention-marker.d.ts +4 -0
- package/dist/updates/retention/update-retention-marker.js +9 -14
- package/dist/updates/retention/update-retirement.d.ts +12 -0
- package/dist/updates/retention/update-retirement.js +59 -31
- package/dist/updates/update-adapter.d.ts +1 -23
- package/dist/updates/update-adapter.js +31 -24
- package/dist/updates/update-channel-store.d.ts +2 -1
- package/dist/updates/update-channel-store.js +6 -4
- package/dist/updates/update-manager.js +2 -2
- package/dist/updates/update-services.d.ts +1 -1
- package/dist/updates/update-services.js +9 -4
- package/dist/updates/update-state-store.d.ts +0 -2
- package/dist/updates/update-state-store.js +5 -12
- package/dist/updates/update-state.d.ts +6 -10
- package/dist/updates/update-state.js +1 -1
- package/dist/views/app-help.d.ts +1 -1
- package/dist/views/app-help.js +1 -3
- package/dist/views/appearance-surface.js +15 -8
- package/dist/views/update-surface.d.ts +1 -3
- package/dist/views/update-surface.js +2 -2
- package/package.json +18 -16
- package/src/app/application.tsx +13 -6
- package/src/appearance/appearance-host.tsx +17 -7
- package/src/appearance/appearance-preferences.ts +0 -1
- package/src/appearance/custom-theme-import.ts +99 -26
- package/src/appearance/custom-theme-library.ts +3 -2
- package/src/appearance/theme-file-importer.ts +3 -2
- package/src/appearance/theme-library-mutation.ts +20 -8
- package/src/appearance/theme-library-schema.ts +7 -0
- package/src/appearance/theme-library-store.ts +41 -26
- package/src/desktop/client-assets.ts +27 -12
- package/src/shell/app-shell.tsx +33 -13
- package/src/shell/app-utilities.tsx +7 -1
- package/src/shell/poll.ts +125 -0
- package/src/updates/feed/release-version.ts +11 -3
- package/src/updates/update-adapter.ts +27 -44
- package/src/updates/update-state.ts +7 -13
- package/src/views/app-help.tsx +1 -1
- package/src/views/appearance-surface.tsx +36 -8
- package/src/views/update-surface.tsx +0 -4
- package/templates/application/.github/workflows/release-assets.yml +2 -2
- package/templates/application/README.md +3 -3
- package/dist/native/cef-helper-download.d.ts +0 -1
- package/dist/native/cef-helper-download.js +0 -35
- package/src/desktop/client-response-lifecycle.ts +0 -305
|
@@ -17,8 +17,7 @@ function errorCode(error) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// src/updates/helper/update-helper.ts
|
|
20
|
-
import {
|
|
21
|
-
import { lstat as lstat3, open as open7, realpath as realpath2 } from "fs/promises";
|
|
20
|
+
import { lstat as lstat4, realpath as realpath2, rm as rm2 } from "fs/promises";
|
|
22
21
|
import { join as join9 } from "path";
|
|
23
22
|
|
|
24
23
|
// src/updates/install/update-marker.ts
|
|
@@ -308,8 +307,8 @@ async function waitForUpdateProcesses(options) {
|
|
|
308
307
|
|
|
309
308
|
// src/updates/install/update-swap.ts
|
|
310
309
|
import { createHash } from "crypto";
|
|
311
|
-
import { constants as
|
|
312
|
-
import { lstat as
|
|
310
|
+
import { constants as constants6 } from "fs";
|
|
311
|
+
import { lstat as lstat3, open as open6, readdir, readFile as readFile4, readlink } from "fs/promises";
|
|
313
312
|
import { basename as basename2, dirname as dirname3, join as join6 } from "path";
|
|
314
313
|
|
|
315
314
|
// src/native/native-rename.ts
|
|
@@ -405,8 +404,8 @@ async function probeDirectoryExchange(parent, exchange = exchangeDirectories) {
|
|
|
405
404
|
|
|
406
405
|
// src/updates/update-state-store.ts
|
|
407
406
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
408
|
-
import { constants as
|
|
409
|
-
import { open as
|
|
407
|
+
import { constants as constants5 } from "fs";
|
|
408
|
+
import { open as open5, rename, unlink as unlink2, writeFile as writeFile3 } from "fs/promises";
|
|
410
409
|
import { join as join5 } from "path";
|
|
411
410
|
|
|
412
411
|
// src/updates/locks/update-lock.ts
|
|
@@ -584,6 +583,13 @@ async function tryAcquireUpdateLock(target) {
|
|
|
584
583
|
return tryAcquireNativeFileLock(updateLockPath(target), "exclusive");
|
|
585
584
|
}
|
|
586
585
|
|
|
586
|
+
// src/updates/feed/release-version.ts
|
|
587
|
+
var MAX_RELEASE_VERSION_LENGTH = 64;
|
|
588
|
+
var RELEASE_VERSION = /^\d+\.\d+\.\d+(?:-dev\.\d+)?$/;
|
|
589
|
+
function isReleaseVersion(value) {
|
|
590
|
+
return typeof value === "string" && value.length <= MAX_RELEASE_VERSION_LENGTH && RELEASE_VERSION.test(value);
|
|
591
|
+
}
|
|
592
|
+
|
|
587
593
|
// src/updates/locks/stable-file.ts
|
|
588
594
|
import { constants as constants3 } from "fs";
|
|
589
595
|
import { lstat, open as open3 } from "fs/promises";
|
|
@@ -615,7 +621,11 @@ async function readSmallStateFile(path, maximum, message) {
|
|
|
615
621
|
const info = await file.stat();
|
|
616
622
|
if (!info.isFile() || info.size < 1 || info.size > maximum || linkFree && (linkFree.dev !== info.dev || linkFree.ino !== info.ino))
|
|
617
623
|
throw new Error(message);
|
|
618
|
-
const
|
|
624
|
+
const bytes = Buffer.allocUnsafe(info.size + 1);
|
|
625
|
+
const { bytesRead } = await file.read(bytes, 0, bytes.length, 0);
|
|
626
|
+
if (bytesRead !== info.size)
|
|
627
|
+
throw new Error(message);
|
|
628
|
+
const text = bytes.toString("utf8", 0, bytesRead);
|
|
619
629
|
if (Buffer.byteLength(text) !== info.size)
|
|
620
630
|
throw new Error(message);
|
|
621
631
|
return text;
|
|
@@ -624,6 +634,28 @@ async function readSmallStateFile(path, maximum, message) {
|
|
|
624
634
|
}
|
|
625
635
|
}
|
|
626
636
|
|
|
637
|
+
// src/shared/file-system.ts
|
|
638
|
+
import { constants as constants4 } from "fs";
|
|
639
|
+
import { lstat as lstat2, open as open4, readFile as readFile3 } from "fs/promises";
|
|
640
|
+
async function pathExists(path) {
|
|
641
|
+
try {
|
|
642
|
+
await lstat2(path);
|
|
643
|
+
return true;
|
|
644
|
+
} catch (error) {
|
|
645
|
+
if (errorCode(error) === "ENOENT")
|
|
646
|
+
return false;
|
|
647
|
+
throw error;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
async function syncDirectory(path) {
|
|
651
|
+
const directory = await open4(path, constants4.O_RDONLY);
|
|
652
|
+
try {
|
|
653
|
+
await directory.sync();
|
|
654
|
+
} finally {
|
|
655
|
+
await directory.close();
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
627
659
|
// src/updates/update-state-store.ts
|
|
628
660
|
class UpdateLockBusyError extends Error {
|
|
629
661
|
constructor() {
|
|
@@ -631,6 +663,9 @@ class UpdateLockBusyError extends Error {
|
|
|
631
663
|
this.name = "UpdateLockBusyError";
|
|
632
664
|
}
|
|
633
665
|
}
|
|
666
|
+
function readUpdateHelperRequestFile(staging) {
|
|
667
|
+
return readSmallStateFile(join5(staging, "request.json"), 65536, "Invalid update helper request");
|
|
668
|
+
}
|
|
634
669
|
async function acquireUpdateLock(target, timeoutMs = 5000) {
|
|
635
670
|
const deadline = performance.now() + timeoutMs;
|
|
636
671
|
while (true) {
|
|
@@ -649,7 +684,7 @@ function parseState(value) {
|
|
|
649
684
|
const candidateTreeIdentity = record.candidateTreeIdentity;
|
|
650
685
|
const candidateTreeDigest = record.candidateTreeDigest;
|
|
651
686
|
const previousTreeIdentity = record.previousTreeIdentity;
|
|
652
|
-
if (record.schema !== 1 || typeof record.generation !== "string" || !isUuid(record.generation) || !["staged", "armed", "swapping", "completed", "retiring", "retired", "failed"].includes(String(record.phase)) ||
|
|
687
|
+
if (record.schema !== 1 || typeof record.generation !== "string" || !isUuid(record.generation) || !["staged", "armed", "swapping", "completed", "retiring", "retired", "failed"].includes(String(record.phase)) || !isReleaseVersion(record.version) || !isReleaseVersion(record.previousVersion) || candidateTreeDigest !== undefined && (typeof candidateTreeDigest !== "string" || !isSha256Hex(candidateTreeDigest)) || candidateTreeIdentity !== undefined && (typeof candidateTreeIdentity !== "object" || candidateTreeIdentity === null || Array.isArray(candidateTreeIdentity) || Object.keys(candidateTreeIdentity).length !== 2 || typeof candidateTreeIdentity.device !== "string" || !/^[1-9]\d{0,19}$/.test(candidateTreeIdentity.device) || typeof candidateTreeIdentity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(candidateTreeIdentity.inode)) || previousTreeIdentity !== undefined && (typeof previousTreeIdentity !== "object" || previousTreeIdentity === null || Array.isArray(previousTreeIdentity) || Object.keys(previousTreeIdentity).length !== 2 || typeof previousTreeIdentity.device !== "string" || !/^[1-9]\d{0,19}$/.test(previousTreeIdentity.device) || typeof previousTreeIdentity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(previousTreeIdentity.inode)) || record.signedRelease !== undefined && (typeof record.signedRelease !== "object" || record.signedRelease === null || Array.isArray(record.signedRelease) || Object.keys(record.signedRelease).length !== 2 || !Object.hasOwn(record.signedRelease, "descriptor") || typeof record.signedRelease.signature !== "string") || record.helperPid !== undefined && (!Number.isSafeInteger(record.helperPid) || record.helperPid < 2) || record.helperOwner !== undefined && (typeof record.helperOwner !== "string" || !isUuid(record.helperOwner)) || record.launchGateOwner !== undefined && (typeof record.launchGateOwner !== "string" || !isUuid(record.launchGateOwner)) || Object.keys(record).some((key) => ![
|
|
653
688
|
"schema",
|
|
654
689
|
"generation",
|
|
655
690
|
"phase",
|
|
@@ -674,14 +709,6 @@ async function readUpdateStageState(staging) {
|
|
|
674
709
|
const text = await readSmallStateFile(join5(staging, "state.json"), 4096, "Invalid update staging state");
|
|
675
710
|
return text === undefined ? undefined : parseState(JSON.parse(text));
|
|
676
711
|
}
|
|
677
|
-
async function syncUpdateStageDirectory(staging) {
|
|
678
|
-
const directory = await open4(staging, constants4.O_RDONLY);
|
|
679
|
-
try {
|
|
680
|
-
await directory.sync();
|
|
681
|
-
} finally {
|
|
682
|
-
await directory.close();
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
712
|
async function writeUpdateStageState(staging, state) {
|
|
686
713
|
await replaceUpdateStageState(staging, state, false);
|
|
687
714
|
}
|
|
@@ -698,7 +725,7 @@ async function replaceUpdateStageState(staging, state, durable) {
|
|
|
698
725
|
let renamed = false;
|
|
699
726
|
try {
|
|
700
727
|
if (durable) {
|
|
701
|
-
const file = await
|
|
728
|
+
const file = await open5(temporary, constants5.O_WRONLY | constants5.O_CREAT | constants5.O_EXCL, 384);
|
|
702
729
|
try {
|
|
703
730
|
await file.writeFile(contents);
|
|
704
731
|
await file.sync();
|
|
@@ -710,7 +737,7 @@ async function replaceUpdateStageState(staging, state, durable) {
|
|
|
710
737
|
await rename(temporary, path);
|
|
711
738
|
renamed = true;
|
|
712
739
|
if (durable)
|
|
713
|
-
await
|
|
740
|
+
await syncDirectory(staging);
|
|
714
741
|
} catch (error) {
|
|
715
742
|
if (!renamed && errorCode(error) !== "EEXIST")
|
|
716
743
|
await unlink2(temporary).catch(() => {});
|
|
@@ -727,7 +754,7 @@ function updateStagingFor(target) {
|
|
|
727
754
|
async function readUpdateTreeVersion(tree) {
|
|
728
755
|
const versionPath = join6(tree, ...process.platform === "darwin" ? ["Contents", "Resources"] : ["Resources"], "version.json");
|
|
729
756
|
try {
|
|
730
|
-
const value = JSON.parse(await
|
|
757
|
+
const value = JSON.parse(await readFile4(versionPath, "utf8"));
|
|
731
758
|
if (typeof value !== "object" || value === null || typeof value.version !== "string")
|
|
732
759
|
return;
|
|
733
760
|
return value.version;
|
|
@@ -741,7 +768,7 @@ function updateTreeIdentityFromStat(info) {
|
|
|
741
768
|
return { device: info.dev.toString(10), inode: info.ino.toString(10) };
|
|
742
769
|
}
|
|
743
770
|
async function readUpdateTreeIdentity(tree) {
|
|
744
|
-
const info = await
|
|
771
|
+
const info = await lstat3(tree, { bigint: true });
|
|
745
772
|
return updateTreeIdentityFromStat(info);
|
|
746
773
|
}
|
|
747
774
|
function sameUpdateTreeIdentity(left, right) {
|
|
@@ -750,14 +777,48 @@ function sameUpdateTreeIdentity(left, right) {
|
|
|
750
777
|
function sameTreeEntrySnapshot(left, right) {
|
|
751
778
|
return left.dev === right.dev && left.ino === right.ino && left.mode === right.mode && left.nlink === right.nlink && left.size === right.size && left.mtimeNs === right.mtimeNs && left.ctimeNs === right.ctimeNs;
|
|
752
779
|
}
|
|
780
|
+
var TREE_DIGEST_CONCURRENCY = 16;
|
|
781
|
+
var TREE_DIGEST_PREFETCH_BYTES = 256 * 1024;
|
|
782
|
+
var TREE_DIGEST_STREAM_BYTES = 1024 * 1024;
|
|
783
|
+
function createTaskLimiter(limit) {
|
|
784
|
+
let active = 0;
|
|
785
|
+
const waiting = [];
|
|
786
|
+
let head = 0;
|
|
787
|
+
return async (task) => {
|
|
788
|
+
if (active < limit)
|
|
789
|
+
active++;
|
|
790
|
+
else
|
|
791
|
+
await new Promise((resolve) => waiting.push(resolve));
|
|
792
|
+
try {
|
|
793
|
+
return await task();
|
|
794
|
+
} finally {
|
|
795
|
+
if (head < waiting.length)
|
|
796
|
+
waiting[head++]();
|
|
797
|
+
else {
|
|
798
|
+
active--;
|
|
799
|
+
waiting.length = head = 0;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
async function readTreeFileBytes(file, buffer, length, position) {
|
|
805
|
+
let offset = 0;
|
|
806
|
+
while (offset < length) {
|
|
807
|
+
const { bytesRead } = await file.read(buffer, offset, length - offset, position + offset);
|
|
808
|
+
if (bytesRead === 0)
|
|
809
|
+
throw new Error("Update tree changed while reading a file");
|
|
810
|
+
offset += bytesRead;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
753
813
|
async function readUpdateTreeDigest(tree, options = {}) {
|
|
754
814
|
const allowHardLinkedFiles = options.allowHardLinkedFiles === true;
|
|
755
815
|
const hash = createHash("sha256");
|
|
756
816
|
hash.update("adea-framework-update-tree\x00v1\x00", "utf8");
|
|
757
|
-
const root = await
|
|
817
|
+
const root = await lstat3(tree, { bigint: true });
|
|
758
818
|
if (!root.isDirectory() || root.isSymbolicLink())
|
|
759
819
|
throw new Error("Update tree is not a real directory");
|
|
760
820
|
const rootDevice = root.dev;
|
|
821
|
+
const limit = createTaskLimiter(TREE_DIGEST_CONCURRENCY);
|
|
761
822
|
let entryCount = 0n;
|
|
762
823
|
const writeRecord = (kind, relative, mode, size, linkTarget) => {
|
|
763
824
|
const name = Buffer.from(relative, "utf8");
|
|
@@ -777,60 +838,138 @@ async function readUpdateTreeDigest(tree, options = {}) {
|
|
|
777
838
|
}
|
|
778
839
|
entryCount++;
|
|
779
840
|
};
|
|
780
|
-
const
|
|
781
|
-
const before = await lstat2(path, { bigint: true });
|
|
782
|
-
if (relative === "" && !sameTreeEntrySnapshot(root, before))
|
|
783
|
-
throw new Error("Update tree root changed before its digest was computed");
|
|
841
|
+
const list = async (path, relative, before) => {
|
|
784
842
|
if (before.dev !== rootDevice)
|
|
785
843
|
throw new Error("Update tree crosses a filesystem device");
|
|
786
|
-
if (before.isSymbolicLink())
|
|
844
|
+
if (before.isSymbolicLink())
|
|
845
|
+
return [{ kind: "symlink", path, relative, before }];
|
|
846
|
+
if (before.isDirectory()) {
|
|
847
|
+
const names = (await limit(() => readdir(path))).map((name) => ({ name, bytes: Buffer.from(name, "utf8") })).toSorted((left, right) => Buffer.compare(left.bytes, right.bytes)).map(({ name }) => name);
|
|
848
|
+
const children = await Promise.all(names.map(async (name) => {
|
|
849
|
+
const childPath = join6(path, name);
|
|
850
|
+
return list(childPath, relative ? `${relative}/${name}` : name, await limit(() => lstat3(childPath, { bigint: true })));
|
|
851
|
+
}));
|
|
852
|
+
return [{ kind: "directory", path, relative, before }, ...children.flat()];
|
|
853
|
+
}
|
|
854
|
+
if (!before.isFile() || before.nlink < 1n || !allowHardLinkedFiles && before.nlink !== 1n || before.size < 0n || before.size > BigInt(Number.MAX_SAFE_INTEGER))
|
|
855
|
+
throw new Error("Update tree contains an unsupported filesystem entry");
|
|
856
|
+
return [{ kind: "file", path, relative, before }];
|
|
857
|
+
};
|
|
858
|
+
const prepare = async (entry) => {
|
|
859
|
+
const { path, before } = entry;
|
|
860
|
+
if (entry.kind === "directory")
|
|
861
|
+
return { kind: "none" };
|
|
862
|
+
if (entry.kind === "symlink") {
|
|
787
863
|
const target = Buffer.from(await readlink(path), "utf8");
|
|
788
|
-
const after = await
|
|
864
|
+
const after = await lstat3(path, { bigint: true });
|
|
789
865
|
if (!sameTreeEntrySnapshot(before, after))
|
|
790
866
|
throw new Error("Update tree changed while reading a symbolic link");
|
|
791
|
-
|
|
792
|
-
return;
|
|
867
|
+
return { kind: "bytes", bytes: target };
|
|
793
868
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
for (const name of names) {
|
|
798
|
-
const child = relative ? `${relative}/${name}` : name;
|
|
799
|
-
await visit(join6(path, name), child);
|
|
800
|
-
}
|
|
801
|
-
const after = await lstat2(path, { bigint: true });
|
|
802
|
-
if (!sameTreeEntrySnapshot(before, after))
|
|
803
|
-
throw new Error("Update tree changed while reading a directory");
|
|
804
|
-
return;
|
|
805
|
-
}
|
|
806
|
-
if (!before.isFile() || before.nlink < 1n || !allowHardLinkedFiles && before.nlink !== 1n || before.size < 0n)
|
|
807
|
-
throw new Error("Update tree contains an unsupported filesystem entry");
|
|
808
|
-
writeRecord("file", relative, before.mode, before.size);
|
|
809
|
-
const noFollow = constants5.O_NOFOLLOW ?? 0;
|
|
810
|
-
const file = await open5(path, constants5.O_RDONLY | noFollow | (constants5.O_NONBLOCK ?? 0));
|
|
869
|
+
const noFollow = constants6.O_NOFOLLOW ?? 0;
|
|
870
|
+
const file = await open6(path, constants6.O_RDONLY | noFollow | (constants6.O_NONBLOCK ?? 0));
|
|
871
|
+
let handedOff = false;
|
|
811
872
|
try {
|
|
812
873
|
const opened = await file.stat({ bigint: true });
|
|
813
874
|
if (!opened.isFile() || !sameTreeEntrySnapshot(before, opened))
|
|
814
875
|
throw new Error("Update tree changed before a file could be read");
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
const result = await file.read(buffer, 0, buffer.length, null);
|
|
819
|
-
if (result.bytesRead === 0)
|
|
820
|
-
break;
|
|
821
|
-
bytesRead += BigInt(result.bytesRead);
|
|
822
|
-
hash.update(buffer.subarray(0, result.bytesRead));
|
|
876
|
+
if (before.size > BigInt(TREE_DIGEST_PREFETCH_BYTES)) {
|
|
877
|
+
handedOff = true;
|
|
878
|
+
return { kind: "stream", file };
|
|
823
879
|
}
|
|
824
|
-
const
|
|
825
|
-
const
|
|
826
|
-
|
|
880
|
+
const size = Number(before.size);
|
|
881
|
+
const bytes = Buffer.allocUnsafe(size);
|
|
882
|
+
await readTreeFileBytes(file, bytes, size, 0);
|
|
883
|
+
if (!sameTreeEntrySnapshot(before, await lstat3(path, { bigint: true })))
|
|
827
884
|
throw new Error("Update tree changed while reading a file");
|
|
885
|
+
return { kind: "bytes", bytes };
|
|
828
886
|
} finally {
|
|
829
|
-
|
|
887
|
+
if (!handedOff)
|
|
888
|
+
await file.close();
|
|
830
889
|
}
|
|
831
890
|
};
|
|
832
|
-
await
|
|
833
|
-
const
|
|
891
|
+
const entries = await list(tree, "", root);
|
|
892
|
+
const pending = [];
|
|
893
|
+
let streamBuffers;
|
|
894
|
+
let started = 0;
|
|
895
|
+
let consumed = 0;
|
|
896
|
+
try {
|
|
897
|
+
for (;consumed < entries.length; consumed++) {
|
|
898
|
+
while (started < entries.length && started < consumed + TREE_DIGEST_CONCURRENCY) {
|
|
899
|
+
const next = prepare(entries[started]);
|
|
900
|
+
next.catch(() => {
|
|
901
|
+
return;
|
|
902
|
+
});
|
|
903
|
+
pending[started++] = next;
|
|
904
|
+
}
|
|
905
|
+
const entry = entries[consumed];
|
|
906
|
+
const prepared = await pending[consumed];
|
|
907
|
+
pending[consumed] = undefined;
|
|
908
|
+
if (entry.kind === "directory") {
|
|
909
|
+
writeRecord("directory", entry.relative, entry.before.mode, 0n);
|
|
910
|
+
continue;
|
|
911
|
+
}
|
|
912
|
+
if (entry.kind === "symlink") {
|
|
913
|
+
if (prepared.kind !== "bytes")
|
|
914
|
+
throw new Error("Update tree entry was not prepared");
|
|
915
|
+
const target = prepared.bytes;
|
|
916
|
+
writeRecord("symlink", entry.relative, entry.before.mode, BigInt(target.length), target);
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
writeRecord("file", entry.relative, entry.before.mode, entry.before.size);
|
|
920
|
+
if (prepared.kind === "bytes") {
|
|
921
|
+
hash.update(prepared.bytes);
|
|
922
|
+
continue;
|
|
923
|
+
}
|
|
924
|
+
if (prepared.kind !== "stream")
|
|
925
|
+
throw new Error("Update tree entry was not prepared");
|
|
926
|
+
const { file } = prepared;
|
|
927
|
+
try {
|
|
928
|
+
streamBuffers ??= [
|
|
929
|
+
Buffer.allocUnsafe(TREE_DIGEST_STREAM_BYTES),
|
|
930
|
+
Buffer.allocUnsafe(TREE_DIGEST_STREAM_BYTES)
|
|
931
|
+
];
|
|
932
|
+
const buffers = streamBuffers;
|
|
933
|
+
const size = Number(entry.before.size);
|
|
934
|
+
const readChunk = async (index, position) => {
|
|
935
|
+
const length = Math.min(TREE_DIGEST_STREAM_BYTES, size - position);
|
|
936
|
+
await readTreeFileBytes(file, buffers[index], length, position);
|
|
937
|
+
return length;
|
|
938
|
+
};
|
|
939
|
+
let position = 0;
|
|
940
|
+
let index = 0;
|
|
941
|
+
let reading = readChunk(index, position);
|
|
942
|
+
while (position < size) {
|
|
943
|
+
const length = await reading;
|
|
944
|
+
const nextPosition = position + length;
|
|
945
|
+
const nextIndex = index === 0 ? 1 : 0;
|
|
946
|
+
if (nextPosition < size)
|
|
947
|
+
reading = readChunk(nextIndex, nextPosition);
|
|
948
|
+
hash.update(buffers[index].subarray(0, length));
|
|
949
|
+
position = nextPosition;
|
|
950
|
+
index = nextIndex;
|
|
951
|
+
}
|
|
952
|
+
if (!sameTreeEntrySnapshot(entry.before, await lstat3(entry.path, { bigint: true })))
|
|
953
|
+
throw new Error("Update tree changed while reading a file");
|
|
954
|
+
} finally {
|
|
955
|
+
await file.close();
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
} catch (error) {
|
|
959
|
+
const unconsumed = await Promise.allSettled(pending.slice(consumed + 1).filter((entry) => entry !== undefined));
|
|
960
|
+
await Promise.all(unconsumed.map((result) => result.status === "fulfilled" && result.value.kind === "stream" ? result.value.file.close().catch(() => {
|
|
961
|
+
return;
|
|
962
|
+
}) : undefined));
|
|
963
|
+
throw error;
|
|
964
|
+
}
|
|
965
|
+
await Promise.all(entries.map(async (entry) => {
|
|
966
|
+
if (entry.kind !== "directory" || entry.relative === "")
|
|
967
|
+
return;
|
|
968
|
+
const after = await limit(() => lstat3(entry.path, { bigint: true }));
|
|
969
|
+
if (!sameTreeEntrySnapshot(entry.before, after))
|
|
970
|
+
throw new Error("Update tree changed while reading a directory");
|
|
971
|
+
}));
|
|
972
|
+
const finalRoot = await lstat3(tree, { bigint: true });
|
|
834
973
|
if (!sameTreeEntrySnapshot(root, finalRoot))
|
|
835
974
|
throw new Error("Update tree changed while its digest was computed");
|
|
836
975
|
const count = Buffer.allocUnsafe(8);
|
|
@@ -844,65 +983,61 @@ function readInstalledUpdateTreeDigest(tree) {
|
|
|
844
983
|
function sameUpdateTreeDigest(left, right) {
|
|
845
984
|
return typeof left === "string" && typeof right === "string" && isSha256Hex(left) && left === right;
|
|
846
985
|
}
|
|
847
|
-
|
|
848
|
-
const directory = await open5(path, constants5.O_RDONLY);
|
|
849
|
-
try {
|
|
850
|
-
await directory.sync();
|
|
851
|
-
} finally {
|
|
852
|
-
await directory.close();
|
|
853
|
-
}
|
|
854
|
-
}
|
|
986
|
+
var TREE_SYNC_CONCURRENCY = 16;
|
|
855
987
|
async function syncUpdateTree(tree) {
|
|
856
|
-
const root = await
|
|
988
|
+
const root = await lstat3(tree);
|
|
857
989
|
if (!root.isDirectory())
|
|
858
990
|
throw new Error("Update tree changed while syncing");
|
|
859
991
|
const rootDevice = root.dev;
|
|
992
|
+
const limit = createTaskLimiter(TREE_SYNC_CONCURRENCY);
|
|
993
|
+
let failure;
|
|
994
|
+
const run = (task) => limit(() => failure ? Promise.reject(failure.error) : task());
|
|
860
995
|
const syncEntry = async (path) => {
|
|
861
|
-
const info = await lstat2(path);
|
|
862
|
-
if (info.isSymbolicLink())
|
|
863
|
-
return;
|
|
864
|
-
if (info.dev !== rootDevice)
|
|
865
|
-
throw new Error("Update tree crosses a filesystem device");
|
|
866
|
-
if (info.isDirectory()) {
|
|
867
|
-
for (const name of await readdir(path))
|
|
868
|
-
await syncEntry(join6(path, name));
|
|
869
|
-
await syncDirectoryPath(path);
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
if (!info.isFile())
|
|
873
|
-
throw new Error("Update tree contains an unsupported filesystem entry");
|
|
874
|
-
const file = await open5(path, constants5.O_RDONLY | (constants5.O_NOFOLLOW ?? 0));
|
|
875
996
|
try {
|
|
876
|
-
const
|
|
877
|
-
if (
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
997
|
+
const info = await run(() => lstat3(path));
|
|
998
|
+
if (info.isSymbolicLink())
|
|
999
|
+
return;
|
|
1000
|
+
if (info.dev !== rootDevice)
|
|
1001
|
+
throw new Error("Update tree crosses a filesystem device");
|
|
1002
|
+
if (info.isDirectory()) {
|
|
1003
|
+
const names = await run(() => readdir(path));
|
|
1004
|
+
const children = await Promise.allSettled(names.map((name) => syncEntry(join6(path, name))));
|
|
1005
|
+
for (const child of children)
|
|
1006
|
+
if (child.status === "rejected")
|
|
1007
|
+
throw child.reason;
|
|
1008
|
+
await run(() => syncDirectory(path));
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
if (!info.isFile())
|
|
1012
|
+
throw new Error("Update tree contains an unsupported filesystem entry");
|
|
1013
|
+
await run(async () => {
|
|
1014
|
+
const file = await open6(path, constants6.O_RDONLY | (constants6.O_NOFOLLOW ?? 0));
|
|
1015
|
+
try {
|
|
1016
|
+
const opened = await file.stat();
|
|
1017
|
+
if (!opened.isFile())
|
|
1018
|
+
throw new Error("Update tree changed while syncing");
|
|
1019
|
+
await file.sync();
|
|
1020
|
+
} finally {
|
|
1021
|
+
await file.close();
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
} catch (error) {
|
|
1025
|
+
failure ??= { error };
|
|
1026
|
+
throw error;
|
|
882
1027
|
}
|
|
883
1028
|
};
|
|
884
|
-
await syncEntry(tree)
|
|
885
|
-
|
|
1029
|
+
await syncEntry(tree).catch(() => {
|
|
1030
|
+
throw failure.error;
|
|
1031
|
+
});
|
|
1032
|
+
const final = await lstat3(tree);
|
|
886
1033
|
if (!final.isDirectory() || final.dev !== rootDevice)
|
|
887
1034
|
throw new Error("Update tree changed while syncing");
|
|
888
1035
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
try {
|
|
892
|
-
await directory.sync();
|
|
893
|
-
} finally {
|
|
894
|
-
await directory.close();
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
async function exists(path) {
|
|
898
|
-
return lstat2(path).then(() => true, (error) => {
|
|
899
|
-
if (errorCode(error) === "ENOENT")
|
|
900
|
-
return false;
|
|
901
|
-
throw error;
|
|
902
|
-
});
|
|
1036
|
+
function syncUpdateTreeParent(target) {
|
|
1037
|
+
return syncDirectory(dirname3(target));
|
|
903
1038
|
}
|
|
904
1039
|
async function assertDirectory(path) {
|
|
905
|
-
const info = await
|
|
1040
|
+
const info = await lstat3(path);
|
|
906
1041
|
if (!info.isDirectory() || info.isSymbolicLink())
|
|
907
1042
|
throw new Error("Update exchange requires real directories");
|
|
908
1043
|
}
|
|
@@ -912,7 +1047,7 @@ async function swapUpdateTreeWhileLocked(options, exchangeOperation = exchangeDi
|
|
|
912
1047
|
throw new Error("Invalid update swap context");
|
|
913
1048
|
const candidate = join6(staging, "candidate");
|
|
914
1049
|
const legacyOld = join6(staging, "old");
|
|
915
|
-
if (await
|
|
1050
|
+
if (await pathExists(legacyOld))
|
|
916
1051
|
throw new Error("A legacy update tree requires recovery before another swap");
|
|
917
1052
|
await assertDirectory(target);
|
|
918
1053
|
await assertDirectory(staging);
|
|
@@ -941,8 +1076,8 @@ async function swapUpdateTreeWhileLocked(options, exchangeOperation = exchangeDi
|
|
|
941
1076
|
|
|
942
1077
|
// src/updates/launch/update-launch-gate.ts
|
|
943
1078
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
944
|
-
import { constants as
|
|
945
|
-
import { open as
|
|
1079
|
+
import { constants as constants7 } from "fs";
|
|
1080
|
+
import { open as open7, rename as rename2, unlink as unlink3 } from "fs/promises";
|
|
946
1081
|
import { basename as basename4, dirname as dirname5, join as join8 } from "path";
|
|
947
1082
|
|
|
948
1083
|
// src/updates/locks/update-instance-lease.ts
|
|
@@ -962,20 +1097,11 @@ async function tryAcquireUpdateInstanceLease(target, mode) {
|
|
|
962
1097
|
}
|
|
963
1098
|
|
|
964
1099
|
// src/updates/launch/update-launch-gate.ts
|
|
965
|
-
var VERSION = /^\d+\.\d+\.\d+(?:-dev\.\d+)?$/;
|
|
966
1100
|
var MAX_GATE_BYTES = 1024;
|
|
967
1101
|
function validateTarget(target) {
|
|
968
1102
|
if (!isCanonicalPath(target))
|
|
969
1103
|
throw new Error("Invalid update launch gate target");
|
|
970
1104
|
}
|
|
971
|
-
async function syncDirectory(directoryPath) {
|
|
972
|
-
const directory = await open6(directoryPath, constants6.O_RDONLY);
|
|
973
|
-
try {
|
|
974
|
-
await directory.sync();
|
|
975
|
-
} finally {
|
|
976
|
-
await directory.close();
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
1105
|
function updateLaunchGatePath(target) {
|
|
980
1106
|
validateTarget(target);
|
|
981
1107
|
return join8(dirname5(target), `.${basename4(target)}.framework-update-launch-gate.json`);
|
|
@@ -1044,7 +1170,7 @@ async function cancelUpdateLaunchGateBeforeTransition(target, helperLiveness, ex
|
|
|
1044
1170
|
if (!sameGate(validated, gate))
|
|
1045
1171
|
return "owner-mismatch";
|
|
1046
1172
|
await unlink3(updateLaunchGatePath(target));
|
|
1047
|
-
await
|
|
1173
|
+
await syncUpdateTreeParent(target);
|
|
1048
1174
|
return "cleared";
|
|
1049
1175
|
} finally {
|
|
1050
1176
|
await transition.release();
|
|
@@ -1061,7 +1187,7 @@ function helperLeaseState(lease, target, owner) {
|
|
|
1061
1187
|
return state;
|
|
1062
1188
|
}
|
|
1063
1189
|
function validateGateInput(gate) {
|
|
1064
|
-
if (typeof gate !== "object" || gate === null || Object.keys(gate).length !== 4 || gate.schema !== 1 || typeof gate.generation !== "string" || !isUuid(gate.generation) || typeof gate.version !== "string" || !
|
|
1190
|
+
if (typeof gate !== "object" || gate === null || Object.keys(gate).length !== 4 || gate.schema !== 1 || typeof gate.generation !== "string" || !isUuid(gate.generation) || typeof gate.version !== "string" || !isReleaseVersion(gate.version) || typeof gate.owner !== "string" || !isUuid(gate.owner))
|
|
1065
1191
|
throw new Error("Invalid update launch gate");
|
|
1066
1192
|
return Object.freeze({
|
|
1067
1193
|
schema: 1,
|
|
@@ -1119,7 +1245,7 @@ async function publishUpdateLaunchGate(target, helperLiveness, input, persistOwn
|
|
|
1119
1245
|
const temporary = join8(dirname5(path), `.${basename4(path)}.${gate.generation}.${randomUUID4()}.tmp`);
|
|
1120
1246
|
let renamed = false;
|
|
1121
1247
|
try {
|
|
1122
|
-
const file = await
|
|
1248
|
+
const file = await open7(temporary, constants7.O_WRONLY | constants7.O_CREAT | constants7.O_EXCL, 384);
|
|
1123
1249
|
try {
|
|
1124
1250
|
await file.writeFile(JSON.stringify(gate) + `
|
|
1125
1251
|
`);
|
|
@@ -1129,7 +1255,7 @@ async function publishUpdateLaunchGate(target, helperLiveness, input, persistOwn
|
|
|
1129
1255
|
}
|
|
1130
1256
|
await rename2(temporary, path);
|
|
1131
1257
|
renamed = true;
|
|
1132
|
-
await
|
|
1258
|
+
await syncUpdateTreeParent(target);
|
|
1133
1259
|
} catch (error) {
|
|
1134
1260
|
if (!renamed)
|
|
1135
1261
|
await unlink3(temporary).catch(() => {});
|
|
@@ -1173,7 +1299,7 @@ async function clearOwnedUpdateLaunchGate(target, expected, transitionCompleted,
|
|
|
1173
1299
|
if (!sameGate(verified, gate))
|
|
1174
1300
|
return "ownership-mismatch";
|
|
1175
1301
|
await unlink3(updateLaunchGatePath(target));
|
|
1176
|
-
await
|
|
1302
|
+
await syncUpdateTreeParent(target);
|
|
1177
1303
|
return "cleared";
|
|
1178
1304
|
} finally {
|
|
1179
1305
|
await lock.release();
|
|
@@ -1358,22 +1484,30 @@ async function waitForUpdateLaunchGateWriter(target, expected, options) {
|
|
|
1358
1484
|
}
|
|
1359
1485
|
|
|
1360
1486
|
// src/updates/helper/update-helper.ts
|
|
1487
|
+
var UPDATE_HELPER_ARTIFACTS = [
|
|
1488
|
+
"request.json",
|
|
1489
|
+
"helper-armed",
|
|
1490
|
+
"helper-ready",
|
|
1491
|
+
"cancel.json",
|
|
1492
|
+
"cancel-ack.json",
|
|
1493
|
+
"helper"
|
|
1494
|
+
];
|
|
1495
|
+
var KNOWN_STAGING_ENTRIES = new Set([
|
|
1496
|
+
"candidate",
|
|
1497
|
+
"state.json",
|
|
1498
|
+
...UPDATE_HELPER_ARTIFACTS
|
|
1499
|
+
]);
|
|
1361
1500
|
function parseUpdateHelperRequest(value) {
|
|
1362
1501
|
const data = value;
|
|
1363
|
-
if (typeof value !== "object" || value === null || Array.isArray(value) || data.schema !== 1 && data.schema !== 2 && data.schema !== 3 || !isCanonicalPath(data.target) || !["macos-arm64", "windows-x64", "linux-x64", "linux-arm64"].includes(data.platform) || typeof data.version !== "string" ||
|
|
1502
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || data.schema !== 1 && data.schema !== 2 && data.schema !== 3 || !isCanonicalPath(data.target) || !["macos-arm64", "windows-x64", "linux-x64", "linux-arm64"].includes(data.platform) || typeof data.version !== "string" || !isReleaseVersion(data.version) || !Array.isArray(data.processes) || data.schema === 2 && (typeof data.generation !== "string" || !/^[0-9a-f-]{36}$/i.test(data.generation) || data.helperOwner !== undefined && (typeof data.helperOwner !== "string" || !/^[0-9a-f-]{36}$/i.test(data.helperOwner))) || data.schema === 3 && (typeof data.generation !== "string" || !isUuid(data.generation) || typeof data.helperOwner !== "string" || !isUuid(data.helperOwner)) || !Number.isSafeInteger(data.processTimeoutMs) || data.processTimeoutMs < 1 || data.processTimeoutMs > 120000)
|
|
1364
1503
|
throw new Error("Invalid update helper request");
|
|
1365
1504
|
return Object.freeze(data);
|
|
1366
1505
|
}
|
|
1367
1506
|
async function readRequest(staging) {
|
|
1368
|
-
const
|
|
1369
|
-
if (
|
|
1507
|
+
const text = await readUpdateHelperRequestFile(staging);
|
|
1508
|
+
if (text === undefined)
|
|
1370
1509
|
throw new Error("Invalid update helper request");
|
|
1371
|
-
|
|
1372
|
-
try {
|
|
1373
|
-
return parseUpdateHelperRequest(JSON.parse(await file.readFile("utf8")));
|
|
1374
|
-
} finally {
|
|
1375
|
-
await file.close();
|
|
1376
|
-
}
|
|
1510
|
+
return parseUpdateHelperRequest(JSON.parse(text));
|
|
1377
1511
|
}
|
|
1378
1512
|
async function cancellationRequested(staging, generation, helperOwner) {
|
|
1379
1513
|
const value = await readUpdateMarker(staging, "cancel.json");
|
|
@@ -1396,16 +1530,6 @@ async function acknowledgeUpdateCancellation(staging, request) {
|
|
|
1396
1530
|
...request.schema === 3 ? { launchGateOwner: current.launchGateOwner } : {}
|
|
1397
1531
|
});
|
|
1398
1532
|
}
|
|
1399
|
-
async function updatePathExists(path) {
|
|
1400
|
-
try {
|
|
1401
|
-
await lstat3(path);
|
|
1402
|
-
return true;
|
|
1403
|
-
} catch (error) {
|
|
1404
|
-
if (errorCode(error) === "ENOENT")
|
|
1405
|
-
return false;
|
|
1406
|
-
throw error;
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
1533
|
async function runUpdateHelper(options) {
|
|
1410
1534
|
const hasBoundIdentity = options.target !== undefined || options.generation !== undefined || options.helperOwner !== undefined;
|
|
1411
1535
|
if (hasBoundIdentity) {
|
|
@@ -1415,7 +1539,7 @@ async function runUpdateHelper(options) {
|
|
|
1415
1539
|
if (!liveness)
|
|
1416
1540
|
throw new Error("Update helper liveness is already owned");
|
|
1417
1541
|
try {
|
|
1418
|
-
const stagingInfo = await
|
|
1542
|
+
const stagingInfo = await lstat4(options.staging);
|
|
1419
1543
|
if (!stagingInfo.isDirectory() || stagingInfo.isSymbolicLink() || await realpath2(options.staging) !== options.staging)
|
|
1420
1544
|
throw new Error("Invalid update staging directory");
|
|
1421
1545
|
const request = await readRequest(options.staging);
|
|
@@ -1515,7 +1639,7 @@ async function runUpdateHelperWithRequest(options, request, binding, helperLiven
|
|
|
1515
1639
|
const current = await readUpdateStageState(options.staging).catch(() => {
|
|
1516
1640
|
return;
|
|
1517
1641
|
});
|
|
1518
|
-
if (current?.phase === "armed" && request.schema === 2 && request.generation && request.helperOwner && await
|
|
1642
|
+
if (current?.phase === "armed" && request.schema === 2 && request.generation && request.helperOwner && await pathExists(join9(options.staging, "cancel.json")).catch(() => false))
|
|
1519
1643
|
throw new Error("Update helper could not acknowledge cancellation before the install transition");
|
|
1520
1644
|
} finally {
|
|
1521
1645
|
await swapLock.release();
|
|
@@ -73,7 +73,6 @@ function createChannelUpdateManager(options) {
|
|
|
73
73
|
});
|
|
74
74
|
try {
|
|
75
75
|
const channel = await options.store.read();
|
|
76
|
-
if (!isUpdateChannel(channel)) throw new Error("Invalid update channel");
|
|
77
76
|
const manager = createUpdateManager({
|
|
78
77
|
currentVersion: options.currentVersion,
|
|
79
78
|
trust: {
|