@ship.zone/runner 2.1.0 → 4.0.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/.smartconfig.json +118 -3
- package/changelog.md +101 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl +0 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.json +679 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.txt +15719 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl.tsrust-build.json +5 -5
- package/dist_rust/runnerworkspace_linux_arm64_musl +0 -0
- package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.json +679 -0
- package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.txt +15719 -0
- package/dist_rust/runnerworkspace_linux_arm64_musl.tsrust-build.json +5 -5
- package/dist_ts/00_commitinfo_data.d.ts +8 -0
- package/dist_ts/00_commitinfo_data.js +9 -0
- package/dist_ts/api-client.d.ts +47 -0
- package/dist_ts/api-client.js +600 -0
- package/dist_ts/artifact-manager.d.ts +11 -0
- package/dist_ts/artifact-manager.js +140 -0
- package/dist_ts/attempt-state.d.ts +18 -0
- package/dist_ts/attempt-state.js +151 -0
- package/dist_ts/cache-manager.d.ts +13 -0
- package/dist_ts/cache-manager.js +300 -0
- package/dist_ts/cli-entry.d.ts +2 -0
- package/dist_ts/cli-entry.js +18 -0
- package/dist_ts/cli.d.ts +14 -0
- package/dist_ts/cli.js +243 -0
- package/dist_ts/config.d.ts +8 -0
- package/dist_ts/config.js +495 -0
- package/dist_ts/egress-proxy.d.ts +99 -0
- package/dist_ts/egress-proxy.js +607 -0
- package/dist_ts/errors.d.ts +41 -0
- package/dist_ts/errors.js +90 -0
- package/dist_ts/filesystem.d.ts +73 -0
- package/dist_ts/filesystem.js +207 -0
- package/dist_ts/index.d.ts +20 -0
- package/dist_ts/index.js +21 -0
- package/dist_ts/interfaces.d.ts +685 -0
- package/dist_ts/interfaces.js +3 -0
- package/dist_ts/log-sender.d.ts +26 -0
- package/dist_ts/log-sender.js +124 -0
- package/dist_ts/microvm-executor.d.ts +90 -0
- package/dist_ts/microvm-executor.js +1045 -0
- package/dist_ts/node-version.d.ts +11 -0
- package/dist_ts/node-version.js +43 -0
- package/dist_ts/npm-grants.d.ts +9 -0
- package/dist_ts/npm-grants.js +44 -0
- package/dist_ts/oci-registry.d.ts +73 -0
- package/dist_ts/oci-registry.js +508 -0
- package/dist_ts/plugins.d.ts +23 -0
- package/dist_ts/plugins.js +27 -0
- package/dist_ts/protocol-validator.d.ts +39 -0
- package/dist_ts/protocol-validator.js +488 -0
- package/dist_ts/redactor.d.ts +78 -0
- package/dist_ts/redactor.js +235 -0
- package/dist_ts/registration-state.d.ts +16 -0
- package/dist_ts/registration-state.js +171 -0
- package/dist_ts/runner.d.ts +65 -0
- package/dist_ts/runner.js +912 -0
- package/dist_ts/source-workspace.d.ts +10 -0
- package/dist_ts/source-workspace.js +125 -0
- package/dist_ts/spec-version.d.ts +11 -0
- package/dist_ts/spec-version.js +41 -0
- package/dist_ts/staging-scavenger.d.ts +7 -0
- package/dist_ts/staging-scavenger.js +63 -0
- package/dist_ts/state-owner.d.ts +74 -0
- package/dist_ts/state-owner.js +291 -0
- package/dist_ts/transfer-archive.d.ts +78 -0
- package/dist_ts/transfer-archive.js +1619 -0
- package/dist_ts/validation.d.ts +11 -0
- package/dist_ts/validation.js +79 -0
- package/dist_ts/vsock-protocol.d.ts +130 -0
- package/dist_ts/vsock-protocol.js +336 -0
- package/dist_ts/wire-schema.d.ts +10 -0
- package/dist_ts/wire-schema.js +114 -0
- package/native-notices/crates/bitflags-2.13.1/license-apache +201 -0
- package/native-notices/crates/bitflags-2.13.1/license-mit +25 -0
- package/native-notices/crates/cc-1.8.0/license-apache +201 -0
- package/native-notices/crates/cc-1.8.0/license-mit +25 -0
- package/native-notices/crates/cfg-if-1.0.4/license-apache +201 -0
- package/native-notices/crates/cfg-if-1.0.4/license-mit +25 -0
- package/native-notices/crates/cfg_aliases-0.2.2/license +9 -0
- package/native-notices/crates/cfg_aliases-0.2.2/notices.md +26 -0
- package/native-notices/crates/find-msvc-tools-0.1.14/license-apache +201 -0
- package/native-notices/crates/find-msvc-tools-0.1.14/license-mit +25 -0
- package/native-notices/crates/itoa-1.0.18/license-apache +176 -0
- package/native-notices/crates/itoa-1.0.18/license-mit +23 -0
- package/native-notices/crates/libc-0.2.189/license-apache +176 -0
- package/native-notices/crates/libc-0.2.189/license-mit +25 -0
- package/native-notices/crates/memchr-2.8.3/copying +3 -0
- package/native-notices/crates/memchr-2.8.3/license-mit +21 -0
- package/native-notices/crates/memchr-2.8.3/unlicense +24 -0
- package/native-notices/crates/nix-0.30.1/license +21 -0
- package/native-notices/crates/proc-macro2-1.0.107/license-apache +176 -0
- package/native-notices/crates/proc-macro2-1.0.107/license-mit +23 -0
- package/native-notices/crates/quote-1.0.47/license-apache +176 -0
- package/native-notices/crates/quote-1.0.47/license-mit +23 -0
- package/native-notices/crates/serde-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_core-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde_core-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_derive-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde_derive-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_json-1.0.151/license-apache +176 -0
- package/native-notices/crates/serde_json-1.0.151/license-mit +23 -0
- package/native-notices/crates/shlex-2.0.1/license-apache +13 -0
- package/native-notices/crates/shlex-2.0.1/license-mit +21 -0
- package/native-notices/crates/syn-3.0.3/license-apache +176 -0
- package/native-notices/crates/syn-3.0.3/license-mit +23 -0
- package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-apache +201 -0
- package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-mit +25 -0
- package/native-notices/crates/tikv-jemallocator-0.7.0/license-apache +201 -0
- package/native-notices/crates/tikv-jemallocator-0.7.0/license-mit +25 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-apache +176 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-mit +23 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-unicode +39 -0
- package/native-notices/crates/zmij-1.0.23/license-mit +23 -0
- package/native-notices/manifest.json +763 -0
- package/native-notices/native/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/jemalloc-5.3.1/jemalloc-copying +27 -0
- package/native-notices/readme.md +46 -0
- package/native-notices/runtime/gcc/gpl-3.0.txt +674 -0
- package/native-notices/runtime/gcc/runtime-library-exception-3.1.txt +73 -0
- package/native-notices/runtime/libunwind-22.1.2/license.txt +311 -0
- package/native-notices/runtime/musl-1.2.5/copyright +193 -0
- package/native-notices/rust/compiler-builtins-license.txt +275 -0
- package/native-notices/rust/copyright-library.html +8266 -0
- package/native-notices/rust/crates/addr2line-0.25.1/license-apache +201 -0
- package/native-notices/rust/crates/addr2line-0.25.1/license-mit +25 -0
- package/native-notices/rust/crates/adler2-2.0.1/license-0bsd +12 -0
- package/native-notices/rust/crates/adler2-2.0.1/license-apache +201 -0
- package/native-notices/rust/crates/adler2-2.0.1/license-mit +23 -0
- package/native-notices/rust/crates/memchr-2.7.6/copying +3 -0
- package/native-notices/rust/crates/memchr-2.7.6/license-mit +21 -0
- package/native-notices/rust/crates/memchr-2.7.6/unlicense +24 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license +25 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license-apache.md +177 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license-mit.md +24 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license-zlib.md +14 -0
- package/native-notices/rust/crates/object-0.37.3/license-apache +201 -0
- package/native-notices/rust/crates/object-0.37.3/license-mit +25 -0
- package/native-notices/rust/licenses/apache-2.0.txt +73 -0
- package/native-notices/rust/licenses/bsd-2-clause.txt +9 -0
- package/native-notices/rust/licenses/cc-by-sa-4.0.txt +427 -0
- package/native-notices/rust/licenses/gcc-exception-3.1.txt +30 -0
- package/native-notices/rust/licenses/gpl-2.0-only.txt +133 -0
- package/native-notices/rust/licenses/gpl-3.0-or-later.txt +202 -0
- package/native-notices/rust/licenses/isc.txt +7 -0
- package/native-notices/rust/licenses/llvm-exception.txt +15 -0
- package/native-notices/rust/licenses/mit.txt +9 -0
- package/native-notices/rust/licenses/ncsa.txt +29 -0
- package/native-notices/rust/licenses/ofl-1.1.txt +43 -0
- package/native-notices/rust/licenses/unicode-3.0.txt +39 -0
- package/package.json +31 -26
- package/readme.md +157 -95
- package/rust/.cargo/config.toml +1 -1
- package/rust/Cargo.lock +1 -0
- package/rust/Cargo.toml +3 -2
- package/rust/src/cpio.rs +147 -0
- package/rust/src/extfs.rs +747 -0
- package/rust/src/guest.rs +2411 -0
- package/rust/src/lib.rs +197 -1
- package/rust/src/main.rs +7 -2
- package/rust/src/oci_tar.rs +842 -0
- package/rust-toolchain.toml +4 -0
- package/ts/00_commitinfo_data.ts +2 -2
- package/ts/api-client.ts +29 -8
- package/ts/artifact-manager.ts +9 -7
- package/ts/attempt-state.ts +75 -84
- package/ts/cache-manager.ts +22 -28
- package/ts/cli-entry.ts +17 -0
- package/ts/cli.ts +86 -53
- package/ts/config.ts +146 -62
- package/ts/egress-proxy.ts +649 -0
- package/ts/errors.ts +19 -0
- package/ts/filesystem.ts +316 -0
- package/ts/index.ts +20 -15
- package/ts/interfaces.ts +105 -23
- package/ts/log-sender.ts +4 -4
- package/ts/microvm-executor.ts +1265 -0
- package/ts/node-version.ts +49 -0
- package/ts/npm-grants.ts +49 -0
- package/ts/oci-registry.ts +649 -0
- package/ts/plugins.ts +25 -3
- package/ts/protocol-validator.ts +34 -30
- package/ts/redactor.ts +2 -2
- package/ts/registration-state.ts +82 -90
- package/ts/runner.ts +81 -34
- package/ts/source-workspace.ts +11 -8
- package/ts/spec-version.ts +2 -2
- package/ts/staging-scavenger.ts +37 -26
- package/ts/state-owner.ts +353 -0
- package/ts/transfer-archive.ts +214 -243
- package/ts/validation.ts +1 -1
- package/ts/vsock-protocol.ts +437 -0
- package/ts/wire-schema.ts +3 -3
- package/deno.json +0 -56
- package/deno.lock +0 -1495
- package/dist_npm/mod.d.ts +0 -967
- package/dist_npm/mod.js +0 -10058
- package/mod.ts +0 -8
- package/musl-copyright.md +0 -81
- package/third-party-licenses.md +0 -187
- package/ts/oci-executor.ts +0 -3137
package/ts/transfer-archive.ts
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import {
|
|
3
|
+
asyncIteratorStream,
|
|
4
|
+
createNewWriteFlags,
|
|
5
|
+
type IMakeTempOptions,
|
|
6
|
+
type IRemoveOptions,
|
|
7
|
+
isNotFound,
|
|
8
|
+
makeTempFile,
|
|
9
|
+
openReadableFile,
|
|
10
|
+
readFileChunks,
|
|
11
|
+
removePath,
|
|
12
|
+
type TFileHandle,
|
|
13
|
+
truncateExistingWriteFlags,
|
|
14
|
+
withFileHandle,
|
|
15
|
+
withFileHandleChunks,
|
|
16
|
+
withOpenFile,
|
|
17
|
+
writeAll,
|
|
18
|
+
} from './filesystem.js';
|
|
4
19
|
import {
|
|
5
20
|
ProtocolError,
|
|
6
21
|
ResourceCleanupError,
|
|
7
22
|
RunnerError,
|
|
8
23
|
SecretDisclosureError,
|
|
9
|
-
} from './errors.
|
|
24
|
+
} from './errors.js';
|
|
10
25
|
import type {
|
|
11
26
|
ISecretRedactionSet,
|
|
12
27
|
ITransferDownload,
|
|
@@ -14,7 +29,9 @@ import type {
|
|
|
14
29
|
ITransferRecord,
|
|
15
30
|
IWorkspaceTreeMetadata,
|
|
16
31
|
TOpenTransferBody,
|
|
17
|
-
} from './interfaces.
|
|
32
|
+
} from './interfaces.js';
|
|
33
|
+
|
|
34
|
+
const { dirname, join, resolve } = plugins.path;
|
|
18
35
|
|
|
19
36
|
const tarBlockSize = 512;
|
|
20
37
|
const maximumPaxHeaderBytes = 16 * 1024;
|
|
@@ -79,10 +96,10 @@ export interface ICreateTarGzipOptions {
|
|
|
79
96
|
}
|
|
80
97
|
|
|
81
98
|
export interface ITransferArchiveFileOperations {
|
|
82
|
-
makeTempFile(options:
|
|
99
|
+
makeTempFile(options: IMakeTempOptions): Promise<string>;
|
|
83
100
|
chmod(path: string, mode: number): Promise<void>;
|
|
84
|
-
remove(path: string, options?:
|
|
85
|
-
openRead?(path: string): Promise<
|
|
101
|
+
remove(path: string, options?: IRemoveOptions): Promise<void>;
|
|
102
|
+
openRead?(path: string): Promise<TFileHandle>;
|
|
86
103
|
}
|
|
87
104
|
|
|
88
105
|
export interface IPreparedTransferArchive {
|
|
@@ -143,10 +160,10 @@ const checkedMultiply = (left: number, right: number, message: string): number =
|
|
|
143
160
|
};
|
|
144
161
|
|
|
145
162
|
const defaultFileOperations: ITransferArchiveFileOperations = {
|
|
146
|
-
makeTempFile: (options) =>
|
|
147
|
-
chmod: (path, mode) =>
|
|
148
|
-
remove: (path, options) =>
|
|
149
|
-
openRead: (path) =>
|
|
163
|
+
makeTempFile: (options) => makeTempFile(options),
|
|
164
|
+
chmod: (path, mode) => plugins.fs.chmod(path, mode),
|
|
165
|
+
remove: (path, options) => removePath(path, options),
|
|
166
|
+
openRead: (path) => plugins.fs.open(path, 'r'),
|
|
150
167
|
};
|
|
151
168
|
|
|
152
169
|
export const removePathIfPresent = async (
|
|
@@ -157,7 +174,7 @@ export const removePathIfPresent = async (
|
|
|
157
174
|
try {
|
|
158
175
|
await remove(path, { recursive });
|
|
159
176
|
} catch (error) {
|
|
160
|
-
if (!(error
|
|
177
|
+
if (!isNotFound(error)) {
|
|
161
178
|
throw new ResourceCleanupError(`Unable to remove owned path ${path}`, [error]);
|
|
162
179
|
}
|
|
163
180
|
}
|
|
@@ -196,25 +213,21 @@ export const ensureStagingCapacity = async (
|
|
|
196
213
|
checkedInteger(requiredInodes, 'Required staging inodes');
|
|
197
214
|
checkedInteger(reserveBytes, 'Transfer staging byte reserve');
|
|
198
215
|
checkedInteger(reserveInodes, 'Transfer staging inode reserve');
|
|
199
|
-
let
|
|
216
|
+
let statistics: plugins.BigIntStatsFs;
|
|
200
217
|
try {
|
|
201
|
-
|
|
202
|
-
args: ['--file-system', '--format=%a %S %d', '--', path],
|
|
203
|
-
stdin: 'null',
|
|
204
|
-
stdout: 'piped',
|
|
205
|
-
stderr: 'piped',
|
|
206
|
-
}).output();
|
|
218
|
+
statistics = await plugins.fs.statfs(path, { bigint: true });
|
|
207
219
|
} catch (error) {
|
|
208
220
|
throw new RunnerError('Unable to inspect transfer staging capacity', { cause: error });
|
|
209
221
|
}
|
|
210
|
-
|
|
211
|
-
|
|
222
|
+
// Available block counts are in units of the fundamental block (fragment) size, `f_frsize`;
|
|
223
|
+
// `bsize` is only the optimal transfer size. `frsize` needs Node.js 26.1 or later.
|
|
224
|
+
const fragmentSize: bigint | undefined = statistics.frsize;
|
|
225
|
+
if (typeof fragmentSize !== 'bigint' || fragmentSize <= 0n) {
|
|
226
|
+
throw new RunnerError('Transfer staging filesystem did not report its fragment size');
|
|
212
227
|
}
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
const availableBytes = BigInt(match[1]) * blockSize;
|
|
217
|
-
const availableInodes = BigInt(match[3]);
|
|
228
|
+
const blockSize = fragmentSize;
|
|
229
|
+
const availableBytes = statistics.bavail * blockSize;
|
|
230
|
+
const availableInodes = statistics.ffree;
|
|
218
231
|
if (availableBytes < 0n || availableInodes < 0n) {
|
|
219
232
|
throw new RunnerError('Transfer staging filesystem returned invalid capacity');
|
|
220
233
|
}
|
|
@@ -289,15 +302,6 @@ const cancelBody = async (
|
|
|
289
302
|
throw error;
|
|
290
303
|
};
|
|
291
304
|
|
|
292
|
-
const writeAll = async (file: Deno.FsFile, value: Uint8Array): Promise<void> => {
|
|
293
|
-
let offset = 0;
|
|
294
|
-
while (offset < value.byteLength) {
|
|
295
|
-
const written = await file.write(value.subarray(offset));
|
|
296
|
-
if (written <= 0) throw new RunnerError('Transfer staging write made no progress');
|
|
297
|
-
offset += written;
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
|
|
301
305
|
export const stageTransferDownload = async (
|
|
302
306
|
download: ITransferDownload,
|
|
303
307
|
options: {
|
|
@@ -324,7 +328,7 @@ export const stageTransferDownload = async (
|
|
|
324
328
|
let path: string | undefined;
|
|
325
329
|
let cleanup: (() => Promise<void>) | undefined;
|
|
326
330
|
try {
|
|
327
|
-
await
|
|
331
|
+
await plugins.fs.mkdir(options.directory, { recursive: true, mode: 0o700 });
|
|
328
332
|
await ensureStagingCapacity(
|
|
329
333
|
options.directory,
|
|
330
334
|
download.sizeBytes,
|
|
@@ -345,7 +349,7 @@ export const stageTransferDownload = async (
|
|
|
345
349
|
if (!path || !cleanup) {
|
|
346
350
|
throw new RunnerError('Transfer staging path ownership was not established');
|
|
347
351
|
}
|
|
348
|
-
const digest = createHash('sha256');
|
|
352
|
+
const digest = plugins.crypto.createHash('sha256');
|
|
349
353
|
let reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
350
354
|
try {
|
|
351
355
|
reader = download.body.getReader();
|
|
@@ -360,29 +364,35 @@ export const stageTransferDownload = async (
|
|
|
360
364
|
}
|
|
361
365
|
throw error;
|
|
362
366
|
}
|
|
363
|
-
let file: Deno.FsFile | undefined;
|
|
364
367
|
let sizeBytes = 0;
|
|
365
368
|
let primaryError: unknown;
|
|
366
369
|
try {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
370
|
+
await withOpenFile(
|
|
371
|
+
path,
|
|
372
|
+
truncateExistingWriteFlags(),
|
|
373
|
+
undefined,
|
|
374
|
+
async (file) => {
|
|
375
|
+
while (true) {
|
|
376
|
+
if (options.signal?.aborted) throw options.signal.reason;
|
|
377
|
+
const { done, value } = await reader.read();
|
|
378
|
+
if (done) break;
|
|
379
|
+
if (value.byteLength === 0) continue;
|
|
380
|
+
sizeBytes = checkedAdd(sizeBytes, value.byteLength, 'Transfer body length overflow');
|
|
381
|
+
if (sizeBytes > download.sizeBytes || sizeBytes > options.limits.maximumArchiveBytes) {
|
|
382
|
+
throw new ProtocolError(`${options.label} body exceeded its declared length`);
|
|
383
|
+
}
|
|
384
|
+
digest.update(value);
|
|
385
|
+
await writeAll(file, value, 'Transfer staging write made no progress');
|
|
386
|
+
}
|
|
387
|
+
if (sizeBytes !== download.sizeBytes) {
|
|
388
|
+
throw new ProtocolError(`${options.label} body length did not match its declaration`);
|
|
389
|
+
}
|
|
390
|
+
if (digest.digest('hex') !== download.sha256) {
|
|
391
|
+
throw new ProtocolError(`${options.label} SHA-256 did not match its declaration`);
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
'Transfer staging stream cleanup failed',
|
|
395
|
+
);
|
|
386
396
|
} catch (error) {
|
|
387
397
|
primaryError = error;
|
|
388
398
|
try {
|
|
@@ -394,21 +404,12 @@ export const stageTransferDownload = async (
|
|
|
394
404
|
);
|
|
395
405
|
}
|
|
396
406
|
} finally {
|
|
397
|
-
const cleanupErrors: unknown[] = [];
|
|
398
407
|
try {
|
|
399
408
|
reader.releaseLock();
|
|
400
409
|
} catch (error) {
|
|
401
|
-
cleanupErrors.push(error);
|
|
402
|
-
}
|
|
403
|
-
try {
|
|
404
|
-
file?.close();
|
|
405
|
-
} catch (error) {
|
|
406
|
-
cleanupErrors.push(error);
|
|
407
|
-
}
|
|
408
|
-
if (cleanupErrors.length > 0) {
|
|
409
410
|
primaryError = new ResourceCleanupError(
|
|
410
411
|
'Transfer staging stream cleanup failed',
|
|
411
|
-
primaryError === undefined ?
|
|
412
|
+
primaryError === undefined ? [error] : [primaryError, error],
|
|
412
413
|
);
|
|
413
414
|
}
|
|
414
415
|
}
|
|
@@ -709,7 +710,7 @@ class StreamBytes {
|
|
|
709
710
|
private async pull(): Promise<void> {
|
|
710
711
|
if (this.done) return;
|
|
711
712
|
if (this.signal?.aborted) throw this.signal.reason;
|
|
712
|
-
let result:
|
|
713
|
+
let result: Awaited<ReturnType<ReadableStreamDefaultReader<Uint8Array>['read']>>;
|
|
713
714
|
try {
|
|
714
715
|
result = await this.reader.read();
|
|
715
716
|
} catch (error) {
|
|
@@ -1062,9 +1063,9 @@ const addPathMetadataBytes = (
|
|
|
1062
1063
|
};
|
|
1063
1064
|
|
|
1064
1065
|
const effectivePathMetadataLimit = (configured?: number): number => {
|
|
1065
|
-
const limit = configured ?? maximumArchivePathMetadataBytes;
|
|
1066
|
+
const limit = configured ?? plugins.maximumArchivePathMetadataBytes;
|
|
1066
1067
|
checkedInteger(limit, 'Maximum archive path metadata bytes', false);
|
|
1067
|
-
if (limit > maximumArchivePathMetadataBytes) {
|
|
1068
|
+
if (limit > plugins.maximumArchivePathMetadataBytes) {
|
|
1068
1069
|
throw new ProtocolError('Maximum archive path metadata bytes exceeds the protocol ceiling');
|
|
1069
1070
|
}
|
|
1070
1071
|
return limit;
|
|
@@ -1094,13 +1095,13 @@ const maximumTarStreamBytes = (maximumExtractedBytes: number, maximumEntries: nu
|
|
|
1094
1095
|
|
|
1095
1096
|
const assertEmptyDirectory = async (path: string): Promise<string> => {
|
|
1096
1097
|
const absolute = resolve(path);
|
|
1097
|
-
const stat = await
|
|
1098
|
+
const stat = await plugins.fs.lstat(absolute).catch((error) => {
|
|
1098
1099
|
throw new RunnerError('Unable to inspect archive extraction root', { cause: error });
|
|
1099
1100
|
});
|
|
1100
|
-
if (!stat.isDirectory || stat.
|
|
1101
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
1101
1102
|
throw new RunnerError('Archive extraction root must be a real directory');
|
|
1102
1103
|
}
|
|
1103
|
-
|
|
1104
|
+
if ((await plugins.fs.readdir(absolute)).length > 0) {
|
|
1104
1105
|
throw new RunnerError('Archive extraction root must be empty');
|
|
1105
1106
|
}
|
|
1106
1107
|
return absolute;
|
|
@@ -1118,21 +1119,41 @@ const parseTarGzip = async (
|
|
|
1118
1119
|
options.maximumPathMetadataBytes,
|
|
1119
1120
|
);
|
|
1120
1121
|
const maximumMaterializedEntries = effectiveMaterializedEntryLimit(options);
|
|
1121
|
-
const archive = await
|
|
1122
|
+
const archive = await plugins.fs.open(options.archivePath, 'r').catch((error) => {
|
|
1122
1123
|
throw new RunnerError('Unable to open staged transfer archive', { cause: error });
|
|
1123
1124
|
});
|
|
1125
|
+
return await withFileHandle(
|
|
1126
|
+
archive,
|
|
1127
|
+
(archiveHandle) =>
|
|
1128
|
+
parseOpenTarGzip(
|
|
1129
|
+
options,
|
|
1130
|
+
destination,
|
|
1131
|
+
extract,
|
|
1132
|
+
archiveHandle,
|
|
1133
|
+
allowedPaths,
|
|
1134
|
+
maximumPathMetadataBytes,
|
|
1135
|
+
maximumMaterializedEntries,
|
|
1136
|
+
),
|
|
1137
|
+
'Transfer archive close failed',
|
|
1138
|
+
);
|
|
1139
|
+
};
|
|
1140
|
+
|
|
1141
|
+
const parseOpenTarGzip = async (
|
|
1142
|
+
options: IExtractTarGzipOptions,
|
|
1143
|
+
destination: string,
|
|
1144
|
+
extract: boolean,
|
|
1145
|
+
archive: TFileHandle,
|
|
1146
|
+
allowedPaths: string[] | undefined,
|
|
1147
|
+
maximumPathMetadataBytes: number,
|
|
1148
|
+
maximumMaterializedEntries: number,
|
|
1149
|
+
): Promise<IExtractedArchiveMetadata> => {
|
|
1124
1150
|
let decompressed: ReadableStream<Uint8Array>;
|
|
1125
1151
|
try {
|
|
1126
|
-
decompressed = archive
|
|
1152
|
+
decompressed = asyncIteratorStream(readFileChunks(archive, streamBufferBytes))
|
|
1153
|
+
.pipeThrough(
|
|
1154
|
+
new DecompressionStream('gzip') as unknown as TransformStream<Uint8Array, Uint8Array>,
|
|
1155
|
+
);
|
|
1127
1156
|
} catch (error) {
|
|
1128
|
-
try {
|
|
1129
|
-
archive.close();
|
|
1130
|
-
} catch (cleanupError) {
|
|
1131
|
-
throw new ResourceCleanupError('Transfer archive setup cleanup failed', [
|
|
1132
|
-
error,
|
|
1133
|
-
cleanupError,
|
|
1134
|
-
]);
|
|
1135
|
-
}
|
|
1136
1157
|
throw new ProtocolError('Transfer archive is not valid gzip data', { cause: error });
|
|
1137
1158
|
}
|
|
1138
1159
|
const bytes = new StreamBytes(
|
|
@@ -1265,8 +1286,8 @@ const parseTarGzip = async (
|
|
|
1265
1286
|
throw new ProtocolError('Tar directory metadata is invalid');
|
|
1266
1287
|
}
|
|
1267
1288
|
if (extract) {
|
|
1268
|
-
await
|
|
1269
|
-
await
|
|
1289
|
+
await plugins.fs.mkdir(target, { recursive: true, mode: 0o700 });
|
|
1290
|
+
await plugins.fs.chmod(target, 0o700);
|
|
1270
1291
|
}
|
|
1271
1292
|
} else if (entryType === 'symlink') {
|
|
1272
1293
|
if (options.allowSymlinks === false) {
|
|
@@ -1293,32 +1314,24 @@ const parseTarGzip = async (
|
|
|
1293
1314
|
) {
|
|
1294
1315
|
throw new ProtocolError('Tar archive exceeds the effective extracted byte limit');
|
|
1295
1316
|
}
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
await bytes.consume(sizeBytes, output ? (value) => writeAll(output!, value) : undefined);
|
|
1308
|
-
} catch (error) {
|
|
1309
|
-
entryError = error;
|
|
1310
|
-
}
|
|
1311
|
-
try {
|
|
1312
|
-
output?.close();
|
|
1313
|
-
} catch (cleanupError) {
|
|
1314
|
-
throw new ResourceCleanupError(
|
|
1317
|
+
if (extract) {
|
|
1318
|
+
await plugins.fs.mkdir(dirname(target), { recursive: true, mode: 0o700 });
|
|
1319
|
+
await withOpenFile(
|
|
1320
|
+
target,
|
|
1321
|
+
createNewWriteFlags,
|
|
1322
|
+
(mode & 0o111) !== 0 ? 0o700 : 0o600,
|
|
1323
|
+
async (output) =>
|
|
1324
|
+
await bytes.consume(
|
|
1325
|
+
sizeBytes,
|
|
1326
|
+
(value) => writeAll(output, value, 'Transfer staging write made no progress'),
|
|
1327
|
+
),
|
|
1315
1328
|
'Archive extraction file cleanup failed',
|
|
1316
|
-
entryError === undefined ? [cleanupError] : [entryError, cleanupError],
|
|
1317
1329
|
);
|
|
1330
|
+
} else {
|
|
1331
|
+
await bytes.consume(sizeBytes);
|
|
1318
1332
|
}
|
|
1319
|
-
if (entryError !== undefined) throw entryError;
|
|
1320
1333
|
if (extract) {
|
|
1321
|
-
await
|
|
1334
|
+
await plugins.fs.chmod(target, (mode & 0o111) !== 0 ? 0o700 : 0o600);
|
|
1322
1335
|
}
|
|
1323
1336
|
}
|
|
1324
1337
|
if (padding) {
|
|
@@ -1351,8 +1364,8 @@ const parseTarGzip = async (
|
|
|
1351
1364
|
for (const symlink of symlinks) {
|
|
1352
1365
|
if (options.signal?.aborted) throw options.signal.reason;
|
|
1353
1366
|
const target = join(destination, ...symlink.path.split('/'));
|
|
1354
|
-
await
|
|
1355
|
-
await
|
|
1367
|
+
await plugins.fs.mkdir(dirname(target), { recursive: true, mode: 0o700 });
|
|
1368
|
+
await plugins.fs.symlink(symlink.target, target);
|
|
1356
1369
|
}
|
|
1357
1370
|
}
|
|
1358
1371
|
complete = true;
|
|
@@ -1407,19 +1420,10 @@ export const extractTarGzipArchive = async (
|
|
|
1407
1420
|
};
|
|
1408
1421
|
|
|
1409
1422
|
const snapshotFor = (
|
|
1410
|
-
stat:
|
|
1423
|
+
stat: plugins.Stats,
|
|
1411
1424
|
type: TArchiveEntryType,
|
|
1412
1425
|
label: string,
|
|
1413
1426
|
): IFileSnapshot => {
|
|
1414
|
-
if (
|
|
1415
|
-
stat.dev === null ||
|
|
1416
|
-
stat.ino === null ||
|
|
1417
|
-
stat.nlink === null ||
|
|
1418
|
-
stat.mode === null ||
|
|
1419
|
-
stat.size === null
|
|
1420
|
-
) {
|
|
1421
|
-
throw new RunnerError(`${label} does not expose stable filesystem metadata`);
|
|
1422
|
-
}
|
|
1423
1427
|
return {
|
|
1424
1428
|
type,
|
|
1425
1429
|
dev: stat.dev,
|
|
@@ -1427,19 +1431,19 @@ const snapshotFor = (
|
|
|
1427
1431
|
nlink: stat.nlink,
|
|
1428
1432
|
size: stat.size,
|
|
1429
1433
|
mode: stat.mode,
|
|
1430
|
-
mtime: stat.mtime
|
|
1434
|
+
mtime: stat.mtime.getTime(),
|
|
1431
1435
|
};
|
|
1432
1436
|
};
|
|
1433
1437
|
|
|
1434
|
-
const typeForStat = (stat:
|
|
1435
|
-
if (stat.isDirectory) return 'directory';
|
|
1436
|
-
if (stat.isFile) return 'file';
|
|
1437
|
-
if (stat.
|
|
1438
|
+
const typeForStat = (stat: plugins.Stats): TArchiveEntryType => {
|
|
1439
|
+
if (stat.isDirectory()) return 'directory';
|
|
1440
|
+
if (stat.isFile()) return 'file';
|
|
1441
|
+
if (stat.isSymbolicLink()) return 'symlink';
|
|
1438
1442
|
throw new RunnerError('Workspace export contains a special filesystem entry');
|
|
1439
1443
|
};
|
|
1440
1444
|
|
|
1441
1445
|
const assertSnapshot = async (path: string, expected: IFileSnapshot): Promise<void> => {
|
|
1442
|
-
const stat = await
|
|
1446
|
+
const stat = await plugins.fs.lstat(path).catch((error) => {
|
|
1443
1447
|
throw new RunnerError('Workspace export changed during archive creation', { cause: error });
|
|
1444
1448
|
});
|
|
1445
1449
|
const current = snapshotFor(stat, typeForStat(stat), 'Workspace export entry');
|
|
@@ -1492,11 +1496,11 @@ const collectArchiveEntries = async (
|
|
|
1492
1496
|
selectedEntryScope: descendantScope.slice(0, -1),
|
|
1493
1497
|
});
|
|
1494
1498
|
}
|
|
1495
|
-
const root = await
|
|
1499
|
+
const root = await plugins.fs.realpath(options.sourcePath).catch((error) => {
|
|
1496
1500
|
throw new RunnerError('Unable to resolve workspace export root', { cause: error });
|
|
1497
1501
|
});
|
|
1498
|
-
const rootStat = await
|
|
1499
|
-
if (!rootStat.isDirectory || rootStat.
|
|
1502
|
+
const rootStat = await plugins.fs.lstat(root);
|
|
1503
|
+
if (!rootStat.isDirectory() || rootStat.isSymbolicLink()) {
|
|
1500
1504
|
throw new RunnerError('Workspace export root must be a real directory');
|
|
1501
1505
|
}
|
|
1502
1506
|
const rootSnapshot = snapshotFor(rootStat, 'directory', 'Workspace export root');
|
|
@@ -1530,11 +1534,11 @@ const collectArchiveEntries = async (
|
|
|
1530
1534
|
parentPath: string,
|
|
1531
1535
|
): Promise<Array<{ name: string; nameBytes: Uint8Array; pathBytes: number } | undefined>> => {
|
|
1532
1536
|
const children: Array<{ name: string; nameBytes: Uint8Array; pathBytes: number }> = [];
|
|
1533
|
-
for
|
|
1537
|
+
for (const childName of await plugins.fs.readdir(absolutePath)) {
|
|
1534
1538
|
if (options.signal?.aborted) throw options.signal.reason;
|
|
1535
|
-
const childPath = parentPath ? `${parentPath}/${
|
|
1539
|
+
const childPath = parentPath ? `${parentPath}/${childName}` : childName;
|
|
1536
1540
|
pathSegments(childPath, maximumPathBytes, 'Workspace export');
|
|
1537
|
-
const nameBytes = textEncoder.encode(
|
|
1541
|
+
const nameBytes = textEncoder.encode(childName);
|
|
1538
1542
|
const pathBytes = textEncoder.encode(childPath).byteLength;
|
|
1539
1543
|
const nextPendingEntries = checkedAdd(
|
|
1540
1544
|
pendingEntries,
|
|
@@ -1567,7 +1571,7 @@ const collectArchiveEntries = async (
|
|
|
1567
1571
|
}
|
|
1568
1572
|
pendingEntries = nextPendingEntries;
|
|
1569
1573
|
pendingPathMetadataBytes = nextPendingPathMetadataBytes;
|
|
1570
|
-
children.push({ name:
|
|
1574
|
+
children.push({ name: childName, nameBytes, pathBytes });
|
|
1571
1575
|
}
|
|
1572
1576
|
return await orderByUtf8Bytes(children, (child) => child.nameBytes, options.signal);
|
|
1573
1577
|
};
|
|
@@ -1576,7 +1580,7 @@ const collectArchiveEntries = async (
|
|
|
1576
1580
|
pathSegments(path, maximumPathBytes, 'Workspace export');
|
|
1577
1581
|
retainPathMetadata(path);
|
|
1578
1582
|
const absolutePath = join(root, ...path.split('/'));
|
|
1579
|
-
const stat = await
|
|
1583
|
+
const stat = await plugins.fs.lstat(absolutePath);
|
|
1580
1584
|
const type = typeForStat(stat);
|
|
1581
1585
|
const membership = selectedMembership(path, type, selections);
|
|
1582
1586
|
if (!membership.accepted) {
|
|
@@ -1595,7 +1599,7 @@ const collectArchiveEntries = async (
|
|
|
1595
1599
|
let linkTarget: string | undefined;
|
|
1596
1600
|
let symlinkScope: string[] | undefined;
|
|
1597
1601
|
if (type === 'symlink') {
|
|
1598
|
-
linkTarget = await
|
|
1602
|
+
linkTarget = await plugins.fs.readlink(absolutePath);
|
|
1599
1603
|
validateLinkTarget(linkTarget);
|
|
1600
1604
|
retainPathMetadata(linkTarget);
|
|
1601
1605
|
const selectionScopes = scopesBySelection.get(membership.selected!)!;
|
|
@@ -1766,15 +1770,15 @@ const assertSafeAncestors = async (root: string, path: string, device: number):
|
|
|
1766
1770
|
let current = root;
|
|
1767
1771
|
for (const segment of segments) {
|
|
1768
1772
|
current = join(current, segment);
|
|
1769
|
-
const stat = await
|
|
1770
|
-
if (!stat.isDirectory || stat.
|
|
1773
|
+
const stat = await plugins.fs.lstat(current);
|
|
1774
|
+
if (!stat.isDirectory() || stat.isSymbolicLink() || stat.dev !== device) {
|
|
1771
1775
|
throw new RunnerError('Workspace export path changed or crossed a boundary');
|
|
1772
1776
|
}
|
|
1773
1777
|
}
|
|
1774
1778
|
};
|
|
1775
1779
|
|
|
1776
1780
|
const assertOpenFileSnapshot = async (
|
|
1777
|
-
file: Pick<
|
|
1781
|
+
file: Pick<TFileHandle, 'stat'>,
|
|
1778
1782
|
expected: IFileSnapshot,
|
|
1779
1783
|
): Promise<void> => {
|
|
1780
1784
|
const stat = await file.stat();
|
|
@@ -1792,6 +1796,29 @@ const assertOpenFileSnapshot = async (
|
|
|
1792
1796
|
}
|
|
1793
1797
|
};
|
|
1794
1798
|
|
|
1799
|
+
async function* exportFileChunks(
|
|
1800
|
+
file: TFileHandle,
|
|
1801
|
+
entry: IArchiveEntry,
|
|
1802
|
+
redactionSet: ISecretRedactionSet,
|
|
1803
|
+
signal?: AbortSignal,
|
|
1804
|
+
): AsyncGenerator<Uint8Array> {
|
|
1805
|
+
await assertOpenFileSnapshot(file, entry.snapshot);
|
|
1806
|
+
const contentMatcher = redactionSet.empty ? undefined : redactionSet.createContentMatcher();
|
|
1807
|
+
let emitted = 0;
|
|
1808
|
+
for await (const content of readFileChunks(file, streamBufferBytes, signal)) {
|
|
1809
|
+
emitted = checkedAdd(emitted, content.byteLength, 'Workspace export file length overflow');
|
|
1810
|
+
if (emitted > entry.sizeBytes) {
|
|
1811
|
+
throw new RunnerError('Workspace export file grew during archive creation');
|
|
1812
|
+
}
|
|
1813
|
+
if (contentMatcher?.push(content)) throw new SecretDisclosureError();
|
|
1814
|
+
yield content;
|
|
1815
|
+
}
|
|
1816
|
+
if (emitted !== entry.sizeBytes) {
|
|
1817
|
+
throw new RunnerError('Workspace export file shrank during archive creation');
|
|
1818
|
+
}
|
|
1819
|
+
await assertOpenFileSnapshot(file, entry.snapshot);
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1795
1822
|
async function* tarChunks(
|
|
1796
1823
|
entries: IArchiveEntry[],
|
|
1797
1824
|
root: string,
|
|
@@ -1838,54 +1865,16 @@ async function* tarChunks(
|
|
|
1838
1865
|
const type = entry.type === 'directory' ? '5' : entry.type === 'symlink' ? '2' : '0';
|
|
1839
1866
|
yield tarHeader(pathField, type, entry.sizeBytes, entry.executable, linkField);
|
|
1840
1867
|
if (entry.type === 'file') {
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
[Symbol.dispose]: () => file.close(),
|
|
1847
|
-
};
|
|
1848
|
-
try {
|
|
1849
|
-
await assertOpenFileSnapshot(file, entry.snapshot);
|
|
1850
|
-
const contentMatcher = redactionSet.empty
|
|
1851
|
-
? undefined
|
|
1852
|
-
: redactionSet.createContentMatcher();
|
|
1853
|
-
const buffer = new Uint8Array(streamBufferBytes);
|
|
1854
|
-
let emitted = 0;
|
|
1855
|
-
while (true) {
|
|
1856
|
-
if (signal?.aborted) throw signal.reason;
|
|
1857
|
-
const read = await file.read(buffer);
|
|
1858
|
-
if (read === null) break;
|
|
1859
|
-
emitted = checkedAdd(emitted, read, 'Workspace export file length overflow');
|
|
1860
|
-
if (emitted > entry.sizeBytes) {
|
|
1861
|
-
throw new RunnerError('Workspace export file grew during archive creation');
|
|
1862
|
-
}
|
|
1863
|
-
const content = buffer.slice(0, read);
|
|
1864
|
-
if (contentMatcher?.push(content)) throw new SecretDisclosureError();
|
|
1865
|
-
yield content;
|
|
1866
|
-
}
|
|
1867
|
-
if (emitted !== entry.sizeBytes) {
|
|
1868
|
-
throw new RunnerError('Workspace export file shrank during archive creation');
|
|
1869
|
-
}
|
|
1870
|
-
await assertOpenFileSnapshot(file, entry.snapshot);
|
|
1871
|
-
} catch (error) {
|
|
1872
|
-
fileError = error;
|
|
1873
|
-
throw error;
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
} catch (error) {
|
|
1877
|
-
if (error === fileError) throw error;
|
|
1878
|
-
const cleanupError = error instanceof SuppressedError ? error.error : error;
|
|
1879
|
-
throw new ResourceCleanupError(
|
|
1880
|
-
'Workspace export file cleanup failed',
|
|
1881
|
-
fileError === undefined ? [cleanupError] : [fileError, cleanupError],
|
|
1882
|
-
);
|
|
1883
|
-
}
|
|
1868
|
+
yield* withFileHandleChunks(
|
|
1869
|
+
await openRead(entry.absolutePath),
|
|
1870
|
+
(file) => exportFileChunks(file, entry, redactionSet, signal),
|
|
1871
|
+
'Workspace export file cleanup failed',
|
|
1872
|
+
);
|
|
1884
1873
|
await assertSnapshot(entry.absolutePath, entry.snapshot);
|
|
1885
1874
|
const padding = paddingFor(entry.sizeBytes);
|
|
1886
1875
|
if (padding.byteLength) yield padding;
|
|
1887
1876
|
} else if (entry.type === 'symlink') {
|
|
1888
|
-
if (await
|
|
1877
|
+
if (await plugins.fs.readlink(entry.absolutePath) !== entry.linkTarget) {
|
|
1889
1878
|
throw new RunnerError('Workspace export symlink changed during archive creation');
|
|
1890
1879
|
}
|
|
1891
1880
|
}
|
|
@@ -1895,18 +1884,6 @@ async function* tarChunks(
|
|
|
1895
1884
|
yield zeroBlock;
|
|
1896
1885
|
}
|
|
1897
1886
|
|
|
1898
|
-
const iteratorStream = (iterator: AsyncGenerator<Uint8Array>): ReadableStream<Uint8Array> =>
|
|
1899
|
-
new ReadableStream<Uint8Array>({
|
|
1900
|
-
async pull(controller) {
|
|
1901
|
-
const result = await iterator.next();
|
|
1902
|
-
if (result.done) controller.close();
|
|
1903
|
-
else controller.enqueue(result.value);
|
|
1904
|
-
},
|
|
1905
|
-
async cancel() {
|
|
1906
|
-
await iterator.return(undefined);
|
|
1907
|
-
},
|
|
1908
|
-
});
|
|
1909
|
-
|
|
1910
1887
|
export const createTarGzipArchive = async (
|
|
1911
1888
|
options: ICreateTarGzipOptions,
|
|
1912
1889
|
): Promise<IPreparedTransferArchive> => {
|
|
@@ -1916,7 +1893,7 @@ export const createTarGzipArchive = async (
|
|
|
1916
1893
|
checkedInteger(options.expectedMetadata.logicalBytes, 'Workspace export logical bytes');
|
|
1917
1894
|
checkedInteger(options.expectedMetadata.entryCount, 'Workspace export entry count');
|
|
1918
1895
|
const collected = await collectArchiveEntries(options);
|
|
1919
|
-
await
|
|
1896
|
+
await plugins.fs.mkdir(options.archiveDirectory, { recursive: true, mode: 0o700 });
|
|
1920
1897
|
const fileOperations = options.fileOperations ?? defaultFileOperations;
|
|
1921
1898
|
const path = await fileOperations.makeTempFile({
|
|
1922
1899
|
dir: options.archiveDirectory,
|
|
@@ -1937,64 +1914,66 @@ export const createTarGzipArchive = async (
|
|
|
1937
1914
|
}
|
|
1938
1915
|
throw error;
|
|
1939
1916
|
}
|
|
1940
|
-
const digest = createHash('sha256');
|
|
1917
|
+
const digest = plugins.crypto.createHash('sha256');
|
|
1941
1918
|
let sizeBytes = 0;
|
|
1942
|
-
let output: Deno.FsFile | undefined;
|
|
1943
1919
|
let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;
|
|
1944
1920
|
let archiveSnapshot: IFileSnapshot | undefined;
|
|
1945
1921
|
try {
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1922
|
+
await withOpenFile(
|
|
1923
|
+
path,
|
|
1924
|
+
truncateExistingWriteFlags(),
|
|
1925
|
+
undefined,
|
|
1926
|
+
async (output) => {
|
|
1927
|
+
const compressor = new CompressionStream('gzip') as unknown as TransformStream<
|
|
1928
|
+
Uint8Array,
|
|
1929
|
+
Uint8Array
|
|
1930
|
+
>;
|
|
1931
|
+
const compressed = asyncIteratorStream(
|
|
1932
|
+
tarChunks(
|
|
1933
|
+
collected.entries,
|
|
1934
|
+
collected.root,
|
|
1935
|
+
collected.rootSnapshot.dev,
|
|
1936
|
+
fileOperations.openRead ?? defaultFileOperations.openRead!,
|
|
1937
|
+
options.redactionSet,
|
|
1938
|
+
options.signal,
|
|
1939
|
+
),
|
|
1940
|
+
).pipeThrough(compressor);
|
|
1941
|
+
reader = compressed.getReader();
|
|
1942
|
+
while (true) {
|
|
1943
|
+
if (options.signal?.aborted) throw options.signal.reason;
|
|
1944
|
+
const { done, value } = await reader.read();
|
|
1945
|
+
if (done) break;
|
|
1946
|
+
sizeBytes = checkedAdd(sizeBytes, value.byteLength, 'Archive size overflow');
|
|
1947
|
+
if (sizeBytes > options.maximumArchiveBytes) {
|
|
1948
|
+
throw new RunnerError('Archive exceeds the effective compressed byte limit');
|
|
1949
|
+
}
|
|
1950
|
+
digest.update(value);
|
|
1951
|
+
await writeAll(output, value, 'Transfer staging write made no progress');
|
|
1952
|
+
}
|
|
1953
|
+
},
|
|
1954
|
+
'Archive stream cleanup failed',
|
|
1955
|
+
);
|
|
1973
1956
|
await assertSnapshot(collected.root, collected.rootSnapshot);
|
|
1974
1957
|
for (const entry of collected.entries) {
|
|
1975
1958
|
if (options.signal?.aborted) throw options.signal.reason;
|
|
1976
1959
|
await assertSnapshot(entry.absolutePath, entry.snapshot);
|
|
1977
1960
|
}
|
|
1978
1961
|
archiveSnapshot = snapshotFor(
|
|
1979
|
-
await
|
|
1962
|
+
await plugins.fs.lstat(path),
|
|
1980
1963
|
'file',
|
|
1981
1964
|
'Prepared transfer archive',
|
|
1982
1965
|
);
|
|
1983
1966
|
} catch (error) {
|
|
1984
1967
|
const errors = [error];
|
|
1968
|
+
const openReader = reader as ReadableStreamDefaultReader<Uint8Array> | undefined;
|
|
1985
1969
|
try {
|
|
1986
|
-
await
|
|
1970
|
+
await openReader?.cancel(error);
|
|
1987
1971
|
} catch (cleanupError) {
|
|
1988
1972
|
// Canceling a stream that already errored rejects with that same stored error.
|
|
1989
1973
|
if (cleanupError !== error) errors.push(cleanupError);
|
|
1990
1974
|
}
|
|
1991
1975
|
try {
|
|
1992
|
-
|
|
1993
|
-
} catch (cleanupError) {
|
|
1994
|
-
errors.push(cleanupError);
|
|
1995
|
-
}
|
|
1996
|
-
try {
|
|
1997
|
-
output?.close();
|
|
1976
|
+
openReader?.releaseLock();
|
|
1998
1977
|
} catch (cleanupError) {
|
|
1999
1978
|
errors.push(cleanupError);
|
|
2000
1979
|
}
|
|
@@ -2008,18 +1987,10 @@ export const createTarGzipArchive = async (
|
|
|
2008
1987
|
}
|
|
2009
1988
|
throw error;
|
|
2010
1989
|
}
|
|
2011
|
-
const streamCleanupErrors: unknown[] = [];
|
|
2012
1990
|
try {
|
|
2013
|
-
reader
|
|
1991
|
+
(reader as ReadableStreamDefaultReader<Uint8Array> | undefined)?.releaseLock();
|
|
2014
1992
|
} catch (error) {
|
|
2015
|
-
streamCleanupErrors
|
|
2016
|
-
}
|
|
2017
|
-
try {
|
|
2018
|
-
output.close();
|
|
2019
|
-
} catch (error) {
|
|
2020
|
-
streamCleanupErrors.push(error);
|
|
2021
|
-
}
|
|
2022
|
-
if (streamCleanupErrors.length > 0) {
|
|
1993
|
+
const streamCleanupErrors: unknown[] = [error];
|
|
2023
1994
|
try {
|
|
2024
1995
|
await cleanup();
|
|
2025
1996
|
} catch (cleanupError) {
|
|
@@ -2047,7 +2018,7 @@ export const createTarGzipArchive = async (
|
|
|
2047
2018
|
metadata,
|
|
2048
2019
|
openBody: async () => {
|
|
2049
2020
|
await assertSnapshot(path, archiveSnapshot);
|
|
2050
|
-
return
|
|
2021
|
+
return await openReadableFile(path, streamBufferBytes, 'Transfer archive body close failed');
|
|
2051
2022
|
},
|
|
2052
2023
|
cleanup,
|
|
2053
2024
|
};
|