@adea-ai/app-framework 0.31.0 → 0.33.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 +33 -15
- 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 -178
- 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/packaged-update-startup.d.ts +25 -5
- package/dist/updates/packaged-update-startup.js +30 -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 +65 -2
- package/dist/updates/update-adapter.d.ts +2 -13
- package/dist/updates/update-arm.js +13 -13
- 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 +30 -27
- package/dist/updates/update-retention-marker.js +7 -5
- package/dist/updates/update-retention-plan.js +2 -2
- package/dist/updates/update-retirement.js +52 -52
- package/dist/updates/update-state-store.d.ts +2 -0
- package/dist/updates/update-state-store.js +34 -38
- 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/templates/application/src/bun/index.ts +13 -9
- 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 lstat3, 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 as lstat2, open as
|
|
267
|
-
import { basename as basename2, dirname as dirname3,
|
|
311
|
+
import { constants as constants5 } from "fs";
|
|
312
|
+
import { lstat as lstat2, 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,46 @@ 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 { lstat, open as open3 } from "fs/promises";
|
|
590
|
+
async function readSmallStateFile(path, maximum, message) {
|
|
591
|
+
let linkFree;
|
|
592
|
+
if (constants3.O_NOFOLLOW === undefined) {
|
|
593
|
+
try {
|
|
594
|
+
linkFree = await lstat(path);
|
|
595
|
+
} catch (error) {
|
|
596
|
+
if (errorCode(error) === "ENOENT")
|
|
597
|
+
return;
|
|
598
|
+
throw error;
|
|
599
|
+
}
|
|
600
|
+
if (linkFree.isSymbolicLink())
|
|
601
|
+
throw new Error(message);
|
|
602
|
+
}
|
|
603
|
+
let file;
|
|
604
|
+
try {
|
|
605
|
+
file = await open3(path, constants3.O_RDONLY | (constants3.O_NOFOLLOW ?? 0) | (constants3.O_NONBLOCK ?? 0));
|
|
606
|
+
} catch (error) {
|
|
607
|
+
const code = errorCode(error);
|
|
608
|
+
if (code === "ENOENT")
|
|
609
|
+
return;
|
|
610
|
+
if (code === "ELOOP" || code === "EMLINK")
|
|
611
|
+
throw new Error(message, { cause: error });
|
|
612
|
+
throw error;
|
|
613
|
+
}
|
|
614
|
+
try {
|
|
615
|
+
const info = await file.stat();
|
|
616
|
+
if (!info.isFile() || info.size < 1 || info.size > maximum || linkFree && (linkFree.dev !== info.dev || linkFree.ino !== info.ino))
|
|
617
|
+
throw new Error(message);
|
|
618
|
+
const text = await file.readFile("utf8");
|
|
619
|
+
if (Buffer.byteLength(text) !== info.size)
|
|
620
|
+
throw new Error(message);
|
|
621
|
+
return text;
|
|
622
|
+
} finally {
|
|
623
|
+
await file.close();
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
523
627
|
// src/updates/update-state-store.ts
|
|
524
628
|
class UpdateLockBusyError extends Error {
|
|
525
629
|
constructor() {
|
|
@@ -545,7 +649,7 @@ function parseState(value) {
|
|
|
545
649
|
const candidateTreeIdentity = record.candidateTreeIdentity;
|
|
546
650
|
const candidateTreeDigest = record.candidateTreeDigest;
|
|
547
651
|
const previousTreeIdentity = record.previousTreeIdentity;
|
|
548
|
-
if (record.schema !== 1 || typeof record.generation !== "string" ||
|
|
652
|
+
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
653
|
"schema",
|
|
550
654
|
"generation",
|
|
551
655
|
"phase",
|
|
@@ -567,21 +671,11 @@ function parseState(value) {
|
|
|
567
671
|
return Object.freeze(record);
|
|
568
672
|
}
|
|
569
673
|
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")));
|
|
674
|
+
const text = await readSmallStateFile(join5(staging, "state.json"), 4096, "Invalid update staging state");
|
|
675
|
+
return text === undefined ? undefined : parseState(JSON.parse(text));
|
|
582
676
|
}
|
|
583
677
|
async function syncUpdateStageDirectory(staging) {
|
|
584
|
-
const directory = await
|
|
678
|
+
const directory = await open4(staging, constants4.O_RDONLY);
|
|
585
679
|
try {
|
|
586
680
|
await directory.sync();
|
|
587
681
|
} finally {
|
|
@@ -589,39 +683,36 @@ async function syncUpdateStageDirectory(staging) {
|
|
|
589
683
|
}
|
|
590
684
|
}
|
|
591
685
|
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
|
-
}
|
|
686
|
+
await replaceUpdateStageState(staging, state, false);
|
|
604
687
|
}
|
|
605
688
|
async function writeUpdateStageStateDurably(staging, state) {
|
|
606
|
-
|
|
689
|
+
await replaceUpdateStageState(staging, state, true);
|
|
690
|
+
}
|
|
691
|
+
async function replaceUpdateStageState(staging, state, durable) {
|
|
692
|
+
if (typeof state.generation !== "string" || !isUuid(state.generation))
|
|
607
693
|
throw new Error("Invalid update staging state");
|
|
608
694
|
const path = join5(staging, "state.json");
|
|
609
695
|
const temporary = join5(staging, `.state-${state.generation}-${randomUUID3()}.tmp`);
|
|
696
|
+
const contents = JSON.stringify(state) + `
|
|
697
|
+
`;
|
|
610
698
|
let renamed = false;
|
|
611
699
|
try {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
700
|
+
if (durable) {
|
|
701
|
+
const file = await open4(temporary, constants4.O_WRONLY | constants4.O_CREAT | constants4.O_EXCL, 384);
|
|
702
|
+
try {
|
|
703
|
+
await file.writeFile(contents);
|
|
704
|
+
await file.sync();
|
|
705
|
+
} finally {
|
|
706
|
+
await file.close();
|
|
707
|
+
}
|
|
708
|
+
} else
|
|
709
|
+
await writeFile3(temporary, contents, { flag: "wx", mode: 384 });
|
|
620
710
|
await rename(temporary, path);
|
|
621
711
|
renamed = true;
|
|
622
|
-
|
|
712
|
+
if (durable)
|
|
713
|
+
await syncUpdateStageDirectory(staging);
|
|
623
714
|
} catch (error) {
|
|
624
|
-
if (!renamed)
|
|
715
|
+
if (!renamed && errorCode(error) !== "EEXIST")
|
|
625
716
|
await unlink2(temporary).catch(() => {});
|
|
626
717
|
throw error;
|
|
627
718
|
}
|
|
@@ -629,14 +720,14 @@ async function writeUpdateStageStateDurably(staging, state) {
|
|
|
629
720
|
|
|
630
721
|
// src/updates/update-swap.ts
|
|
631
722
|
function updateStagingFor(target) {
|
|
632
|
-
if (
|
|
723
|
+
if (!isCanonicalPath(target))
|
|
633
724
|
throw new Error("Invalid update target");
|
|
634
725
|
return join6(dirname3(target), `.${basename2(target)}.framework-update`);
|
|
635
726
|
}
|
|
636
727
|
async function readUpdateTreeVersion(tree) {
|
|
637
728
|
const versionPath = join6(tree, ...process.platform === "darwin" ? ["Contents", "Resources"] : ["Resources"], "version.json");
|
|
638
729
|
try {
|
|
639
|
-
const value = JSON.parse(await
|
|
730
|
+
const value = JSON.parse(await readFile3(versionPath, "utf8"));
|
|
640
731
|
if (typeof value !== "object" || value === null || typeof value.version !== "string")
|
|
641
732
|
return;
|
|
642
733
|
return value.version;
|
|
@@ -714,8 +805,8 @@ async function readUpdateTreeDigest(tree) {
|
|
|
714
805
|
if (!before.isFile() || before.nlink !== 1n || before.size < 0n)
|
|
715
806
|
throw new Error("Update tree contains an unsupported filesystem entry");
|
|
716
807
|
writeRecord("file", relative, before.mode, before.size);
|
|
717
|
-
const noFollow =
|
|
718
|
-
const file = await
|
|
808
|
+
const noFollow = constants5.O_NOFOLLOW ?? 0;
|
|
809
|
+
const file = await open5(path, constants5.O_RDONLY | noFollow | (constants5.O_NONBLOCK ?? 0));
|
|
719
810
|
try {
|
|
720
811
|
const opened = await file.stat({ bigint: true });
|
|
721
812
|
if (!opened.isFile() || !sameTreeEntrySnapshot(before, opened))
|
|
@@ -747,10 +838,10 @@ async function readUpdateTreeDigest(tree) {
|
|
|
747
838
|
return hash.digest("hex");
|
|
748
839
|
}
|
|
749
840
|
function sameUpdateTreeDigest(left, right) {
|
|
750
|
-
return typeof left === "string" && typeof right === "string" &&
|
|
841
|
+
return typeof left === "string" && typeof right === "string" && isSha256Hex(left) && left === right;
|
|
751
842
|
}
|
|
752
843
|
async function syncDirectoryPath(path) {
|
|
753
|
-
const directory = await
|
|
844
|
+
const directory = await open5(path, constants5.O_RDONLY);
|
|
754
845
|
try {
|
|
755
846
|
await directory.sync();
|
|
756
847
|
} finally {
|
|
@@ -776,7 +867,7 @@ async function syncUpdateTree(tree) {
|
|
|
776
867
|
}
|
|
777
868
|
if (!info.isFile())
|
|
778
869
|
throw new Error("Update tree contains an unsupported filesystem entry");
|
|
779
|
-
const file = await
|
|
870
|
+
const file = await open5(path, constants5.O_RDONLY | (constants5.O_NOFOLLOW ?? 0));
|
|
780
871
|
try {
|
|
781
872
|
const opened = await file.stat();
|
|
782
873
|
if (!opened.isFile())
|
|
@@ -792,7 +883,7 @@ async function syncUpdateTree(tree) {
|
|
|
792
883
|
throw new Error("Update tree changed while syncing");
|
|
793
884
|
}
|
|
794
885
|
async function syncUpdateTreeParent(target) {
|
|
795
|
-
const directory = await
|
|
886
|
+
const directory = await open5(dirname3(target), constants5.O_RDONLY);
|
|
796
887
|
try {
|
|
797
888
|
await directory.sync();
|
|
798
889
|
} finally {
|
|
@@ -801,7 +892,7 @@ async function syncUpdateTreeParent(target) {
|
|
|
801
892
|
}
|
|
802
893
|
async function exists(path) {
|
|
803
894
|
return lstat2(path).then(() => true, (error) => {
|
|
804
|
-
if (error
|
|
895
|
+
if (errorCode(error) === "ENOENT")
|
|
805
896
|
return false;
|
|
806
897
|
throw error;
|
|
807
898
|
});
|
|
@@ -846,14 +937,14 @@ async function swapUpdateTreeWhileLocked(options, exchangeOperation = exchangeDi
|
|
|
846
937
|
|
|
847
938
|
// src/updates/update-launch-gate.ts
|
|
848
939
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
849
|
-
import { constants as
|
|
850
|
-
import {
|
|
851
|
-
import { basename as basename4, dirname as dirname5,
|
|
940
|
+
import { constants as constants6 } from "fs";
|
|
941
|
+
import { open as open6, rename as rename2, unlink as unlink3 } from "fs/promises";
|
|
942
|
+
import { basename as basename4, dirname as dirname5, join as join8 } from "path";
|
|
852
943
|
|
|
853
944
|
// src/updates/update-instance-lease.ts
|
|
854
|
-
import { basename as basename3, dirname as dirname4,
|
|
945
|
+
import { basename as basename3, dirname as dirname4, join as join7 } from "path";
|
|
855
946
|
function updateInstanceLeasePath(target) {
|
|
856
|
-
if (
|
|
947
|
+
if (!isCanonicalPath(target))
|
|
857
948
|
throw new Error("Invalid update instance lease target");
|
|
858
949
|
return join7(dirname4(target), "." + basename3(target) + ".framework-instance-lease.lock");
|
|
859
950
|
}
|
|
@@ -867,15 +958,14 @@ async function tryAcquireUpdateInstanceLease(target, mode) {
|
|
|
867
958
|
}
|
|
868
959
|
|
|
869
960
|
// 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
961
|
var VERSION = /^\d+\.\d+\.\d+(?:-dev\.\d+)?$/;
|
|
872
962
|
var MAX_GATE_BYTES = 1024;
|
|
873
963
|
function validateTarget(target) {
|
|
874
|
-
if (
|
|
964
|
+
if (!isCanonicalPath(target))
|
|
875
965
|
throw new Error("Invalid update launch gate target");
|
|
876
966
|
}
|
|
877
967
|
async function syncDirectory(directoryPath) {
|
|
878
|
-
const directory = await
|
|
968
|
+
const directory = await open6(directoryPath, constants6.O_RDONLY);
|
|
879
969
|
try {
|
|
880
970
|
await directory.sync();
|
|
881
971
|
} finally {
|
|
@@ -967,7 +1057,7 @@ function helperLeaseState(lease, target, owner) {
|
|
|
967
1057
|
return state;
|
|
968
1058
|
}
|
|
969
1059
|
function validateGateInput(gate) {
|
|
970
|
-
if (typeof gate !== "object" || gate === null || Object.keys(gate).length !== 4 || gate.schema !== 1 || typeof gate.generation !== "string" || !
|
|
1060
|
+
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
1061
|
throw new Error("Invalid update launch gate");
|
|
972
1062
|
return Object.freeze({
|
|
973
1063
|
schema: 1,
|
|
@@ -985,26 +1075,8 @@ function parseGate(value) {
|
|
|
985
1075
|
return validateGateInput(record);
|
|
986
1076
|
}
|
|
987
1077
|
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
|
-
}
|
|
1078
|
+
const text = await readSmallStateFile(updateLaunchGatePath(target), MAX_GATE_BYTES, "Invalid update launch gate");
|
|
1079
|
+
return text === undefined ? undefined : parseGate(JSON.parse(text));
|
|
1008
1080
|
}
|
|
1009
1081
|
function sameGate(left, right) {
|
|
1010
1082
|
return left?.schema === right.schema && left.generation === right.generation && left.version === right.version && left.owner === right.owner;
|
|
@@ -1043,7 +1115,7 @@ async function publishUpdateLaunchGate(target, helperLiveness, input, persistOwn
|
|
|
1043
1115
|
const temporary = join8(dirname5(path), `.${basename4(path)}.${gate.generation}.${randomUUID4()}.tmp`);
|
|
1044
1116
|
let renamed = false;
|
|
1045
1117
|
try {
|
|
1046
|
-
const file = await
|
|
1118
|
+
const file = await open6(temporary, constants6.O_WRONLY | constants6.O_CREAT | constants6.O_EXCL, 384);
|
|
1047
1119
|
try {
|
|
1048
1120
|
await file.writeFile(JSON.stringify(gate) + `
|
|
1049
1121
|
`);
|
|
@@ -1284,15 +1356,15 @@ async function waitForUpdateLaunchGateWriter(target, expected, options) {
|
|
|
1284
1356
|
// src/updates/update-helper.ts
|
|
1285
1357
|
function parseUpdateHelperRequest(value) {
|
|
1286
1358
|
const data = value;
|
|
1287
|
-
if (typeof value !== "object" || value === null || Array.isArray(value) || data.schema !== 1 && data.schema !== 2 && data.schema !== 3 ||
|
|
1359
|
+
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
1360
|
throw new Error("Invalid update helper request");
|
|
1289
1361
|
return Object.freeze(data);
|
|
1290
1362
|
}
|
|
1291
1363
|
async function readRequest(staging) {
|
|
1292
|
-
const path = join9(staging, "request.json"), info = await
|
|
1364
|
+
const path = join9(staging, "request.json"), info = await lstat3(path);
|
|
1293
1365
|
if (!info.isFile() || info.size < 1 || info.size > 65536)
|
|
1294
1366
|
throw new Error("Invalid update helper request");
|
|
1295
|
-
const file = await
|
|
1367
|
+
const file = await open7(path, constants7.O_RDONLY | (constants7.O_NOFOLLOW ?? 0));
|
|
1296
1368
|
try {
|
|
1297
1369
|
return parseUpdateHelperRequest(JSON.parse(await file.readFile("utf8")));
|
|
1298
1370
|
} finally {
|
|
@@ -1322,10 +1394,10 @@ async function acknowledgeUpdateCancellation(staging, request) {
|
|
|
1322
1394
|
}
|
|
1323
1395
|
async function updatePathExists(path) {
|
|
1324
1396
|
try {
|
|
1325
|
-
await
|
|
1397
|
+
await lstat3(path);
|
|
1326
1398
|
return true;
|
|
1327
1399
|
} catch (error) {
|
|
1328
|
-
if (error
|
|
1400
|
+
if (errorCode(error) === "ENOENT")
|
|
1329
1401
|
return false;
|
|
1330
1402
|
throw error;
|
|
1331
1403
|
}
|
|
@@ -1333,13 +1405,13 @@ async function updatePathExists(path) {
|
|
|
1333
1405
|
async function runUpdateHelper(options) {
|
|
1334
1406
|
const hasBoundIdentity = options.target !== undefined || options.generation !== undefined || options.helperOwner !== undefined;
|
|
1335
1407
|
if (hasBoundIdentity) {
|
|
1336
|
-
if (
|
|
1408
|
+
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
1409
|
throw new Error("Invalid update helper invocation");
|
|
1338
1410
|
const liveness = await tryAcquireUpdateHelperLiveness(options.target);
|
|
1339
1411
|
if (!liveness)
|
|
1340
1412
|
throw new Error("Update helper liveness is already owned");
|
|
1341
1413
|
try {
|
|
1342
|
-
const stagingInfo = await
|
|
1414
|
+
const stagingInfo = await lstat3(options.staging);
|
|
1343
1415
|
if (!stagingInfo.isDirectory() || stagingInfo.isSymbolicLink() || await realpath2(options.staging) !== options.staging)
|
|
1344
1416
|
throw new Error("Invalid update staging directory");
|
|
1345
1417
|
const request = await readRequest(options.staging);
|