@adea-ai/app-framework 0.31.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -11
- package/dist/app/create-application.js +4 -3
- package/dist/app/serial-queue.d.ts +5 -0
- package/dist/app/serial-queue.js +14 -0
- package/dist/app/value-guards.d.ts +15 -0
- package/dist/app/value-guards.js +29 -0
- package/dist/ci/toolchain-identity.js +1 -1
- package/dist/desktop/channel-proof.js +2 -1
- package/dist/desktop/client-asset-stream.js +6 -12
- package/dist/desktop/desktop-host.d.ts +25 -5
- package/dist/desktop/desktop-host.js +75 -20
- package/dist/framework-source.json +1 -1
- package/dist/installer/command-artifact.js +4 -3
- package/dist/installer/command-qualification-command.js +6 -5
- package/dist/installer/hosted-runner.d.ts +9 -2
- package/dist/installer/hosted-runner.js +18 -5
- package/dist/installer/installed-payload.js +20 -46
- package/dist/installer/installer-archive.d.ts +33 -0
- package/dist/installer/installer-archive.js +116 -0
- package/dist/installer/installer-ci-bootstrap.js +10 -6
- package/dist/installer/installer-extraction.js +54 -120
- package/dist/installer/installer-identity.js +33 -111
- package/dist/installer/installer-observation.js +3 -2
- package/dist/installer/installer-process-cleanup.js +7 -46
- package/dist/installer/installer-qualification-command.js +6 -5
- package/dist/installer/installer-upgrade-command.js +5 -5
- package/dist/installer/installer-worker-guard.js +2 -1
- package/dist/native/canonical-path.d.ts +5 -0
- package/dist/native/canonical-path.js +10 -0
- package/dist/native/cef-helper.js +5 -4
- package/dist/native/electrobun-source-patch.js +3 -2
- package/dist/native/{directory-exchange.d.ts → native-rename.d.ts} +2 -0
- package/dist/native/native-rename.js +126 -0
- package/dist/native/native-secret-store.js +2 -6
- package/dist/native/native-utilities.js +4 -4
- package/dist/native/posix-launcher-build.js +1 -1
- package/dist/native/posix-tree-removal.js +2 -2
- package/dist/native/windows-process.d.ts +9 -0
- package/dist/native/windows-process.js +60 -0
- package/dist/release/feed-release-cut.js +2 -1
- package/dist/release/framework-package-publish.js +1 -1
- package/dist/release/framework-update-lock.js +2 -1
- package/dist/release/github-cli.d.ts +18 -0
- package/dist/release/github-cli.js +13 -1
- package/dist/release/github-release-cut.js +3 -2
- package/dist/release/github-release-provenance.js +2 -1
- package/dist/release/github-release-publisher.js +2 -1
- package/dist/release/local-provenance.js +3 -2
- package/dist/release/local-release.js +6 -6
- package/dist/release/qualification-run.d.ts +25 -0
- package/dist/release/qualification-run.js +43 -0
- package/dist/release/release-artifact.js +3 -11
- package/dist/release/release-assets-plan.js +16 -6
- package/dist/release/release-config.js +14 -14
- package/dist/release/release-cut-command.js +14 -4
- package/dist/release/release-cut.js +3 -2
- package/dist/release/release-descriptor-staging.js +13 -27
- package/dist/release/release-finalize.js +2 -1
- package/dist/release/release-publication.js +3 -11
- package/dist/release/release-publish-command.js +15 -6
- package/dist/release/release-qualification.js +3 -2
- package/dist/release/retained-release-build.js +12 -12
- package/dist/update-helper.bundle.js +250 -190
- package/dist/updates/desktop-updater.js +53 -58
- package/dist/updates/packaged-launch-admission.js +3 -2
- package/dist/updates/packaged-release-config.js +6 -5
- package/dist/updates/release-feed.js +9 -9
- package/dist/updates/signed-release.js +5 -5
- package/dist/updates/stable-file.d.ts +18 -0
- package/dist/updates/stable-file.js +54 -1
- package/dist/updates/update-adapter.d.ts +2 -13
- package/dist/updates/update-arm.js +7 -5
- package/dist/updates/update-channel-store.js +7 -9
- package/dist/updates/update-discovery.js +30 -34
- package/dist/updates/update-download-cleanup.js +2 -1
- package/dist/updates/update-download.js +2 -4
- package/dist/updates/update-extraction.js +1 -1
- package/dist/updates/update-generation-lease.js +4 -3
- package/dist/updates/update-handoff-plan.js +3 -2
- package/dist/updates/update-helper.js +8 -6
- package/dist/updates/update-instance-lease.js +3 -2
- package/dist/updates/update-launch-gate.js +12 -25
- package/dist/updates/update-launch.js +3 -2
- package/dist/updates/update-lock.js +3 -2
- package/dist/updates/update-marker.js +3 -2
- package/dist/updates/update-process-fence.js +10 -39
- package/dist/updates/update-process-liveness.js +2 -1
- package/dist/updates/update-resume.js +26 -22
- package/dist/updates/update-retention-marker.js +7 -5
- package/dist/updates/update-retention-plan.js +2 -2
- package/dist/updates/update-retirement.js +40 -39
- package/dist/updates/update-state-store.js +29 -37
- package/dist/updates/update-state.d.ts +8 -3
- package/dist/updates/update-swap-stage.js +6 -5
- package/dist/updates/update-swap.d.ts +1 -1
- package/dist/updates/update-swap.js +8 -6
- package/package.json +4 -12
- package/src/desktop/client-asset-stream.ts +6 -12
- package/src/updates/update-adapter.ts +2 -14
- package/src/updates/update-state.ts +11 -2
- package/dist/native/directory-exchange.js +0 -90
- package/dist/native/exclusive-rename.d.ts +0 -2
- package/dist/native/exclusive-rename.js +0 -52
- package/dist/release/retention-dry-run.d.ts +0 -46
- package/dist/release/retention-dry-run.js +0 -94
- package/dist/updates/update-exclusive-rename.d.ts +0 -3
- package/dist/updates/update-exclusive-rename.js +0 -5
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// src/app/value-guards.ts
|
|
3
|
+
function isRecord(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
var UUID_SOURCE = /[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/.source;
|
|
7
|
+
var UUID = new RegExp(`^${UUID_SOURCE}$`, "i");
|
|
8
|
+
function isUuid(value) {
|
|
9
|
+
return typeof value === "string" && UUID.test(value);
|
|
10
|
+
}
|
|
11
|
+
function isSha256Hex(value) {
|
|
12
|
+
return typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
|
|
13
|
+
}
|
|
14
|
+
function errorCode(error) {
|
|
15
|
+
const code = isRecord(error) || error instanceof Error ? error.code : undefined;
|
|
16
|
+
return typeof code === "string" ? code : undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
2
19
|
// src/updates/update-helper.ts
|
|
3
|
-
import { constants as
|
|
4
|
-
import { lstat as
|
|
5
|
-
import {
|
|
20
|
+
import { constants as constants7 } from "fs";
|
|
21
|
+
import { lstat as lstat2, open as open7, realpath as realpath2 } from "fs/promises";
|
|
22
|
+
import { join as join9 } from "path";
|
|
6
23
|
|
|
7
24
|
// src/updates/update-marker.ts
|
|
8
25
|
import { randomUUID } from "crypto";
|
|
@@ -48,7 +65,7 @@ async function readUpdateMarker(staging, name) {
|
|
|
48
65
|
try {
|
|
49
66
|
file = await open(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
50
67
|
} catch (error) {
|
|
51
|
-
if (error
|
|
68
|
+
if (errorCode(error) === "ENOENT")
|
|
52
69
|
return;
|
|
53
70
|
throw error;
|
|
54
71
|
}
|
|
@@ -67,14 +84,20 @@ async function readUpdateMarker(staging, name) {
|
|
|
67
84
|
|
|
68
85
|
// src/updates/update-launch.ts
|
|
69
86
|
import { spawn } from "child_process";
|
|
70
|
-
import { dirname,
|
|
87
|
+
import { dirname, join as join2 } from "path";
|
|
71
88
|
|
|
72
89
|
// src/updates/launch-environment.ts
|
|
73
90
|
var INHERITED_LAUNCH_LEASE_ENV = "ADEA_INHERITED_LAUNCH_LEASE_FD";
|
|
74
91
|
|
|
92
|
+
// src/native/canonical-path.ts
|
|
93
|
+
import { isAbsolute, resolve } from "path";
|
|
94
|
+
function isCanonicalPath(value) {
|
|
95
|
+
return typeof value === "string" && isAbsolute(value) && resolve(value) === value && !value.includes("\x00");
|
|
96
|
+
}
|
|
97
|
+
|
|
75
98
|
// src/updates/update-launch.ts
|
|
76
99
|
function updateLauncherPath(platform, target) {
|
|
77
|
-
if (
|
|
100
|
+
if (!isCanonicalPath(target))
|
|
78
101
|
throw new Error("Invalid update target");
|
|
79
102
|
if (platform === "macos-arm64")
|
|
80
103
|
return join2(target, "Contents", "MacOS", "launcher");
|
|
@@ -101,10 +124,51 @@ async function launchInstalledApp(platform, target, env = process.env) {
|
|
|
101
124
|
}
|
|
102
125
|
|
|
103
126
|
// src/updates/update-process-fence.ts
|
|
104
|
-
import { dlopen, FFIType, ptr } from "bun:ffi";
|
|
127
|
+
import { dlopen as dlopen2, FFIType as FFIType2, ptr as ptr2 } from "bun:ffi";
|
|
105
128
|
import { readFile, realpath } from "fs/promises";
|
|
106
129
|
import { isAbsolute as isAbsolute2 } from "path";
|
|
107
130
|
|
|
131
|
+
// src/native/windows-process.ts
|
|
132
|
+
import { dlopen, FFIType, ptr } from "bun:ffi";
|
|
133
|
+
var PROCESS_QUERY_LIMITED_INFORMATION = 4096;
|
|
134
|
+
var STILL_ACTIVE = 259;
|
|
135
|
+
var MAX_PATH_CHARS = 32768;
|
|
136
|
+
function kernel32() {
|
|
137
|
+
return dlopen("kernel32.dll", {
|
|
138
|
+
OpenProcess: { args: [FFIType.u32, FFIType.i32, FFIType.u32], returns: FFIType.ptr },
|
|
139
|
+
GetExitCodeProcess: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
140
|
+
QueryFullProcessImageNameW: {
|
|
141
|
+
args: [FFIType.ptr, FFIType.u32, FFIType.ptr, FFIType.ptr],
|
|
142
|
+
returns: FFIType.i32
|
|
143
|
+
},
|
|
144
|
+
CloseHandle: { args: [FFIType.ptr], returns: FFIType.i32 }
|
|
145
|
+
}).symbols;
|
|
146
|
+
}
|
|
147
|
+
var symbols;
|
|
148
|
+
function windowsProcessImage(pid, options) {
|
|
149
|
+
symbols ??= kernel32();
|
|
150
|
+
const handle = symbols.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid);
|
|
151
|
+
if (!handle)
|
|
152
|
+
return "missing";
|
|
153
|
+
try {
|
|
154
|
+
if (options.requireRunning) {
|
|
155
|
+
const code = new Uint32Array(1);
|
|
156
|
+
if (!symbols.GetExitCodeProcess(handle, ptr(code)))
|
|
157
|
+
throw new Error("Unable to query process state");
|
|
158
|
+
if (code[0] !== STILL_ACTIVE)
|
|
159
|
+
return "missing";
|
|
160
|
+
}
|
|
161
|
+
const name = new Uint16Array(MAX_PATH_CHARS), length = new Uint32Array([MAX_PATH_CHARS]);
|
|
162
|
+
if (!symbols.QueryFullProcessImageNameW(handle, 0, ptr(name), ptr(length)))
|
|
163
|
+
throw new Error("Unable to query process executable");
|
|
164
|
+
if (!length[0] || length[0] >= MAX_PATH_CHARS)
|
|
165
|
+
throw new Error("Invalid process executable path");
|
|
166
|
+
return Buffer.from(name.buffer, 0, length[0] * 2).toString("utf16le");
|
|
167
|
+
} finally {
|
|
168
|
+
symbols.CloseHandle(handle);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
108
172
|
// src/updates/linux-process-state.ts
|
|
109
173
|
function linuxProcessIsExited(stat, pid) {
|
|
110
174
|
const prefix = `${pid} (`;
|
|
@@ -132,7 +196,7 @@ function isProcessRunning(pid) {
|
|
|
132
196
|
process.kill(pid, 0);
|
|
133
197
|
return true;
|
|
134
198
|
} catch (error) {
|
|
135
|
-
if (error
|
|
199
|
+
if (errorCode(error) === "ESRCH")
|
|
136
200
|
return false;
|
|
137
201
|
throw new Error("Cannot inspect update process", { cause: error });
|
|
138
202
|
}
|
|
@@ -146,7 +210,7 @@ async function hasVerifiedProcessExited(pid) {
|
|
|
146
210
|
try {
|
|
147
211
|
stat = await readFile(`/proc/${pid}/stat`, "utf8");
|
|
148
212
|
} catch (error) {
|
|
149
|
-
const code = error
|
|
213
|
+
const code = errorCode(error);
|
|
150
214
|
if ((code === "ENOENT" || code === "ESRCH") && !isProcessRunning(pid))
|
|
151
215
|
return true;
|
|
152
216
|
throw new Error("Cannot inspect update process", { cause: error });
|
|
@@ -157,12 +221,12 @@ async function executable(pid) {
|
|
|
157
221
|
if (process.platform === "linux")
|
|
158
222
|
return realpath(`/proc/${pid}/exe`);
|
|
159
223
|
if (process.platform === "darwin") {
|
|
160
|
-
const library =
|
|
161
|
-
proc_pidpath: { args: [
|
|
224
|
+
const library = dlopen2("/usr/lib/libproc.dylib", {
|
|
225
|
+
proc_pidpath: { args: [FFIType2.i32, FFIType2.ptr, FFIType2.u32], returns: FFIType2.i32 }
|
|
162
226
|
});
|
|
163
227
|
try {
|
|
164
228
|
const buffer = Buffer.alloc(4096);
|
|
165
|
-
const count = library.symbols.proc_pidpath(pid,
|
|
229
|
+
const count = library.symbols.proc_pidpath(pid, ptr2(buffer), buffer.length);
|
|
166
230
|
if (count <= 0 || count >= buffer.length)
|
|
167
231
|
throw new Error("Cannot inspect update process");
|
|
168
232
|
const end = buffer.indexOf(0);
|
|
@@ -177,33 +241,15 @@ async function executable(pid) {
|
|
|
177
241
|
}
|
|
178
242
|
}
|
|
179
243
|
if (process.platform === "win32") {
|
|
180
|
-
|
|
181
|
-
OpenProcess: { args: [FFIType.u32, FFIType.i32, FFIType.u32], returns: FFIType.ptr },
|
|
182
|
-
QueryFullProcessImageNameW: {
|
|
183
|
-
args: [FFIType.ptr, FFIType.u32, FFIType.ptr, FFIType.ptr],
|
|
184
|
-
returns: FFIType.i32
|
|
185
|
-
},
|
|
186
|
-
CloseHandle: { args: [FFIType.ptr], returns: FFIType.i32 }
|
|
187
|
-
});
|
|
244
|
+
let image;
|
|
188
245
|
try {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
try {
|
|
193
|
-
const buffer = Buffer.alloc(32768 * 2), length = Buffer.alloc(4);
|
|
194
|
-
length.writeUInt32LE(32768);
|
|
195
|
-
if (!library.symbols.QueryFullProcessImageNameW(handle, 0, ptr(buffer), ptr(length)))
|
|
196
|
-
throw new Error("Cannot inspect update process");
|
|
197
|
-
const count = length.readUInt32LE();
|
|
198
|
-
if (!count || count >= 32768)
|
|
199
|
-
throw new Error("Invalid update process path");
|
|
200
|
-
return await realpath(buffer.subarray(0, count * 2).toString("utf16le"));
|
|
201
|
-
} finally {
|
|
202
|
-
library.symbols.CloseHandle(handle);
|
|
203
|
-
}
|
|
204
|
-
} finally {
|
|
205
|
-
library.close();
|
|
246
|
+
image = windowsProcessImage(pid, { requireRunning: false });
|
|
247
|
+
} catch (error) {
|
|
248
|
+
throw new Error("Cannot inspect update process", { cause: error });
|
|
206
249
|
}
|
|
250
|
+
if (image === "missing")
|
|
251
|
+
throw new Error("Cannot open update process");
|
|
252
|
+
return realpath(image);
|
|
207
253
|
}
|
|
208
254
|
throw new Error("Unsupported update process platform");
|
|
209
255
|
}
|
|
@@ -262,50 +308,68 @@ async function waitForUpdateProcesses(options) {
|
|
|
262
308
|
|
|
263
309
|
// src/updates/update-swap.ts
|
|
264
310
|
import { createHash } from "crypto";
|
|
265
|
-
import { constants as
|
|
266
|
-
import { lstat
|
|
267
|
-
import { basename as basename2, dirname as dirname3,
|
|
311
|
+
import { constants as constants5 } from "fs";
|
|
312
|
+
import { lstat, open as open5, readdir, readFile as readFile3, readlink } from "fs/promises";
|
|
313
|
+
import { basename as basename2, dirname as dirname3, join as join6 } from "path";
|
|
268
314
|
|
|
269
|
-
// src/native/
|
|
315
|
+
// src/native/native-rename.ts
|
|
270
316
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
271
317
|
import { mkdir, readFile as readFile2, rm, writeFile as writeFile2 } from "fs/promises";
|
|
272
|
-
import { dlopen as
|
|
273
|
-
import {
|
|
274
|
-
var
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
318
|
+
import { dlopen as dlopen3, FFIType as FFIType3, ptr as ptr3 } from "bun:ffi";
|
|
319
|
+
import { join as join3 } from "path";
|
|
320
|
+
var DARWIN_RENAME_SWAP = 2;
|
|
321
|
+
var LINUX_RENAME_EXCHANGE = 2;
|
|
322
|
+
var AT_FDCWD = -100;
|
|
323
|
+
var library;
|
|
324
|
+
function renameLibrary() {
|
|
325
|
+
if (library)
|
|
326
|
+
return library;
|
|
278
327
|
if (process.platform === "darwin") {
|
|
279
|
-
const
|
|
280
|
-
renamex_np: { args: [
|
|
328
|
+
const { symbols } = dlopen3("libSystem.B.dylib", {
|
|
329
|
+
renamex_np: { args: [FFIType3.ptr, FFIType3.ptr, FFIType3.u32], returns: FFIType3.i32 }
|
|
281
330
|
});
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
} finally {
|
|
287
|
-
library.close();
|
|
288
|
-
}
|
|
331
|
+
library = {
|
|
332
|
+
platform: "darwin",
|
|
333
|
+
rename: (from, to, flags) => symbols.renamex_np(ptr3(from), ptr3(to), flags) === 0
|
|
334
|
+
};
|
|
289
335
|
} else if (process.platform === "linux") {
|
|
290
|
-
const
|
|
336
|
+
const { symbols } = dlopen3("libc.so.6", {
|
|
291
337
|
renameat2: {
|
|
292
|
-
args: [
|
|
293
|
-
returns:
|
|
338
|
+
args: [FFIType3.i32, FFIType3.ptr, FFIType3.i32, FFIType3.ptr, FFIType3.u32],
|
|
339
|
+
returns: FFIType3.i32
|
|
294
340
|
}
|
|
295
341
|
});
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
342
|
+
library = {
|
|
343
|
+
platform: "linux",
|
|
344
|
+
rename: (from, to, flags) => symbols.renameat2(AT_FDCWD, ptr3(from), AT_FDCWD, ptr3(to), flags) === 0
|
|
345
|
+
};
|
|
346
|
+
} else if (process.platform === "win32") {
|
|
347
|
+
const { symbols } = dlopen3("kernel32.dll", {
|
|
348
|
+
MoveFileW: { args: [FFIType3.ptr, FFIType3.ptr], returns: FFIType3.i32 }
|
|
349
|
+
});
|
|
350
|
+
library = { platform: "win32", move: (from, to) => symbols.MoveFileW(ptr3(from), ptr3(to)) !== 0 };
|
|
351
|
+
} else
|
|
352
|
+
throw new Error("Unsupported native rename platform");
|
|
353
|
+
return library;
|
|
354
|
+
}
|
|
355
|
+
function renamePaths(source, destination) {
|
|
356
|
+
return isCanonicalPath(source) && isCanonicalPath(destination) && source !== destination;
|
|
357
|
+
}
|
|
358
|
+
var cString = (path) => Buffer.from(path + "\x00");
|
|
359
|
+
function exchangeDirectories(source, destination) {
|
|
360
|
+
if (!renamePaths(source, destination))
|
|
361
|
+
throw new Error("Invalid atomic directory exchange paths");
|
|
362
|
+
if (process.platform !== "darwin" && process.platform !== "linux")
|
|
304
363
|
throw new Error("Atomic directory exchange is unsupported on this platform");
|
|
305
|
-
|
|
364
|
+
const native = renameLibrary();
|
|
365
|
+
if (native.platform === "win32")
|
|
366
|
+
throw new Error("Atomic directory exchange is unsupported on this platform");
|
|
367
|
+
const flags = native.platform === "darwin" ? DARWIN_RENAME_SWAP : LINUX_RENAME_EXCHANGE;
|
|
368
|
+
if (!native.rename(cString(source), cString(destination), flags))
|
|
369
|
+
throw new Error("Atomic directory exchange is unsupported or failed");
|
|
306
370
|
}
|
|
307
371
|
async function probeDirectoryExchange(parent, exchange = exchangeDirectories) {
|
|
308
|
-
if (
|
|
372
|
+
if (!isCanonicalPath(parent))
|
|
309
373
|
throw new Error("Invalid directory exchange probe parent");
|
|
310
374
|
const id = randomUUID2();
|
|
311
375
|
const first = join3(parent, `.framework-exchange-probe-${id}-a`);
|
|
@@ -341,17 +405,17 @@ async function probeDirectoryExchange(parent, exchange = exchangeDirectories) {
|
|
|
341
405
|
|
|
342
406
|
// src/updates/update-state-store.ts
|
|
343
407
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
344
|
-
import { constants as
|
|
345
|
-
import {
|
|
408
|
+
import { constants as constants4 } from "fs";
|
|
409
|
+
import { open as open4, rename, unlink as unlink2, writeFile as writeFile3 } from "fs/promises";
|
|
346
410
|
import { join as join5 } from "path";
|
|
347
411
|
|
|
348
412
|
// src/updates/update-lock.ts
|
|
349
|
-
import { basename, dirname as dirname2,
|
|
413
|
+
import { basename, dirname as dirname2, join as join4 } from "path";
|
|
350
414
|
|
|
351
415
|
// src/updates/native-file-lock.ts
|
|
352
416
|
import { constants as constants2 } from "fs";
|
|
353
417
|
import { open as open2 } from "fs/promises";
|
|
354
|
-
import { dlopen as
|
|
418
|
+
import { dlopen as dlopen4, FFIType as FFIType4, ptr as ptr4, read } from "bun:ffi";
|
|
355
419
|
var LOCK_SH = 1;
|
|
356
420
|
var LOCK_EX = 2;
|
|
357
421
|
var LOCK_NB = 4;
|
|
@@ -431,9 +495,9 @@ function loadPosixLibrary(darwin) {
|
|
|
431
495
|
let failure;
|
|
432
496
|
for (const name of candidates) {
|
|
433
497
|
try {
|
|
434
|
-
return
|
|
435
|
-
flock: { args: [
|
|
436
|
-
[errnoSymbol]: { args: [], returns:
|
|
498
|
+
return dlopen4(name, {
|
|
499
|
+
flock: { args: [FFIType4.i32, FFIType4.i32], returns: FFIType4.i32 },
|
|
500
|
+
[errnoSymbol]: { args: [], returns: FFIType4.ptr }
|
|
437
501
|
});
|
|
438
502
|
} catch (error) {
|
|
439
503
|
failure = error;
|
|
@@ -444,32 +508,32 @@ function loadPosixLibrary(darwin) {
|
|
|
444
508
|
async function tryAcquireWindows(path, mode) {
|
|
445
509
|
if (process.arch !== "x64" && process.arch !== "arm64")
|
|
446
510
|
throw new Error("Unsupported Windows native file lock architecture");
|
|
447
|
-
const library =
|
|
511
|
+
const library = dlopen4("kernel32.dll", {
|
|
448
512
|
CreateFileW: {
|
|
449
513
|
args: [
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
514
|
+
FFIType4.ptr,
|
|
515
|
+
FFIType4.u32,
|
|
516
|
+
FFIType4.u32,
|
|
517
|
+
FFIType4.ptr,
|
|
518
|
+
FFIType4.u32,
|
|
519
|
+
FFIType4.u32,
|
|
520
|
+
FFIType4.u64
|
|
457
521
|
],
|
|
458
|
-
returns:
|
|
522
|
+
returns: FFIType4.u64
|
|
459
523
|
},
|
|
460
524
|
LockFileEx: {
|
|
461
|
-
args: [
|
|
462
|
-
returns:
|
|
525
|
+
args: [FFIType4.u64, FFIType4.u32, FFIType4.u32, FFIType4.u32, FFIType4.u32, FFIType4.ptr],
|
|
526
|
+
returns: FFIType4.i32
|
|
463
527
|
},
|
|
464
528
|
UnlockFileEx: {
|
|
465
|
-
args: [
|
|
466
|
-
returns:
|
|
529
|
+
args: [FFIType4.u64, FFIType4.u32, FFIType4.u32, FFIType4.u32, FFIType4.ptr],
|
|
530
|
+
returns: FFIType4.i32
|
|
467
531
|
},
|
|
468
|
-
CloseHandle: { args: [
|
|
469
|
-
GetLastError: { args: [], returns:
|
|
532
|
+
CloseHandle: { args: [FFIType4.u64], returns: FFIType4.i32 },
|
|
533
|
+
GetLastError: { args: [], returns: FFIType4.u32 }
|
|
470
534
|
});
|
|
471
535
|
const name = Buffer.from(path + "\x00", "utf16le");
|
|
472
|
-
const handle = library.symbols.CreateFileW(
|
|
536
|
+
const handle = library.symbols.CreateFileW(ptr4(name), 3221225472, 3, 0, 4, 128, 0);
|
|
473
537
|
if (handle === 0n || handle === INVALID_HANDLE_VALUE) {
|
|
474
538
|
const error = library.symbols.GetLastError();
|
|
475
539
|
library.close();
|
|
@@ -477,7 +541,7 @@ async function tryAcquireWindows(path, mode) {
|
|
|
477
541
|
}
|
|
478
542
|
const overlapped = Buffer.alloc(32);
|
|
479
543
|
const flags = LOCKFILE_FAIL_IMMEDIATELY | (mode === "exclusive" ? LOCKFILE_EXCLUSIVE_LOCK : 0);
|
|
480
|
-
if (!library.symbols.LockFileEx(handle, flags, 0, 1, 0,
|
|
544
|
+
if (!library.symbols.LockFileEx(handle, flags, 0, 1, 0, ptr4(overlapped))) {
|
|
481
545
|
const error = library.symbols.GetLastError();
|
|
482
546
|
library.symbols.CloseHandle(handle);
|
|
483
547
|
library.close();
|
|
@@ -493,7 +557,7 @@ async function tryAcquireWindows(path, mode) {
|
|
|
493
557
|
acquired = false;
|
|
494
558
|
let failure;
|
|
495
559
|
try {
|
|
496
|
-
if (!library.symbols.UnlockFileEx(handle, 0, 1, 0,
|
|
560
|
+
if (!library.symbols.UnlockFileEx(handle, 0, 1, 0, ptr4(overlapped))) {
|
|
497
561
|
const error = library.symbols.GetLastError();
|
|
498
562
|
failure = new Error("Could not release native file lock (Windows error " + error + ")");
|
|
499
563
|
}
|
|
@@ -512,7 +576,7 @@ async function tryAcquireWindows(path, mode) {
|
|
|
512
576
|
|
|
513
577
|
// src/updates/update-lock.ts
|
|
514
578
|
function updateLockPath(target) {
|
|
515
|
-
if (
|
|
579
|
+
if (!isCanonicalPath(target))
|
|
516
580
|
throw new Error("Invalid update lock target");
|
|
517
581
|
return join4(dirname2(target), `.${basename(target)}.framework-update.lock`);
|
|
518
582
|
}
|
|
@@ -520,6 +584,34 @@ async function tryAcquireUpdateLock(target) {
|
|
|
520
584
|
return tryAcquireNativeFileLock(updateLockPath(target), "exclusive");
|
|
521
585
|
}
|
|
522
586
|
|
|
587
|
+
// src/updates/stable-file.ts
|
|
588
|
+
import { constants as constants3 } from "fs";
|
|
589
|
+
import { open as open3 } from "fs/promises";
|
|
590
|
+
async function readSmallStateFile(path, maximum, message) {
|
|
591
|
+
let file;
|
|
592
|
+
try {
|
|
593
|
+
file = await open3(path, constants3.O_RDONLY | (constants3.O_NOFOLLOW ?? 0) | (constants3.O_NONBLOCK ?? 0));
|
|
594
|
+
} catch (error) {
|
|
595
|
+
const code = errorCode(error);
|
|
596
|
+
if (code === "ENOENT")
|
|
597
|
+
return;
|
|
598
|
+
if (code === "ELOOP" || code === "EMLINK")
|
|
599
|
+
throw new Error(message, { cause: error });
|
|
600
|
+
throw error;
|
|
601
|
+
}
|
|
602
|
+
try {
|
|
603
|
+
const info = await file.stat();
|
|
604
|
+
if (!info.isFile() || info.size < 1 || info.size > maximum)
|
|
605
|
+
throw new Error(message);
|
|
606
|
+
const text = await file.readFile("utf8");
|
|
607
|
+
if (Buffer.byteLength(text) !== info.size)
|
|
608
|
+
throw new Error(message);
|
|
609
|
+
return text;
|
|
610
|
+
} finally {
|
|
611
|
+
await file.close();
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
523
615
|
// src/updates/update-state-store.ts
|
|
524
616
|
class UpdateLockBusyError extends Error {
|
|
525
617
|
constructor() {
|
|
@@ -545,7 +637,7 @@ function parseState(value) {
|
|
|
545
637
|
const candidateTreeIdentity = record.candidateTreeIdentity;
|
|
546
638
|
const candidateTreeDigest = record.candidateTreeDigest;
|
|
547
639
|
const previousTreeIdentity = record.previousTreeIdentity;
|
|
548
|
-
if (record.schema !== 1 || typeof record.generation !== "string" ||
|
|
640
|
+
if (record.schema !== 1 || typeof record.generation !== "string" || !isUuid(record.generation) || !["staged", "armed", "swapping", "completed", "retiring", "retired", "failed"].includes(String(record.phase)) || typeof record.version !== "string" || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(record.version) || typeof record.previousVersion !== "string" || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(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) => ![
|
|
549
641
|
"schema",
|
|
550
642
|
"generation",
|
|
551
643
|
"phase",
|
|
@@ -567,21 +659,11 @@ function parseState(value) {
|
|
|
567
659
|
return Object.freeze(record);
|
|
568
660
|
}
|
|
569
661
|
async function readUpdateStageState(staging) {
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
try {
|
|
573
|
-
info = await lstat(path);
|
|
574
|
-
} catch (error) {
|
|
575
|
-
if (error.code === "ENOENT")
|
|
576
|
-
return;
|
|
577
|
-
throw error;
|
|
578
|
-
}
|
|
579
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > 4096)
|
|
580
|
-
throw new Error("Invalid update staging state");
|
|
581
|
-
return parseState(JSON.parse(await readFile3(path, "utf8")));
|
|
662
|
+
const text = await readSmallStateFile(join5(staging, "state.json"), 4096, "Invalid update staging state");
|
|
663
|
+
return text === undefined ? undefined : parseState(JSON.parse(text));
|
|
582
664
|
}
|
|
583
665
|
async function syncUpdateStageDirectory(staging) {
|
|
584
|
-
const directory = await
|
|
666
|
+
const directory = await open4(staging, constants4.O_RDONLY);
|
|
585
667
|
try {
|
|
586
668
|
await directory.sync();
|
|
587
669
|
} finally {
|
|
@@ -589,39 +671,36 @@ async function syncUpdateStageDirectory(staging) {
|
|
|
589
671
|
}
|
|
590
672
|
}
|
|
591
673
|
async function writeUpdateStageState(staging, state) {
|
|
592
|
-
|
|
593
|
-
throw new Error("Invalid update staging state");
|
|
594
|
-
const path = join5(staging, "state.json");
|
|
595
|
-
const temporary = join5(staging, `.state-${state.generation}-${randomUUID3()}.tmp`);
|
|
596
|
-
await writeFile3(temporary, JSON.stringify(state) + `
|
|
597
|
-
`, { flag: "wx", mode: 384 });
|
|
598
|
-
try {
|
|
599
|
-
await rename(temporary, path);
|
|
600
|
-
} catch (error) {
|
|
601
|
-
await unlink2(temporary).catch(() => {});
|
|
602
|
-
throw error;
|
|
603
|
-
}
|
|
674
|
+
await replaceUpdateStageState(staging, state, false);
|
|
604
675
|
}
|
|
605
676
|
async function writeUpdateStageStateDurably(staging, state) {
|
|
606
|
-
|
|
677
|
+
await replaceUpdateStageState(staging, state, true);
|
|
678
|
+
}
|
|
679
|
+
async function replaceUpdateStageState(staging, state, durable) {
|
|
680
|
+
if (typeof state.generation !== "string" || !isUuid(state.generation))
|
|
607
681
|
throw new Error("Invalid update staging state");
|
|
608
682
|
const path = join5(staging, "state.json");
|
|
609
683
|
const temporary = join5(staging, `.state-${state.generation}-${randomUUID3()}.tmp`);
|
|
684
|
+
const contents = JSON.stringify(state) + `
|
|
685
|
+
`;
|
|
610
686
|
let renamed = false;
|
|
611
687
|
try {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
688
|
+
if (durable) {
|
|
689
|
+
const file = await open4(temporary, constants4.O_WRONLY | constants4.O_CREAT | constants4.O_EXCL, 384);
|
|
690
|
+
try {
|
|
691
|
+
await file.writeFile(contents);
|
|
692
|
+
await file.sync();
|
|
693
|
+
} finally {
|
|
694
|
+
await file.close();
|
|
695
|
+
}
|
|
696
|
+
} else
|
|
697
|
+
await writeFile3(temporary, contents, { flag: "wx", mode: 384 });
|
|
620
698
|
await rename(temporary, path);
|
|
621
699
|
renamed = true;
|
|
622
|
-
|
|
700
|
+
if (durable)
|
|
701
|
+
await syncUpdateStageDirectory(staging);
|
|
623
702
|
} catch (error) {
|
|
624
|
-
if (!renamed)
|
|
703
|
+
if (!renamed && errorCode(error) !== "EEXIST")
|
|
625
704
|
await unlink2(temporary).catch(() => {});
|
|
626
705
|
throw error;
|
|
627
706
|
}
|
|
@@ -629,14 +708,14 @@ async function writeUpdateStageStateDurably(staging, state) {
|
|
|
629
708
|
|
|
630
709
|
// src/updates/update-swap.ts
|
|
631
710
|
function updateStagingFor(target) {
|
|
632
|
-
if (
|
|
711
|
+
if (!isCanonicalPath(target))
|
|
633
712
|
throw new Error("Invalid update target");
|
|
634
713
|
return join6(dirname3(target), `.${basename2(target)}.framework-update`);
|
|
635
714
|
}
|
|
636
715
|
async function readUpdateTreeVersion(tree) {
|
|
637
716
|
const versionPath = join6(tree, ...process.platform === "darwin" ? ["Contents", "Resources"] : ["Resources"], "version.json");
|
|
638
717
|
try {
|
|
639
|
-
const value = JSON.parse(await
|
|
718
|
+
const value = JSON.parse(await readFile3(versionPath, "utf8"));
|
|
640
719
|
if (typeof value !== "object" || value === null || typeof value.version !== "string")
|
|
641
720
|
return;
|
|
642
721
|
return value.version;
|
|
@@ -650,7 +729,7 @@ function updateTreeIdentityFromStat(info) {
|
|
|
650
729
|
return { device: info.dev.toString(10), inode: info.ino.toString(10) };
|
|
651
730
|
}
|
|
652
731
|
async function readUpdateTreeIdentity(tree) {
|
|
653
|
-
const info = await
|
|
732
|
+
const info = await lstat(tree, { bigint: true });
|
|
654
733
|
return updateTreeIdentityFromStat(info);
|
|
655
734
|
}
|
|
656
735
|
function sameUpdateTreeIdentity(left, right) {
|
|
@@ -662,7 +741,7 @@ function sameTreeEntrySnapshot(left, right) {
|
|
|
662
741
|
async function readUpdateTreeDigest(tree) {
|
|
663
742
|
const hash = createHash("sha256");
|
|
664
743
|
hash.update("adea-framework-update-tree\x00v1\x00", "utf8");
|
|
665
|
-
const root = await
|
|
744
|
+
const root = await lstat(tree, { bigint: true });
|
|
666
745
|
if (!root.isDirectory() || root.isSymbolicLink())
|
|
667
746
|
throw new Error("Update tree is not a real directory");
|
|
668
747
|
const rootDevice = root.dev;
|
|
@@ -686,14 +765,14 @@ async function readUpdateTreeDigest(tree) {
|
|
|
686
765
|
entryCount++;
|
|
687
766
|
};
|
|
688
767
|
const visit = async (path, relative) => {
|
|
689
|
-
const before = await
|
|
768
|
+
const before = await lstat(path, { bigint: true });
|
|
690
769
|
if (relative === "" && !sameTreeEntrySnapshot(root, before))
|
|
691
770
|
throw new Error("Update tree root changed before its digest was computed");
|
|
692
771
|
if (before.dev !== rootDevice)
|
|
693
772
|
throw new Error("Update tree crosses a filesystem device");
|
|
694
773
|
if (before.isSymbolicLink()) {
|
|
695
774
|
const target = Buffer.from(await readlink(path), "utf8");
|
|
696
|
-
const after = await
|
|
775
|
+
const after = await lstat(path, { bigint: true });
|
|
697
776
|
if (!sameTreeEntrySnapshot(before, after))
|
|
698
777
|
throw new Error("Update tree changed while reading a symbolic link");
|
|
699
778
|
writeRecord("symlink", relative, before.mode, BigInt(target.length), target);
|
|
@@ -706,7 +785,7 @@ async function readUpdateTreeDigest(tree) {
|
|
|
706
785
|
const child = relative ? `${relative}/${name}` : name;
|
|
707
786
|
await visit(join6(path, name), child);
|
|
708
787
|
}
|
|
709
|
-
const after = await
|
|
788
|
+
const after = await lstat(path, { bigint: true });
|
|
710
789
|
if (!sameTreeEntrySnapshot(before, after))
|
|
711
790
|
throw new Error("Update tree changed while reading a directory");
|
|
712
791
|
return;
|
|
@@ -714,8 +793,8 @@ async function readUpdateTreeDigest(tree) {
|
|
|
714
793
|
if (!before.isFile() || before.nlink !== 1n || before.size < 0n)
|
|
715
794
|
throw new Error("Update tree contains an unsupported filesystem entry");
|
|
716
795
|
writeRecord("file", relative, before.mode, before.size);
|
|
717
|
-
const noFollow =
|
|
718
|
-
const file = await
|
|
796
|
+
const noFollow = constants5.O_NOFOLLOW ?? 0;
|
|
797
|
+
const file = await open5(path, constants5.O_RDONLY | noFollow | (constants5.O_NONBLOCK ?? 0));
|
|
719
798
|
try {
|
|
720
799
|
const opened = await file.stat({ bigint: true });
|
|
721
800
|
if (!opened.isFile() || !sameTreeEntrySnapshot(before, opened))
|
|
@@ -730,7 +809,7 @@ async function readUpdateTreeDigest(tree) {
|
|
|
730
809
|
hash.update(buffer.subarray(0, result.bytesRead));
|
|
731
810
|
}
|
|
732
811
|
const afterOpen = await file.stat({ bigint: true });
|
|
733
|
-
const afterPath = await
|
|
812
|
+
const afterPath = await lstat(path, { bigint: true });
|
|
734
813
|
if (bytesRead !== before.size || !sameTreeEntrySnapshot(opened, afterOpen) || !sameTreeEntrySnapshot(before, afterPath))
|
|
735
814
|
throw new Error("Update tree changed while reading a file");
|
|
736
815
|
} finally {
|
|
@@ -738,7 +817,7 @@ async function readUpdateTreeDigest(tree) {
|
|
|
738
817
|
}
|
|
739
818
|
};
|
|
740
819
|
await visit(tree, "");
|
|
741
|
-
const finalRoot = await
|
|
820
|
+
const finalRoot = await lstat(tree, { bigint: true });
|
|
742
821
|
if (!sameTreeEntrySnapshot(root, finalRoot))
|
|
743
822
|
throw new Error("Update tree changed while its digest was computed");
|
|
744
823
|
const count = Buffer.allocUnsafe(8);
|
|
@@ -747,10 +826,10 @@ async function readUpdateTreeDigest(tree) {
|
|
|
747
826
|
return hash.digest("hex");
|
|
748
827
|
}
|
|
749
828
|
function sameUpdateTreeDigest(left, right) {
|
|
750
|
-
return typeof left === "string" && typeof right === "string" &&
|
|
829
|
+
return typeof left === "string" && typeof right === "string" && isSha256Hex(left) && left === right;
|
|
751
830
|
}
|
|
752
831
|
async function syncDirectoryPath(path) {
|
|
753
|
-
const directory = await
|
|
832
|
+
const directory = await open5(path, constants5.O_RDONLY);
|
|
754
833
|
try {
|
|
755
834
|
await directory.sync();
|
|
756
835
|
} finally {
|
|
@@ -758,12 +837,12 @@ async function syncDirectoryPath(path) {
|
|
|
758
837
|
}
|
|
759
838
|
}
|
|
760
839
|
async function syncUpdateTree(tree) {
|
|
761
|
-
const root = await
|
|
840
|
+
const root = await lstat(tree);
|
|
762
841
|
if (!root.isDirectory())
|
|
763
842
|
throw new Error("Update tree changed while syncing");
|
|
764
843
|
const rootDevice = root.dev;
|
|
765
844
|
const syncEntry = async (path) => {
|
|
766
|
-
const info = await
|
|
845
|
+
const info = await lstat(path);
|
|
767
846
|
if (info.isSymbolicLink())
|
|
768
847
|
return;
|
|
769
848
|
if (info.dev !== rootDevice)
|
|
@@ -776,7 +855,7 @@ async function syncUpdateTree(tree) {
|
|
|
776
855
|
}
|
|
777
856
|
if (!info.isFile())
|
|
778
857
|
throw new Error("Update tree contains an unsupported filesystem entry");
|
|
779
|
-
const file = await
|
|
858
|
+
const file = await open5(path, constants5.O_RDONLY | (constants5.O_NOFOLLOW ?? 0));
|
|
780
859
|
try {
|
|
781
860
|
const opened = await file.stat();
|
|
782
861
|
if (!opened.isFile())
|
|
@@ -787,12 +866,12 @@ async function syncUpdateTree(tree) {
|
|
|
787
866
|
}
|
|
788
867
|
};
|
|
789
868
|
await syncEntry(tree);
|
|
790
|
-
const final = await
|
|
869
|
+
const final = await lstat(tree);
|
|
791
870
|
if (!final.isDirectory() || final.dev !== rootDevice)
|
|
792
871
|
throw new Error("Update tree changed while syncing");
|
|
793
872
|
}
|
|
794
873
|
async function syncUpdateTreeParent(target) {
|
|
795
|
-
const directory = await
|
|
874
|
+
const directory = await open5(dirname3(target), constants5.O_RDONLY);
|
|
796
875
|
try {
|
|
797
876
|
await directory.sync();
|
|
798
877
|
} finally {
|
|
@@ -800,14 +879,14 @@ async function syncUpdateTreeParent(target) {
|
|
|
800
879
|
}
|
|
801
880
|
}
|
|
802
881
|
async function exists(path) {
|
|
803
|
-
return
|
|
804
|
-
if (error
|
|
882
|
+
return lstat(path).then(() => true, (error) => {
|
|
883
|
+
if (errorCode(error) === "ENOENT")
|
|
805
884
|
return false;
|
|
806
885
|
throw error;
|
|
807
886
|
});
|
|
808
887
|
}
|
|
809
888
|
async function assertDirectory(path) {
|
|
810
|
-
const info = await
|
|
889
|
+
const info = await lstat(path);
|
|
811
890
|
if (!info.isDirectory() || info.isSymbolicLink())
|
|
812
891
|
throw new Error("Update exchange requires real directories");
|
|
813
892
|
}
|
|
@@ -846,14 +925,14 @@ async function swapUpdateTreeWhileLocked(options, exchangeOperation = exchangeDi
|
|
|
846
925
|
|
|
847
926
|
// src/updates/update-launch-gate.ts
|
|
848
927
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
849
|
-
import { constants as
|
|
850
|
-
import {
|
|
851
|
-
import { basename as basename4, dirname as dirname5,
|
|
928
|
+
import { constants as constants6 } from "fs";
|
|
929
|
+
import { open as open6, rename as rename2, unlink as unlink3 } from "fs/promises";
|
|
930
|
+
import { basename as basename4, dirname as dirname5, join as join8 } from "path";
|
|
852
931
|
|
|
853
932
|
// src/updates/update-instance-lease.ts
|
|
854
|
-
import { basename as basename3, dirname as dirname4,
|
|
933
|
+
import { basename as basename3, dirname as dirname4, join as join7 } from "path";
|
|
855
934
|
function updateInstanceLeasePath(target) {
|
|
856
|
-
if (
|
|
935
|
+
if (!isCanonicalPath(target))
|
|
857
936
|
throw new Error("Invalid update instance lease target");
|
|
858
937
|
return join7(dirname4(target), "." + basename3(target) + ".framework-instance-lease.lock");
|
|
859
938
|
}
|
|
@@ -867,15 +946,14 @@ async function tryAcquireUpdateInstanceLease(target, mode) {
|
|
|
867
946
|
}
|
|
868
947
|
|
|
869
948
|
// src/updates/update-launch-gate.ts
|
|
870
|
-
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
871
949
|
var VERSION = /^\d+\.\d+\.\d+(?:-dev\.\d+)?$/;
|
|
872
950
|
var MAX_GATE_BYTES = 1024;
|
|
873
951
|
function validateTarget(target) {
|
|
874
|
-
if (
|
|
952
|
+
if (!isCanonicalPath(target))
|
|
875
953
|
throw new Error("Invalid update launch gate target");
|
|
876
954
|
}
|
|
877
955
|
async function syncDirectory(directoryPath) {
|
|
878
|
-
const directory = await
|
|
956
|
+
const directory = await open6(directoryPath, constants6.O_RDONLY);
|
|
879
957
|
try {
|
|
880
958
|
await directory.sync();
|
|
881
959
|
} finally {
|
|
@@ -967,7 +1045,7 @@ function helperLeaseState(lease, target, owner) {
|
|
|
967
1045
|
return state;
|
|
968
1046
|
}
|
|
969
1047
|
function validateGateInput(gate) {
|
|
970
|
-
if (typeof gate !== "object" || gate === null || Object.keys(gate).length !== 4 || gate.schema !== 1 || typeof gate.generation !== "string" || !
|
|
1048
|
+
if (typeof gate !== "object" || gate === null || Object.keys(gate).length !== 4 || gate.schema !== 1 || typeof gate.generation !== "string" || !isUuid(gate.generation) || typeof gate.version !== "string" || !VERSION.test(gate.version) || typeof gate.owner !== "string" || !isUuid(gate.owner))
|
|
971
1049
|
throw new Error("Invalid update launch gate");
|
|
972
1050
|
return Object.freeze({
|
|
973
1051
|
schema: 1,
|
|
@@ -985,26 +1063,8 @@ function parseGate(value) {
|
|
|
985
1063
|
return validateGateInput(record);
|
|
986
1064
|
}
|
|
987
1065
|
async function readUpdateLaunchGate(target) {
|
|
988
|
-
const
|
|
989
|
-
|
|
990
|
-
try {
|
|
991
|
-
info = await lstat3(path);
|
|
992
|
-
} catch (error) {
|
|
993
|
-
if (error.code === "ENOENT")
|
|
994
|
-
return;
|
|
995
|
-
throw error;
|
|
996
|
-
}
|
|
997
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > MAX_GATE_BYTES)
|
|
998
|
-
throw new Error("Invalid update launch gate");
|
|
999
|
-
const file = await open5(path, constants5.O_RDONLY | (constants5.O_NOFOLLOW ?? 0));
|
|
1000
|
-
try {
|
|
1001
|
-
const opened = await file.stat();
|
|
1002
|
-
if (!opened.isFile() || opened.size < 1 || opened.size > MAX_GATE_BYTES)
|
|
1003
|
-
throw new Error("Invalid update launch gate");
|
|
1004
|
-
return parseGate(JSON.parse(await file.readFile("utf8")));
|
|
1005
|
-
} finally {
|
|
1006
|
-
await file.close();
|
|
1007
|
-
}
|
|
1066
|
+
const text = await readSmallStateFile(updateLaunchGatePath(target), MAX_GATE_BYTES, "Invalid update launch gate");
|
|
1067
|
+
return text === undefined ? undefined : parseGate(JSON.parse(text));
|
|
1008
1068
|
}
|
|
1009
1069
|
function sameGate(left, right) {
|
|
1010
1070
|
return left?.schema === right.schema && left.generation === right.generation && left.version === right.version && left.owner === right.owner;
|
|
@@ -1043,7 +1103,7 @@ async function publishUpdateLaunchGate(target, helperLiveness, input, persistOwn
|
|
|
1043
1103
|
const temporary = join8(dirname5(path), `.${basename4(path)}.${gate.generation}.${randomUUID4()}.tmp`);
|
|
1044
1104
|
let renamed = false;
|
|
1045
1105
|
try {
|
|
1046
|
-
const file = await
|
|
1106
|
+
const file = await open6(temporary, constants6.O_WRONLY | constants6.O_CREAT | constants6.O_EXCL, 384);
|
|
1047
1107
|
try {
|
|
1048
1108
|
await file.writeFile(JSON.stringify(gate) + `
|
|
1049
1109
|
`);
|
|
@@ -1284,15 +1344,15 @@ async function waitForUpdateLaunchGateWriter(target, expected, options) {
|
|
|
1284
1344
|
// src/updates/update-helper.ts
|
|
1285
1345
|
function parseUpdateHelperRequest(value) {
|
|
1286
1346
|
const data = value;
|
|
1287
|
-
if (typeof value !== "object" || value === null || Array.isArray(value) || data.schema !== 1 && data.schema !== 2 && data.schema !== 3 ||
|
|
1347
|
+
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" || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(data.version) || !Array.isArray(data.processes) || data.schema === 2 && (typeof data.generation !== "string" || !/^[0-9a-f-]{36}$/i.test(data.generation) || data.helperOwner !== 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)
|
|
1288
1348
|
throw new Error("Invalid update helper request");
|
|
1289
1349
|
return Object.freeze(data);
|
|
1290
1350
|
}
|
|
1291
1351
|
async function readRequest(staging) {
|
|
1292
|
-
const path = join9(staging, "request.json"), info = await
|
|
1352
|
+
const path = join9(staging, "request.json"), info = await lstat2(path);
|
|
1293
1353
|
if (!info.isFile() || info.size < 1 || info.size > 65536)
|
|
1294
1354
|
throw new Error("Invalid update helper request");
|
|
1295
|
-
const file = await
|
|
1355
|
+
const file = await open7(path, constants7.O_RDONLY | (constants7.O_NOFOLLOW ?? 0));
|
|
1296
1356
|
try {
|
|
1297
1357
|
return parseUpdateHelperRequest(JSON.parse(await file.readFile("utf8")));
|
|
1298
1358
|
} finally {
|
|
@@ -1322,10 +1382,10 @@ async function acknowledgeUpdateCancellation(staging, request) {
|
|
|
1322
1382
|
}
|
|
1323
1383
|
async function updatePathExists(path) {
|
|
1324
1384
|
try {
|
|
1325
|
-
await
|
|
1385
|
+
await lstat2(path);
|
|
1326
1386
|
return true;
|
|
1327
1387
|
} catch (error) {
|
|
1328
|
-
if (error
|
|
1388
|
+
if (errorCode(error) === "ENOENT")
|
|
1329
1389
|
return false;
|
|
1330
1390
|
throw error;
|
|
1331
1391
|
}
|
|
@@ -1333,13 +1393,13 @@ async function updatePathExists(path) {
|
|
|
1333
1393
|
async function runUpdateHelper(options) {
|
|
1334
1394
|
const hasBoundIdentity = options.target !== undefined || options.generation !== undefined || options.helperOwner !== undefined;
|
|
1335
1395
|
if (hasBoundIdentity) {
|
|
1336
|
-
if (
|
|
1396
|
+
if (!isCanonicalPath(options.target) || !isCanonicalPath(options.staging) || updateStagingFor(options.target) !== options.staging || typeof options.generation !== "string" || !isUuid(options.generation) || typeof options.helperOwner !== "string" || !isUuid(options.helperOwner))
|
|
1337
1397
|
throw new Error("Invalid update helper invocation");
|
|
1338
1398
|
const liveness = await tryAcquireUpdateHelperLiveness(options.target);
|
|
1339
1399
|
if (!liveness)
|
|
1340
1400
|
throw new Error("Update helper liveness is already owned");
|
|
1341
1401
|
try {
|
|
1342
|
-
const stagingInfo = await
|
|
1402
|
+
const stagingInfo = await lstat2(options.staging);
|
|
1343
1403
|
if (!stagingInfo.isDirectory() || stagingInfo.isSymbolicLink() || await realpath2(options.staging) !== options.staging)
|
|
1344
1404
|
throw new Error("Invalid update staging directory");
|
|
1345
1405
|
const request = await readRequest(options.staging);
|