@yu_robotics/remote-cli 1.6.252 → 1.6.255
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/dist/client/WebSocketClient.d.ts +0 -3
- package/dist/client/WebSocketClient.d.ts.map +1 -1
- package/dist/client/WebSocketClient.js +1 -3
- package/dist/client/WebSocketClient.js.map +1 -1
- package/dist/commands/start.d.ts +0 -5
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +0 -25
- package/dist/commands/start.js.map +1 -1
- package/dist/executor/AgyExecutor.js +3 -3
- package/dist/executor/AgyExecutor.js.map +1 -1
- package/dist/executor/IExecutor.d.ts +1 -1
- package/dist/executor/IExecutor.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/maintenance/release-notes.json +1 -1
- package/dist/scheduling/ScheduleService.d.ts +3 -15
- package/dist/scheduling/ScheduleService.d.ts.map +1 -1
- package/dist/scheduling/ScheduleService.js +58 -93
- package/dist/scheduling/ScheduleService.js.map +1 -1
- package/native/prebuilds/darwin-arm64/managed_native.node +0 -0
- package/native/prebuilds/darwin-arm64/manifest.json +1 -1
- package/native/prebuilds/darwin-x64/managed_native.node +0 -0
- package/native/prebuilds/darwin-x64/manifest.json +1 -1
- package/native/prebuilds/win32-arm64/managed_native.node +0 -0
- package/native/prebuilds/win32-arm64/manifest.json +1 -1
- package/native/prebuilds/win32-x64/managed_native.node +0 -0
- package/native/prebuilds/win32-x64/manifest.json +1 -1
- package/package.json +1 -1
- package/dist/service/SessionHostSupervisor.d.ts +0 -63
- package/dist/service/SessionHostSupervisor.d.ts.map +0 -1
- package/dist/service/SessionHostSupervisor.js +0 -323
- package/dist/service/SessionHostSupervisor.js.map +0 -1
- package/dist/sessionHost/HostClient.d.ts +0 -49
- package/dist/sessionHost/HostClient.d.ts.map +0 -1
- package/dist/sessionHost/HostClient.js +0 -101
- package/dist/sessionHost/HostClient.js.map +0 -1
- package/dist/sessionHost/HostProtocol.d.ts +0 -65
- package/dist/sessionHost/HostProtocol.d.ts.map +0 -1
- package/dist/sessionHost/HostProtocol.js +0 -78
- package/dist/sessionHost/HostProtocol.js.map +0 -1
- package/dist/sessionHost/HostServer.d.ts +0 -52
- package/dist/sessionHost/HostServer.d.ts.map +0 -1
- package/dist/sessionHost/HostServer.js +0 -413
- package/dist/sessionHost/HostServer.js.map +0 -1
- package/dist/sessionHost/HostStore.d.ts +0 -43
- package/dist/sessionHost/HostStore.d.ts.map +0 -1
- package/dist/sessionHost/HostStore.js +0 -206
- package/dist/sessionHost/HostStore.js.map +0 -1
- package/dist/sessionHost/RetainedFrontend.d.ts +0 -63
- package/dist/sessionHost/RetainedFrontend.d.ts.map +0 -1
- package/dist/sessionHost/RetainedFrontend.js +0 -244
- package/dist/sessionHost/RetainedFrontend.js.map +0 -1
- package/dist/sessionHost/RetainedHostLauncher.d.ts +0 -25
- package/dist/sessionHost/RetainedHostLauncher.d.ts.map +0 -1
- package/dist/sessionHost/RetainedHostLauncher.js +0 -132
- package/dist/sessionHost/RetainedHostLauncher.js.map +0 -1
- package/dist/sessionHost/RetainedRuntime.d.ts +0 -62
- package/dist/sessionHost/RetainedRuntime.d.ts.map +0 -1
- package/dist/sessionHost/RetainedRuntime.js +0 -478
- package/dist/sessionHost/RetainedRuntime.js.map +0 -1
- package/dist/sessionHost/RuntimeJournal.d.ts +0 -47
- package/dist/sessionHost/RuntimeJournal.d.ts.map +0 -1
- package/dist/sessionHost/RuntimeJournal.js +0 -103
- package/dist/sessionHost/RuntimeJournal.js.map +0 -1
- package/dist/sessionHost/entry.d.ts +0 -13
- package/dist/sessionHost/entry.d.ts.map +0 -1
- package/dist/sessionHost/entry.js +0 -107
- package/dist/sessionHost/entry.js.map +0 -1
- package/dist/update/PinnedHostBundle.d.ts +0 -49
- package/dist/update/PinnedHostBundle.d.ts.map +0 -1
- package/dist/update/PinnedHostBundle.js +0 -309
- package/dist/update/PinnedHostBundle.js.map +0 -1
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.RuntimeJournal = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const crypto_1 = require("crypto");
|
|
10
|
-
const OwnershipRuntime_1 = require("../delegation/OwnershipRuntime");
|
|
11
|
-
/** Host-owned ingress, output and native callback acceptance. No clock or native replay. */
|
|
12
|
-
class RuntimeJournal {
|
|
13
|
-
directory;
|
|
14
|
-
state;
|
|
15
|
-
gate;
|
|
16
|
-
file;
|
|
17
|
-
identity;
|
|
18
|
-
healthy = true;
|
|
19
|
-
constructor(directory, incarnation) {
|
|
20
|
-
this.directory = directory;
|
|
21
|
-
fs_1.default.mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
22
|
-
const entry = fs_1.default.lstatSync(directory);
|
|
23
|
-
if (!entry.isDirectory() || entry.isSymbolicLink() || process.platform !== 'win32' && (entry.mode & 0o077) !== 0)
|
|
24
|
-
throw new Error('Unsafe runtime directory.');
|
|
25
|
-
this.directory = fs_1.default.realpathSync(directory);
|
|
26
|
-
this.identity = fs_1.default.statSync(this.directory);
|
|
27
|
-
this.file = path_1.default.join(this.directory, 'runtime.json');
|
|
28
|
-
const gate = (0, OwnershipRuntime_1.kernelGate)(path_1.default.join(directory, 'runtime.lock'));
|
|
29
|
-
if (!gate)
|
|
30
|
-
throw new Error('Another retained runtime owns this directory.');
|
|
31
|
-
this.gate = gate;
|
|
32
|
-
this.state = { version: 1, incarnation, owners: [], commands: [], nativeEvents: [] };
|
|
33
|
-
try {
|
|
34
|
-
if (fs_1.default.existsSync(this.file)) {
|
|
35
|
-
const stat = fs_1.default.lstatSync(this.file);
|
|
36
|
-
if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1 || stat.size > 32 * 1024 * 1024
|
|
37
|
-
|| process.platform !== 'win32' && (stat.mode & 0o077) !== 0)
|
|
38
|
-
throw new Error('Unsafe runtime journal.');
|
|
39
|
-
const previous = JSON.parse(fs_1.default.readFileSync(this.file, 'utf8'));
|
|
40
|
-
if (previous.version !== 1 || !Array.isArray(previous.owners) || !Array.isArray(previous.commands) || !Array.isArray(previous.nativeEvents))
|
|
41
|
-
throw new Error('Invalid runtime journal.');
|
|
42
|
-
// A released filesystem lock is not proof that a native predecessor died.
|
|
43
|
-
// Never start a new executor or turn a callback snapshot into native restore.
|
|
44
|
-
if (previous.owners.length || previous.commands.length || previous.nativeEvents.length)
|
|
45
|
-
throw new Error('Retained native runtime restart requires inspection; existing sessions are not imported or recreated.');
|
|
46
|
-
}
|
|
47
|
-
this.change(() => { });
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
gate.close();
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
snapshot() { return structuredClone(this.state); }
|
|
55
|
-
change(update) {
|
|
56
|
-
if (!this.healthy)
|
|
57
|
-
throw new Error('Runtime journal is unavailable.');
|
|
58
|
-
const next = this.snapshot();
|
|
59
|
-
update(next);
|
|
60
|
-
if (next.owners.length > 10 || next.commands.length > 10_000 || next.nativeEvents.length > 512
|
|
61
|
-
|| next.commands.filter(command => command.status !== 'acknowledged').length > 128)
|
|
62
|
-
throw new Error('Retained runtime capacity exhausted; no accepted output was evicted.');
|
|
63
|
-
const bytes = JSON.stringify(next);
|
|
64
|
-
if (Buffer.byteLength(bytes) > 32 * 1024 * 1024)
|
|
65
|
-
throw new Error('Retained runtime storage capacity exhausted.');
|
|
66
|
-
const temporary = path_1.default.join(this.directory, `.runtime-${(0, crypto_1.randomUUID)()}.tmp`);
|
|
67
|
-
try {
|
|
68
|
-
this.gate.verify();
|
|
69
|
-
const directory = fs_1.default.lstatSync(this.directory);
|
|
70
|
-
if (!directory.isDirectory() || directory.isSymbolicLink() || directory.ino !== this.identity.ino || directory.dev !== this.identity.dev)
|
|
71
|
-
throw new Error('Runtime directory identity changed.');
|
|
72
|
-
if (fs_1.default.existsSync(this.file)) {
|
|
73
|
-
const file = fs_1.default.lstatSync(this.file);
|
|
74
|
-
if (!file.isFile() || file.isSymbolicLink() || file.nlink !== 1)
|
|
75
|
-
throw new Error('Unsafe runtime journal.');
|
|
76
|
-
}
|
|
77
|
-
const fd = fs_1.default.openSync(temporary, 'wx', 0o600);
|
|
78
|
-
try {
|
|
79
|
-
fs_1.default.writeFileSync(fd, bytes);
|
|
80
|
-
fs_1.default.fsyncSync(fd);
|
|
81
|
-
}
|
|
82
|
-
finally {
|
|
83
|
-
fs_1.default.closeSync(fd);
|
|
84
|
-
}
|
|
85
|
-
fs_1.default.renameSync(temporary, this.file);
|
|
86
|
-
(0, OwnershipRuntime_1.syncDirectory)(this.directory);
|
|
87
|
-
this.state = next;
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
this.healthy = false;
|
|
91
|
-
throw new Error('Runtime persistence outcome is unknown; native admission is fenced.');
|
|
92
|
-
}
|
|
93
|
-
finally {
|
|
94
|
-
try {
|
|
95
|
-
fs_1.default.unlinkSync(temporary);
|
|
96
|
-
}
|
|
97
|
-
catch { /* Already replaced. */ }
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
close() { this.healthy = false; this.gate.close(); }
|
|
101
|
-
}
|
|
102
|
-
exports.RuntimeJournal = RuntimeJournal;
|
|
103
|
-
//# sourceMappingURL=RuntimeJournal.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RuntimeJournal.js","sourceRoot":"","sources":["../../src/sessionHost/RuntimeJournal.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,mCAAoC;AACpC,qEAA4F;AAa5F,4FAA4F;AAC5F,MAAa,cAAc;IAMI;IALrB,KA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,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAC3D;AAtDD,wCAsDC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { HostServer } from './HostServer';
|
|
2
|
-
import { RetainedRuntime } from './RetainedRuntime';
|
|
3
|
-
/** Pinned supervisor entry: node <bundle>/dist/sessionHost/entry.js --config <private-file>.
|
|
4
|
-
* Manifest: { directory, installationId, secret, launcherSecret, descriptorFile }.
|
|
5
|
-
* The supervisor owns this process independently; stdin/parent IPC is not its lifetime.
|
|
6
|
-
* Frontends use REMOTE_CLI_SESSION_HOST_DESCRIPTOR pointing at descriptorFile.
|
|
7
|
-
*/
|
|
8
|
-
export declare function startRetainedHost(manifestFile: string): Promise<{
|
|
9
|
-
host: HostServer;
|
|
10
|
-
runtime: RetainedRuntime;
|
|
11
|
-
}>;
|
|
12
|
-
export declare function hostConfigArgument(args: string[]): string;
|
|
13
|
-
//# sourceMappingURL=entry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../src/sessionHost/entry.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,eAAe,CAAA;CAAE,CAAC,CAkDrH;AACD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAGzD"}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.startRetainedHost = startRetainedHost;
|
|
7
|
-
exports.hostConfigArgument = hostConfigArgument;
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const ConfigManager_1 = require("../config/ConfigManager");
|
|
11
|
-
const DirectoryGuard_1 = require("../security/DirectoryGuard");
|
|
12
|
-
const ThreadManager_1 = require("../thread/ThreadManager");
|
|
13
|
-
const ThreadExecutorPool_1 = require("../thread/ThreadExecutorPool");
|
|
14
|
-
const WebSocketClient_1 = require("../client/WebSocketClient");
|
|
15
|
-
const DeviceIdentity_1 = require("../files/DeviceIdentity");
|
|
16
|
-
const OwnershipRuntime_1 = require("../delegation/OwnershipRuntime");
|
|
17
|
-
const BackendEnvironment_1 = require("../utils/BackendEnvironment");
|
|
18
|
-
const types_1 = require("../types");
|
|
19
|
-
const HostProtocol_1 = require("./HostProtocol");
|
|
20
|
-
const HostServer_1 = require("./HostServer");
|
|
21
|
-
const RetainedRuntime_1 = require("./RetainedRuntime");
|
|
22
|
-
const RetainedFrontend_1 = require("./RetainedFrontend");
|
|
23
|
-
/** Pinned supervisor entry: node <bundle>/dist/sessionHost/entry.js --config <private-file>.
|
|
24
|
-
* Manifest: { directory, installationId, secret, launcherSecret, descriptorFile }.
|
|
25
|
-
* The supervisor owns this process independently; stdin/parent IPC is not its lifetime.
|
|
26
|
-
* Frontends use REMOTE_CLI_SESSION_HOST_DESCRIPTOR pointing at descriptorFile.
|
|
27
|
-
*/
|
|
28
|
-
async function startRetainedHost(manifestFile) {
|
|
29
|
-
const manifest = (0, RetainedFrontend_1.privateJson)(manifestFile);
|
|
30
|
-
(0, HostProtocol_1.fields)(manifest, ['directory', 'installationId', 'secret', 'launcherSecret', 'descriptorFile']);
|
|
31
|
-
(0, HostProtocol_1.identifier)(manifest.installationId);
|
|
32
|
-
(0, HostProtocol_1.secret)(manifest.secret);
|
|
33
|
-
(0, HostProtocol_1.secret)(manifest.launcherSecret);
|
|
34
|
-
if (typeof manifest.directory !== 'string' || !path_1.default.isAbsolute(manifest.directory)
|
|
35
|
-
|| typeof manifest.descriptorFile !== 'string' || !path_1.default.isAbsolute(manifest.descriptorFile))
|
|
36
|
-
throw new Error('Invalid retained host manifest.');
|
|
37
|
-
const config = await ConfigManager_1.ConfigManager.initialize();
|
|
38
|
-
const all = config.getAll();
|
|
39
|
-
if (!all.deviceId || !all.serverUrl || !all.security?.allowedDirectories.length)
|
|
40
|
-
throw new Error('Complete device configuration is required.');
|
|
41
|
-
// The first opt-in must not overlap a pre-feature monolithic client, which
|
|
42
|
-
// cannot export its live callback/stdio state. Never fall back to importing it.
|
|
43
|
-
const marker = path_1.default.join(config.getConfigDir(), 'retained-host-mode.json');
|
|
44
|
-
if (!fs_1.default.existsSync(marker) && all.service?.running)
|
|
45
|
-
throw new Error('First adoption is unsupported while the monolithic client owns live state. No session or process was changed.');
|
|
46
|
-
const routerOwner = (0, OwnershipRuntime_1.kernelGate)(path_1.default.join(config.getConfigDir(), 'router-owner.lock'));
|
|
47
|
-
if (!routerOwner)
|
|
48
|
-
throw new Error('Another client owns the Router connection.');
|
|
49
|
-
let host;
|
|
50
|
-
let runtime;
|
|
51
|
-
try {
|
|
52
|
-
(0, BackendEnvironment_1.initializeBackendEnvironment)();
|
|
53
|
-
const threads = await ThreadManager_1.ThreadManager.initialize();
|
|
54
|
-
const guard = new DirectoryGuard_1.DirectoryGuard(all.security.allowedDirectories);
|
|
55
|
-
const executorConfig = all.executor ?? { type: 'auto' };
|
|
56
|
-
const pool = new ThreadExecutorPool_1.ThreadExecutorPool(threads, guard, executorConfig);
|
|
57
|
-
const url = all.serverUrl.replace(/^http/, 'ws') + '/ws';
|
|
58
|
-
const router = new WebSocketClient_1.WebSocketClient(url, all.deviceId, {
|
|
59
|
-
capabilityProfile: 'retained-runtime',
|
|
60
|
-
identityLoader: () => (0, DeviceIdentity_1.loadIdentity)(config.getConfigDir(), url, all.deviceId),
|
|
61
|
-
maintenanceCapabilities: { updateNotice: false, subscriptionInspection: false },
|
|
62
|
-
});
|
|
63
|
-
runtime = new RetainedRuntime_1.RetainedRuntime({ directory: path_1.default.join(manifest.directory, 'runtime'), runtimeVersion: types_1.CLI_VERSION,
|
|
64
|
-
config: executorConfig, threads, pool, guard, router });
|
|
65
|
-
const directory = path_1.default.join(manifest.directory, 'control');
|
|
66
|
-
const retained = runtime;
|
|
67
|
-
host = new HostServer_1.HostServer({ directory, installationId: manifest.installationId, secret: manifest.secret, launcherSecret: manifest.launcherSecret,
|
|
68
|
-
runtime: { authorityId: runtime.authorityId, execute: operation => retained.execute(operation), assertCanStop: () => retained.assertCanStop(), inspect: (method, args) => retained.inspect(method, args),
|
|
69
|
-
stop: async () => { await retained.stop(); routerOwner.close(); } } });
|
|
70
|
-
await runtime.start();
|
|
71
|
-
const address = await host.listen();
|
|
72
|
-
const temporary = manifest.descriptorFile + '.tmp';
|
|
73
|
-
const fd = fs_1.default.openSync(temporary, 'wx', 0o600);
|
|
74
|
-
try {
|
|
75
|
-
fs_1.default.writeFileSync(fd, JSON.stringify({ address, secret: manifest.secret, launcherSecret: manifest.launcherSecret, directory }));
|
|
76
|
-
fs_1.default.fsyncSync(fd);
|
|
77
|
-
}
|
|
78
|
-
finally {
|
|
79
|
-
fs_1.default.closeSync(fd);
|
|
80
|
-
}
|
|
81
|
-
fs_1.default.renameSync(temporary, manifest.descriptorFile);
|
|
82
|
-
(0, OwnershipRuntime_1.syncDirectory)(path_1.default.dirname(manifest.descriptorFile));
|
|
83
|
-
fs_1.default.writeFileSync(marker, JSON.stringify({ version: 1 }), { mode: 0o600 });
|
|
84
|
-
return { host, runtime };
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
if (host)
|
|
88
|
-
await host.stop();
|
|
89
|
-
else if (runtime)
|
|
90
|
-
await runtime.stop();
|
|
91
|
-
routerOwner.close();
|
|
92
|
-
throw error;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function hostConfigArgument(args) {
|
|
96
|
-
if (args.length !== 2 || args[0] !== '--config' || !path_1.default.isAbsolute(args[1]))
|
|
97
|
-
throw new Error('Expected --config <absolute-private-file>.');
|
|
98
|
-
return args[1];
|
|
99
|
-
}
|
|
100
|
-
if (require.main === module) {
|
|
101
|
-
void Promise.resolve().then(() => startRetainedHost(hostConfigArgument(process.argv.slice(2)))).then(({ host }) => {
|
|
102
|
-
const shutdown = () => { void host.stop().then(() => process.exit(0)).catch(() => { console.error('Native work remains owned; host shutdown was refused.'); }); };
|
|
103
|
-
process.on('SIGTERM', shutdown);
|
|
104
|
-
process.on('SIGINT', shutdown);
|
|
105
|
-
}).catch(() => { console.error('Retained host startup refused; private state was preserved.'); process.exitCode = 1; });
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=entry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../src/sessionHost/entry.ts"],"names":[],"mappings":";;;;;AAqBA,8CAkDC;AACD,gDAGC;AA3ED,4CAAoB;AACpB,gDAAwB;AACxB,2DAAwD;AACxD,+DAA4D;AAC5D,2DAAwD;AACxD,qEAAkE;AAClE,+DAA4D;AAC5D,4DAAuD;AACvD,qEAA2E;AAC3E,oEAA2E;AAC3E,oCAAuC;AACvC,iDAA4D;AAC5D,6CAA0C;AAC1C,uDAAoD;AACpD,yDAAiD;AAEjD;;;;GAIG;AACI,KAAK,UAAU,iBAAiB,CAAC,YAAoB;IAC1D,MAAM,QAAQ,GAAG,IAAA,8BAAW,EAAC,YAAY,CAAC,CAAC;IAC3C,IAAA,qBAAM,EAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,gBAAgB,EAAE,QAAQ,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAChG,IAAA,yBAAU,EAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;IAAC,IAAA,q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,OAAO,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAClK,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,6DAA6D,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1H,CAAC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/** Inventories must come from caller-verified distribution inputs, not a home scan.
|
|
2
|
-
* Inventories cover the complete package tree except node_modules (separate inputs).
|
|
3
|
-
* Paths are package-relative POSIX paths; mode is the original permission bits.
|
|
4
|
-
* Include every runtime asset (including native addons and deferred helpers).
|
|
5
|
-
*/
|
|
6
|
-
export interface VerifiedHostFile {
|
|
7
|
-
path: string;
|
|
8
|
-
sha256: string;
|
|
9
|
-
mode: number;
|
|
10
|
-
}
|
|
11
|
-
export interface VerifiedHostPackage {
|
|
12
|
-
root: string;
|
|
13
|
-
files: VerifiedHostFile[];
|
|
14
|
-
/** Explicitly unavailable optional dependencies; never omit required dependencies. */
|
|
15
|
-
omittedOptionalDependencies?: string[];
|
|
16
|
-
}
|
|
17
|
-
export interface PinnedHostBundleInput {
|
|
18
|
-
storeRoot: string;
|
|
19
|
-
package: VerifiedHostPackage;
|
|
20
|
-
/** Preserve the installed Node resolution layout, including nested versions. */
|
|
21
|
-
dependencies: Array<VerifiedHostPackage & {
|
|
22
|
-
mount: string;
|
|
23
|
-
}>;
|
|
24
|
-
entry: string;
|
|
25
|
-
/** Pin the interpreter too; it must be runnable without its former install tree.
|
|
26
|
-
* OS shared libraries remain an external prerequisite, not bundled dependencies.
|
|
27
|
-
*/
|
|
28
|
-
node: {
|
|
29
|
-
path: string;
|
|
30
|
-
sha256: string;
|
|
31
|
-
mode: number;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export interface PinnedHostBundle {
|
|
35
|
-
digest: string;
|
|
36
|
-
root: string;
|
|
37
|
-
packageRoot: string;
|
|
38
|
-
entryPath: string;
|
|
39
|
-
nodePath: string;
|
|
40
|
-
assetsRoot: string;
|
|
41
|
-
manifestPath: string;
|
|
42
|
-
}
|
|
43
|
-
/** Full verification is required on reuse; a directory name is not an integrity receipt. */
|
|
44
|
-
export declare function verifyPinnedHostBundle(root: string, expectedDigest: string): Promise<PinnedHostBundle>;
|
|
45
|
-
/** Never mutates a published bundle. Staging and atomic rename tolerate concurrent
|
|
46
|
-
* preparations; the loser verifies the winner rather than replacing it. No GC.
|
|
47
|
-
*/
|
|
48
|
-
export declare function preparePinnedHostBundle(input: PinnedHostBundleInput): Promise<PinnedHostBundle>;
|
|
49
|
-
//# sourceMappingURL=PinnedHostBundle.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PinnedHostBundle.d.ts","sourceRoot":"","sources":["../../src/update/PinnedHostBundle.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;AAChF,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,sFAAsF;IACtF,2BAA2B,CAAC,EAAE,MAAM,EAAE,CAAC;CACxC;AACD,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,mBAAmB,CAAC;IAC7B,gFAAgF;IAChF,YAAY,EAAE,KAAK,CAAC,mBAAmB,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CACtD;AACD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AAgFD,4FAA4F;AAC5F,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA0B5G;AAED;;GAEG;AACH,wBAAsB,uBAAuB,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA4GrG"}
|
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.verifyPinnedHostBundle = verifyPinnedHostBundle;
|
|
7
|
-
exports.preparePinnedHostBundle = preparePinnedHostBundle;
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const crypto_1 = require("crypto");
|
|
12
|
-
const hash = (value) => (0, crypto_1.createHash)('sha256').update(value).digest('hex');
|
|
13
|
-
const isInside = (root, child) => child === root || child.startsWith(root + path_1.default.sep);
|
|
14
|
-
const validHash = (value) => /^[a-f0-9]{64}$/.test(value);
|
|
15
|
-
function relative(value) {
|
|
16
|
-
if (!value || value.includes('\\') || value.split('/').some(part => !part || part === '.' || part === '..')
|
|
17
|
-
|| /[\x00-\x1f\x7f:]/.test(value) || path_1.default.posix.isAbsolute(value))
|
|
18
|
-
throw new Error('Invalid bundle-relative path.');
|
|
19
|
-
return value;
|
|
20
|
-
}
|
|
21
|
-
function checkFile(file) {
|
|
22
|
-
relative(file.path);
|
|
23
|
-
if (!validHash(file.sha256) || !Number.isInteger(file.mode) || file.mode < 0 || file.mode > 0o777) {
|
|
24
|
-
throw new Error('Invalid verified file digest or mode.');
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function sealedMode(mode) { return 0o444 | (mode & 0o111); }
|
|
28
|
-
/** Hash through an opened regular file; symlink resolution is checked by the caller. */
|
|
29
|
-
async function readVerified(source, expected, destination) {
|
|
30
|
-
const input = await promises_1.default.open(source, fs_1.constants.O_RDONLY | (fs_1.constants.O_NOFOLLOW ?? 0));
|
|
31
|
-
let output;
|
|
32
|
-
try {
|
|
33
|
-
const before = await input.stat();
|
|
34
|
-
if (!before.isFile() || before.size > 512 * 1024 * 1024 || (before.mode & 0o777) !== expected.mode) {
|
|
35
|
-
throw new Error('Bundle input is not a bounded regular file with the verified mode.');
|
|
36
|
-
}
|
|
37
|
-
if (destination)
|
|
38
|
-
output = await promises_1.default.open(destination, 'wx', 0o600);
|
|
39
|
-
const digest = (0, crypto_1.createHash)('sha256');
|
|
40
|
-
const buffer = Buffer.alloc(128 * 1024);
|
|
41
|
-
let position = 0;
|
|
42
|
-
while (true) {
|
|
43
|
-
const { bytesRead } = await input.read(buffer, 0, buffer.length, position);
|
|
44
|
-
if (!bytesRead)
|
|
45
|
-
break;
|
|
46
|
-
position += bytesRead;
|
|
47
|
-
if (position > 512 * 1024 * 1024)
|
|
48
|
-
throw new Error('Bundle file exceeds size limit.');
|
|
49
|
-
digest.update(buffer.subarray(0, bytesRead));
|
|
50
|
-
if (output)
|
|
51
|
-
await output.writeFile(buffer.subarray(0, bytesRead));
|
|
52
|
-
}
|
|
53
|
-
const after = await input.stat();
|
|
54
|
-
if (before.size !== after.size || before.mtimeMs !== after.mtimeMs || digest.digest('hex') !== expected.sha256) {
|
|
55
|
-
throw new Error('Bundle input integrity mismatch.');
|
|
56
|
-
}
|
|
57
|
-
if (output) {
|
|
58
|
-
await output.chmod(sealedMode(expected.mode));
|
|
59
|
-
await output.sync();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
finally {
|
|
63
|
-
await output?.close();
|
|
64
|
-
await input.close();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
async function regularTree(root, prefix = '') {
|
|
68
|
-
const result = [];
|
|
69
|
-
for (const entry of await promises_1.default.readdir(path_1.default.join(root, prefix), { withFileTypes: true })) {
|
|
70
|
-
const name = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
71
|
-
if (entry.isDirectory())
|
|
72
|
-
result.push(...await regularTree(root, name));
|
|
73
|
-
else if (entry.isFile() || entry.isSymbolicLink())
|
|
74
|
-
result.push(name);
|
|
75
|
-
else
|
|
76
|
-
throw new Error('Published bundles cannot contain special files.');
|
|
77
|
-
}
|
|
78
|
-
return result.sort();
|
|
79
|
-
}
|
|
80
|
-
async function sourceInventory(root, prefix = '') {
|
|
81
|
-
const names = [];
|
|
82
|
-
for (const entry of await promises_1.default.readdir(path_1.default.join(root, prefix), { withFileTypes: true })) {
|
|
83
|
-
if (!prefix && entry.name === 'node_modules')
|
|
84
|
-
continue;
|
|
85
|
-
const name = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
86
|
-
if (entry.isDirectory())
|
|
87
|
-
names.push(...await sourceInventory(root, name));
|
|
88
|
-
else
|
|
89
|
-
names.push(name); // Links are validated against explicit targets below.
|
|
90
|
-
}
|
|
91
|
-
return names.sort();
|
|
92
|
-
}
|
|
93
|
-
async function syncDirectories(root) {
|
|
94
|
-
for (const entry of await promises_1.default.readdir(root, { withFileTypes: true })) {
|
|
95
|
-
if (entry.isDirectory())
|
|
96
|
-
await syncDirectories(path_1.default.join(root, entry.name));
|
|
97
|
-
}
|
|
98
|
-
const directory = await promises_1.default.open(root, 'r');
|
|
99
|
-
try {
|
|
100
|
-
await directory.sync();
|
|
101
|
-
}
|
|
102
|
-
finally {
|
|
103
|
-
await directory.close();
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
function describe(root, digest, entry) {
|
|
107
|
-
return { digest, root, packageRoot: path_1.default.join(root, 'package'), assetsRoot: path_1.default.join(root, 'package'),
|
|
108
|
-
entryPath: path_1.default.join(root, 'package', entry), nodePath: path_1.default.join(root, 'runtime', 'node'),
|
|
109
|
-
manifestPath: path_1.default.join(root, 'manifest.json') };
|
|
110
|
-
}
|
|
111
|
-
/** Full verification is required on reuse; a directory name is not an integrity receipt. */
|
|
112
|
-
async function verifyPinnedHostBundle(root, expectedDigest) {
|
|
113
|
-
if (process.platform === 'win32')
|
|
114
|
-
throw new Error('Pinned session host launch is unsupported on Windows.');
|
|
115
|
-
if (!validHash(expectedDigest) || await promises_1.default.realpath(root) !== path_1.default.resolve(root))
|
|
116
|
-
throw new Error('Invalid pinned bundle root.');
|
|
117
|
-
const manifestPath = path_1.default.join(root, 'manifest.json');
|
|
118
|
-
const stat = await promises_1.default.lstat(manifestPath);
|
|
119
|
-
if (!stat.isFile() || stat.size > 16 * 1024 * 1024)
|
|
120
|
-
throw new Error('Invalid bundle manifest.');
|
|
121
|
-
const encoded = await promises_1.default.readFile(manifestPath, 'utf8');
|
|
122
|
-
if (hash(encoded) !== expectedDigest)
|
|
123
|
-
throw new Error('Pinned bundle manifest integrity mismatch.');
|
|
124
|
-
const manifest = JSON.parse(encoded);
|
|
125
|
-
if (manifest.schema !== 1 || !Array.isArray(manifest.files))
|
|
126
|
-
throw new Error('Unsupported bundle manifest.');
|
|
127
|
-
relative(manifest.entry);
|
|
128
|
-
const names = manifest.files.map(file => { checkFile(file); return file.path; });
|
|
129
|
-
if (new Set(names).size !== names.length || !names.includes(`package/${manifest.entry}`) || !names.includes('runtime/node')) {
|
|
130
|
-
throw new Error('Incomplete bundle manifest.');
|
|
131
|
-
}
|
|
132
|
-
if (JSON.stringify(await regularTree(root)) !== JSON.stringify([...names, 'manifest.json'].sort()))
|
|
133
|
-
throw new Error('Pinned bundle inventory mismatch.');
|
|
134
|
-
for (const file of manifest.files) {
|
|
135
|
-
const filename = path_1.default.join(root, file.path);
|
|
136
|
-
const stat = await promises_1.default.lstat(filename);
|
|
137
|
-
if (file.link) {
|
|
138
|
-
relative(file.link);
|
|
139
|
-
if (!stat.isSymbolicLink() || !names.includes(file.link) || await promises_1.default.realpath(filename) !== path_1.default.join(root, file.link))
|
|
140
|
-
throw new Error('Pinned bundle link integrity mismatch.');
|
|
141
|
-
}
|
|
142
|
-
else if (!stat.isFile())
|
|
143
|
-
throw new Error('Unexpected pinned bundle symlink.');
|
|
144
|
-
await readVerified(file.link ? path_1.default.join(root, file.link) : filename, { ...file, mode: sealedMode(file.mode) });
|
|
145
|
-
}
|
|
146
|
-
return describe(root, expectedDigest, manifest.entry);
|
|
147
|
-
}
|
|
148
|
-
/** Never mutates a published bundle. Staging and atomic rename tolerate concurrent
|
|
149
|
-
* preparations; the loser verifies the winner rather than replacing it. No GC.
|
|
150
|
-
*/
|
|
151
|
-
async function preparePinnedHostBundle(input) {
|
|
152
|
-
if (process.platform === 'win32')
|
|
153
|
-
throw new Error('Pinned session host launch is unsupported on Windows.');
|
|
154
|
-
relative(input.entry);
|
|
155
|
-
const mounts = new Map([['package', input.package]]);
|
|
156
|
-
for (const dependency of input.dependencies) {
|
|
157
|
-
relative(dependency.mount);
|
|
158
|
-
if (!/^(node_modules\/(?:@[a-zA-Z0-9_.-]+\/)?[a-zA-Z0-9_.-]+)(\/node_modules\/(?:@[a-zA-Z0-9_.-]+\/)?[a-zA-Z0-9_.-]+)*$/.test(dependency.mount)) {
|
|
159
|
-
throw new Error('Invalid dependency mount.');
|
|
160
|
-
}
|
|
161
|
-
const mount = `package/${dependency.mount}`;
|
|
162
|
-
if (mounts.has(mount))
|
|
163
|
-
throw new Error('Duplicate dependency mount.');
|
|
164
|
-
mounts.set(mount, dependency);
|
|
165
|
-
}
|
|
166
|
-
const sources = new Map();
|
|
167
|
-
const roots = [];
|
|
168
|
-
for (const [mount, pkg] of mounts) {
|
|
169
|
-
const root = await promises_1.default.realpath(pkg.root); // Explicit workspace package roots may be links.
|
|
170
|
-
roots.push(root);
|
|
171
|
-
const allowed = new Set(pkg.files.map(file => file.path));
|
|
172
|
-
if (!allowed.has('package.json') || allowed.size !== pkg.files.length)
|
|
173
|
-
throw new Error('Incomplete or duplicate package inventory.');
|
|
174
|
-
for (const file of pkg.files) {
|
|
175
|
-
checkFile(file);
|
|
176
|
-
if (file.path.split('/').includes('node_modules'))
|
|
177
|
-
throw new Error('Dependencies require separate verified inputs.');
|
|
178
|
-
const filename = path_1.default.join(root, file.path);
|
|
179
|
-
// Directory links are not traversed. File links retain Node realpath/module
|
|
180
|
-
// identity only when their resolved target is explicitly inventoried.
|
|
181
|
-
if (await promises_1.default.realpath(path_1.default.dirname(filename)) !== path_1.default.dirname(filename))
|
|
182
|
-
throw new Error('Directory symlink in package inventory.');
|
|
183
|
-
const source = await promises_1.default.realpath(filename);
|
|
184
|
-
const target = path_1.default.relative(root, source).split(path_1.default.sep).join('/');
|
|
185
|
-
if (!isInside(root, source) || !allowed.has(target))
|
|
186
|
-
throw new Error('Unproven package symlink target.');
|
|
187
|
-
sources.set(`${mount}/${file.path}`, { source, file, ...(source !== filename ? { link: `${mount}/${target}` } : {}) });
|
|
188
|
-
}
|
|
189
|
-
if (JSON.stringify(await sourceInventory(root)) !== JSON.stringify([...allowed].sort()))
|
|
190
|
-
throw new Error('Package inventory is incomplete or contains unverified files.');
|
|
191
|
-
}
|
|
192
|
-
if (!sources.has(`package/${input.entry}`))
|
|
193
|
-
throw new Error('Host entry is missing from verified inventory.');
|
|
194
|
-
// Validate the entire required dependency closure at the preserved Node lookup
|
|
195
|
-
// locations. Optional omissions are explicit; peer dependencies are included.
|
|
196
|
-
for (const [mount, pkg] of mounts) {
|
|
197
|
-
const source = sources.get(`${mount}/package.json`);
|
|
198
|
-
await readVerified(source.source, source.file);
|
|
199
|
-
const text = await promises_1.default.readFile(source.source, 'utf8');
|
|
200
|
-
if (hash(text) !== source.file.sha256)
|
|
201
|
-
throw new Error('Package metadata changed during verification.');
|
|
202
|
-
const metadata = JSON.parse(text);
|
|
203
|
-
if (mount !== 'package' && metadata.bin) {
|
|
204
|
-
const bins = typeof metadata.bin === 'string' ? { [String(metadata.name).split('/').pop()]: metadata.bin } : metadata.bin;
|
|
205
|
-
for (const [name, value] of Object.entries(bins)) {
|
|
206
|
-
if (!/^[a-zA-Z0-9_.-]+$/.test(name) || typeof value !== 'string')
|
|
207
|
-
throw new Error('Invalid dependency executable.');
|
|
208
|
-
const target = `${mount}/${relative(value.replace(/^\.\//, ''))}`;
|
|
209
|
-
const item = sources.get(target);
|
|
210
|
-
if (!item || item.link || !(item.file.mode & 0o111))
|
|
211
|
-
throw new Error('Dependency executable is not a verified executable regular file.');
|
|
212
|
-
const bin = `${mount.slice(0, mount.lastIndexOf('/node_modules/'))}/node_modules/.bin/${name}`;
|
|
213
|
-
if (sources.has(bin))
|
|
214
|
-
throw new Error('Ambiguous dependency executable binding.');
|
|
215
|
-
sources.set(bin, { ...item, link: target });
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
const required = { ...metadata.dependencies, ...metadata.peerDependencies, ...metadata.optionalDependencies };
|
|
219
|
-
for (const name of Object.keys(required)) {
|
|
220
|
-
if (!/^(?:@[a-zA-Z0-9_.-]+\/)?[a-zA-Z0-9_.-]+$/.test(name))
|
|
221
|
-
throw new Error('Invalid dependency name.');
|
|
222
|
-
let cursor = mount;
|
|
223
|
-
let found = false;
|
|
224
|
-
while (cursor.startsWith('package')) {
|
|
225
|
-
if (mounts.has(`${cursor}/node_modules/${name}`)) {
|
|
226
|
-
found = true;
|
|
227
|
-
break;
|
|
228
|
-
}
|
|
229
|
-
const index = cursor.lastIndexOf('/node_modules/');
|
|
230
|
-
if (index < 0)
|
|
231
|
-
break;
|
|
232
|
-
cursor = cursor.slice(0, index);
|
|
233
|
-
}
|
|
234
|
-
const optional = Object.hasOwn(metadata.optionalDependencies ?? {}, name) || metadata.peerDependenciesMeta?.[name]?.optional === true;
|
|
235
|
-
if (!found && !(optional && pkg.omittedOptionalDependencies?.includes(name)))
|
|
236
|
-
throw new Error(`Missing verified runtime dependency: ${name}`);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
const nodeFile = { path: 'runtime/node', sha256: input.node.sha256, mode: input.node.mode };
|
|
240
|
-
checkFile(nodeFile);
|
|
241
|
-
if (!(input.node.mode & 0o111))
|
|
242
|
-
throw new Error('Pinned Node runtime must be executable.');
|
|
243
|
-
sources.set('runtime/node', { source: await promises_1.default.realpath(input.node.path), file: nodeFile });
|
|
244
|
-
await promises_1.default.mkdir(input.storeRoot, { recursive: true, mode: 0o700 });
|
|
245
|
-
const store = await promises_1.default.realpath(input.storeRoot);
|
|
246
|
-
if (store.split(path_1.default.sep).includes('node_modules') || roots.some(root => isInside(root, store) || isInside(store, root)))
|
|
247
|
-
throw new Error('Bundle store must be separate from package inputs.');
|
|
248
|
-
const storeStat = await promises_1.default.stat(store);
|
|
249
|
-
if ((storeStat.mode & 0o077) || storeStat.uid !== process.getuid?.())
|
|
250
|
-
throw new Error('Bundle store must be private and owned by the current user.');
|
|
251
|
-
const manifest = { schema: 1, entry: input.entry, files: [...sources.entries()]
|
|
252
|
-
.map(([name, value]) => ({ path: name, sha256: value.file.sha256, mode: value.file.mode, ...(value.link ? { link: value.link } : {}) })).sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0) };
|
|
253
|
-
const encoded = JSON.stringify(manifest);
|
|
254
|
-
const digest = hash(encoded);
|
|
255
|
-
const destination = path_1.default.join(store, digest);
|
|
256
|
-
let present = false;
|
|
257
|
-
try {
|
|
258
|
-
await promises_1.default.lstat(destination);
|
|
259
|
-
present = true;
|
|
260
|
-
}
|
|
261
|
-
catch (error) {
|
|
262
|
-
if (error.code !== 'ENOENT')
|
|
263
|
-
throw error;
|
|
264
|
-
}
|
|
265
|
-
if (present)
|
|
266
|
-
return verifyPinnedHostBundle(destination, digest);
|
|
267
|
-
const staging = await promises_1.default.mkdtemp(path_1.default.join(store, '.prepare-'));
|
|
268
|
-
try {
|
|
269
|
-
for (const [name, { source, file, link }] of sources) {
|
|
270
|
-
const output = path_1.default.join(staging, name);
|
|
271
|
-
await promises_1.default.mkdir(path_1.default.dirname(output), { recursive: true, mode: 0o700 });
|
|
272
|
-
if (link) {
|
|
273
|
-
await readVerified(source, file);
|
|
274
|
-
await promises_1.default.symlink(path_1.default.relative(path_1.default.dirname(output), path_1.default.join(staging, link)), output);
|
|
275
|
-
}
|
|
276
|
-
else
|
|
277
|
-
await readVerified(source, file, output);
|
|
278
|
-
}
|
|
279
|
-
const manifestFile = await promises_1.default.open(path_1.default.join(staging, 'manifest.json'), 'wx', 0o400);
|
|
280
|
-
try {
|
|
281
|
-
await manifestFile.writeFile(encoded);
|
|
282
|
-
await manifestFile.sync();
|
|
283
|
-
}
|
|
284
|
-
finally {
|
|
285
|
-
await manifestFile.close();
|
|
286
|
-
}
|
|
287
|
-
await verifyPinnedHostBundle(staging, digest);
|
|
288
|
-
await syncDirectories(staging);
|
|
289
|
-
try {
|
|
290
|
-
await promises_1.default.rename(staging, destination);
|
|
291
|
-
}
|
|
292
|
-
catch (error) {
|
|
293
|
-
if (!['EEXIST', 'ENOTEMPTY'].includes(error.code ?? ''))
|
|
294
|
-
throw error;
|
|
295
|
-
}
|
|
296
|
-
const directory = await promises_1.default.open(store, 'r');
|
|
297
|
-
try {
|
|
298
|
-
await directory.sync();
|
|
299
|
-
}
|
|
300
|
-
finally {
|
|
301
|
-
await directory.close();
|
|
302
|
-
}
|
|
303
|
-
return await verifyPinnedHostBundle(destination, digest);
|
|
304
|
-
}
|
|
305
|
-
finally {
|
|
306
|
-
await promises_1.default.rm(staging, { recursive: true, force: true });
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
//# sourceMappingURL=PinnedHostBundle.js.map
|