mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 11:47:42 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Native agents run inside remote Daytona sandboxes that require a
verified Runner provider pack
> - When a sandbox stages the provider pack into its workspace,
Paperclip copies, transfers, and verifies every
`provider-assets/<provider>` closure (~1.6 GB across pi, cursor,
copilot, kimi, and antigravity) even when the run only uses Claude,
Codex, OpenCode, or one provider
> - New image-backed Daytona sandbox environments also default to a 10
GiB disk, which leaves too little headroom for repository installs and
tests
> - This pull request stages and verifies only the
`provider-assets/<provider>` tree needed by the active run and raises
the Daytona plugin default disk size from 10 GiB to 20 GiB
> - The benefit is significantly more free workspace disk space, smaller
pack transfers, and safer default disk sizing without changing the
provider-pack archive format or breaking multi-provider workspace reuse
## Linked Issues or Issue Description
- Fixes: #19367
- Refs #19484
- Related: #19500 (ENOSPC fail-fast and full-sandbox recovery already
merged in #22068, #22239, #22383, #22466, and #22837), #22241
(deduplicated repeated bytes in staged packs)
## What Changed
- `server/src/services/native-runtime/provider-pack-compatibility.ts`:
add `requiredProviderAssetNames`, `isProviderAssetPathIncluded`, and
`providerAssetExcludeArgs` helpers that resolve the required
`provider-assets/<provider>` subset for a `PackProvider` (returning
unfiltered behavior when `provider` is omitted).
- `server/src/services/native-runtime/provider-pack-layers.ts`: filter
large layer entries by required provider assets before running the
remote reuse script and transferring missing layers, preserve
cross-provider image-twin reuse so core files can still reuse identical
bytes from excluded provider paths in the base image, and pass
`--exclude` flags to GNU `tar` for `overlay.tar.zst`.
- `server/src/services/native-runtime/provider-pack-archive.ts` and
`provider-pack-upload.ts`: forward `provider` and `manifest` into v1 and
v2 archive staging and exclude unused `provider-assets/*` during
extraction.
-
`server/src/services/native-runtime/remote-provider-pack-verification.ts`:
scope candidate asset tree digest checks to the active provider when
`provider` is passed and include `requiredAssets` in the verification
seal key so a pack verified for one provider cannot satisfy a seal check
for a different provider.
- `server/src/services/native-runtime/native-session-executor.ts` and
`server/src/services/kimi-connection-probe.ts`: pass the active
`PackProvider` to `prepareRemoteProviderPackOnTarget` and
`verifyRemoteProviderPackIdentity`.
- `packages/plugins/sandbox-providers/daytona/src/manifest.ts` and
`package.json`: raise the default `disk` allocation from `10` to `20`
GiB and bump the plugin version from `0.1.10` to `0.1.11` so
bundled-plugin boot reconciliation refreshes persisted manifests.
- Added unit and end-to-end tests in
`packages/plugins/sandbox-providers/daytona/src/plugin.test.ts`,
`server/src/services/native-runtime/provider-pack-archive.test.ts`,
`server/src/services/native-runtime/remote-provider-pack-verification.test.ts`,
and updated `server/src/__tests__/kimi-connection-probe.test.ts`.
## Verification
- **RED (before production edits):**
- `cd packages/plugins/sandbox-providers/daytona && npx vitest run
--config vitest.config.ts -t "bumps the plugin version|pre-fills
sizing|validates and passes the default 20 GiB"` — 3 failed (`0.1.10 !==
0.1.11`, `10 !== 20`).
- `cd server && npx vitest run
src/services/native-runtime/provider-pack-archive.test.ts -t "omits all
provider-assets|stages only the selected provider"` — 2 failed (unused
`provider-assets` staged on disk).
- `cd server && npx vitest run
src/services/native-runtime/remote-provider-pack-verification.test.ts -t
"verifies only the selected provider"` — 1 failed (`candidate_digest`
rejected Claude when `provider-assets/` was absent).
- **GREEN (after fix):**
- `cd server && npx tsc --noEmit -p tsconfig.json` — passed.
- `cd server && npx vitest run
src/services/native-runtime/provider-pack-archive.test.ts` — **56/56
passed**, including an end-to-end upload+verify test proving unfiltered
staging writes >= 6 MiB of provider assets, Claude staging omits all 6
MiB (< 256 KiB total) and verifies cleanly, and switching the same
workspace to Cursor rejects the Claude seal (`candidate_digest`) and
re-stages only Cursor (2 MiB, excluding Kimi and Pi).
- `cd server && npx vitest run
src/services/native-runtime/remote-provider-pack-verification.test.ts
src/services/native-runtime/remote-provider-pack.test.ts
src/services/native-runtime/retained-provider-pack-source.test.ts
src/__tests__/kimi-connection-probe.test.ts` — all passed
(`remote-provider-pack-verification.test.ts` 34/34,
`remote-provider-pack.test.ts` 60/60, `kimi-connection-probe.test.ts`
39/39, `retained-provider-pack-source.test.ts` all passed).
- `cd packages/plugins/sandbox-providers/daytona && pnpm typecheck &&
npx vitest run --config vitest.config.ts` — typecheck passed; all 15
offline test files passed (641 passed, 8 live tests skipped;
`archive-stream-window.test.ts` timed out once during parallel CPU
contention and passed in 6.17s when re-run).
- `node scripts/check-test-budget.mjs --files
server/src/services/native-runtime/provider-pack-archive.test.ts
server/src/services/native-runtime/remote-provider-pack-verification.test.ts
server/src/__tests__/kimi-connection-probe.test.ts` — passed (110
nightly suites validated, 3 test files checked).
- `pnpm verify --base 2d06567795
--explain` exited 2 because
`packages/plugins/sandbox-providers/daytona/package.json` is a global CI
input; focused suites and package typechecks ran locally and sharded PR
CI supplies broad coverage.
- **Not run locally:** Live Daytona sandbox provisioning (requires
`DAYTONA_API_KEY`). Managed Cloud snapshot disk sizing is updated
separately in the Cloud repository.
## Risks
- Low risk. Archive schema v1 and v2 remain unchanged, so existing
Docker images and retained OCI release packs work without rebuilding.
- If a reusable workspace previously staged a pack for one provider (for
example Claude) and a later run on the same workspace uses a provider
with native assets (for example Cursor), the provider-scoped
verification seal misses, `verifyStaged` fails with `candidate_digest`,
and `prepareRemoteProviderPackOnTarget` cleanly re-stages with the
needed provider assets.
- Raising the Daytona plugin default `disk` to 20 GiB only affects new
image-backed environments created with the form default; existing saved
environments and snapshot-backed environments keep their existing
configuration.
> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.
## Model Used
- Google Gemini (Antigravity agent) with shell, file editing, and local
test execution tools.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
313 lines
16 KiB
TypeScript
313 lines
16 KiB
TypeScript
import { createHash, randomUUID } from "node:crypto";
|
|
import { constants, createWriteStream } from "node:fs";
|
|
import { lstat, mkdtemp, open, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join, posix } from "node:path";
|
|
import { pipeline } from "node:stream/promises";
|
|
import type { CommandManagedRuntimeRunner } from "@paperclipai/adapter-utils/command-managed-runtime";
|
|
import type { NativeRunTrace } from "./native-run-trace.js";
|
|
import {
|
|
isProviderAssetPathIncluded,
|
|
providerAssetExcludeArgs,
|
|
requiredProviderAssetNames,
|
|
type PackProvider,
|
|
type ProviderPackIdentity,
|
|
} from "./provider-pack-compatibility.js";
|
|
import { providerPackExtractionProbe } from "./provider-pack-extraction.js";
|
|
|
|
type Archive = { sha256: string; bytes: number };
|
|
type FileLayer = Archive & { path: string; mode: number; archive: Archive };
|
|
export type ProviderPackLayers = {
|
|
kind: "layers";
|
|
sourceRoot: string;
|
|
overlay: Archive;
|
|
files: FileLayer[];
|
|
};
|
|
const quote = (value: string) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
const validArchive = (value: unknown): value is Archive => {
|
|
const entry = value as Archive | null;
|
|
return !!entry && /^[a-f0-9]{64}$/.test(entry.sha256)
|
|
&& Number.isSafeInteger(entry.bytes) && entry.bytes > 0;
|
|
};
|
|
|
|
// The run report keeps only the outer message. Name the failed check with a
|
|
// fixed reason so a recurrence is diagnosable without exposing private paths.
|
|
export const invalidArchive = (reason: string, cause?: unknown) =>
|
|
new Error(`runner_remote_provider_archive_invalid: ${reason}`, cause === undefined ? undefined : { cause });
|
|
|
|
const verifiedArchives = new Set<string>();
|
|
const archiveIdentity = (path: string, expected: Archive, metadata: { dev: number; ino: number; size: number; mtimeMs: number; ctimeMs: number }) =>
|
|
[path, expected.sha256, metadata.dev, metadata.ino, metadata.size, metadata.mtimeMs, metadata.ctimeMs].join("\0");
|
|
|
|
export async function verifyArchive(path: string, expected: Archive, signal?: AbortSignal) {
|
|
signal?.throwIfAborted();
|
|
let file;
|
|
try { file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW); }
|
|
catch (error) { throw invalidArchive("archive_unreadable", error); }
|
|
try {
|
|
const metadata = await file.stat();
|
|
if (!metadata.isFile()) throw invalidArchive("archive_not_file");
|
|
if (metadata.size !== expected.bytes) throw invalidArchive("size_mismatch");
|
|
const identity = archiveIdentity(path, expected, metadata);
|
|
if (verifiedArchives.has(identity)) return;
|
|
const hash = createHash("sha256");
|
|
for await (const chunk of file.createReadStream({ autoClose: false, signal })) hash.update(chunk);
|
|
signal?.throwIfAborted();
|
|
if (hash.digest("hex") !== expected.sha256) throw invalidArchive("sha256_mismatch");
|
|
if (verifiedArchives.size >= 1_024) verifiedArchives.clear();
|
|
verifiedArchives.add(identity);
|
|
} finally { await file.close(); }
|
|
}
|
|
|
|
export async function readProviderPackLayers(root: string, expectedDigest: string, value: unknown, signal?: AbortSignal): Promise<ProviderPackLayers> {
|
|
const receipt = value as { encoding: string; providerPackDigest: string; overlay: Archive; files: FileLayer[] };
|
|
if (receipt.providerPackDigest !== expectedDigest) throw invalidArchive("receipt_identity_mismatch");
|
|
if (receipt.encoding !== "tar+zstd"
|
|
|| !validArchive(receipt.overlay) || !Array.isArray(receipt.files) || receipt.files.length > 10_000) {
|
|
throw invalidArchive("receipt_invalid");
|
|
}
|
|
const paths = new Set<string>();
|
|
for (const file of receipt.files) {
|
|
if (!validArchive(file) || !validArchive(file.archive)
|
|
|| typeof file.path !== "string" || !file.path || file.path.length > 4096
|
|
|| file.path.startsWith("/") || file.path.includes("\\") || file.path.includes("\0")
|
|
|| file.path.split("/").some(part => !part || part === "." || part === "..")
|
|
|| !Number.isSafeInteger(file.mode) || file.mode < 0 || file.mode > 0o777 || paths.has(file.path)) {
|
|
throw invalidArchive("layer_invalid");
|
|
}
|
|
paths.add(file.path);
|
|
}
|
|
for (const path of paths) {
|
|
let parent = posix.dirname(path);
|
|
while (parent !== ".") {
|
|
if (paths.has(parent)) throw invalidArchive("layer_invalid");
|
|
parent = posix.dirname(parent);
|
|
}
|
|
}
|
|
const sourceRoot = `${root}.archives`;
|
|
const layers = await lstat(sourceRoot).catch(error => { throw invalidArchive("layers_unreadable", error); });
|
|
if (!layers.isDirectory()) throw invalidArchive("layers_unreadable");
|
|
await verifyArchive(`${sourceRoot}/overlay.tar.zst`, receipt.overlay, signal);
|
|
return { kind: "layers", sourceRoot, overlay: receipt.overlay, files: receipt.files };
|
|
}
|
|
|
|
// Copy first, then hash the private copy: no mutation of the older image, and
|
|
// no time-of-check/time-of-use trust in its contents. Image bytes are never
|
|
// linked, because the runner requires its pack to be physical files inside the
|
|
// pack. Only verified private copies inside the pack are hardlinked, and only
|
|
// to files with the same digest and mode. `providerPackReusePlan` decides how repeated bytes
|
|
// are stored once; this program only follows that plan.
|
|
const reuseScript = `
|
|
(async()=>{
|
|
const fs=require('node:fs'),p=require('node:path'),c=require('node:crypto');
|
|
const spec=JSON.parse(Buffer.from(process.argv[1],'base64').toString('utf8'));
|
|
const f=fs.promises;await f.mkdir(p.dirname(spec.target),{recursive:true,mode:448});
|
|
await f.mkdir(spec.target,{mode:448});
|
|
const missing=[],anchors=new Map();
|
|
const regularPath=async(root,relative)=>{
|
|
let current=root;if(!(await f.lstat(current)).isDirectory())return false;
|
|
const parts=relative.split('/');
|
|
for(let i=0;i<parts.length;i++){current=p.join(current,parts[i]);const s=await f.lstat(current);
|
|
if(i===parts.length-1?!s.isFile():!s.isDirectory())return false;}
|
|
return true;
|
|
};
|
|
for(const [index,entry] of spec.files.entries()){
|
|
const target=p.join(spec.target,entry.path);let reused=false;
|
|
const anchor=anchors.get(entry.group);
|
|
if(anchor!==undefined){try{
|
|
await f.mkdir(p.dirname(target),{recursive:true,mode:448});await f.link(anchor,target);continue;
|
|
}catch{await f.unlink(target).catch(()=>{});}}
|
|
for(const root of spec.roots){for(const relative of entry.sources){try{
|
|
if(!await regularPath(root,relative))continue;
|
|
const source=p.join(root,relative);if((await f.lstat(source)).size!==entry.bytes)continue;
|
|
await f.mkdir(p.dirname(target),{recursive:true,mode:448});
|
|
await f.copyFile(source,target,fs.constants.COPYFILE_EXCL|fs.constants.COPYFILE_FICLONE);
|
|
const handle=await f.open(target,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
|
|
let matches=false;try{const hash=c.createHash('sha256');for await(const chunk of handle.createReadStream({autoClose:false}))hash.update(chunk);
|
|
matches=(await handle.stat()).size===entry.bytes&&hash.digest('hex')===entry.sha256;
|
|
}finally{await handle.close();}
|
|
if(!matches)throw Error('digest mismatch');
|
|
await f.chmod(target,entry.mode);reused=true;break;
|
|
}catch{await f.unlink(target).catch(()=>{});}}if(reused)break;}
|
|
if(reused)anchors.set(entry.group,target);
|
|
else missing.push(index);
|
|
}
|
|
console.log(JSON.stringify(missing));
|
|
})().catch(()=>process.exitCode=1);
|
|
`;
|
|
|
|
export type ProviderPackReuseStep = {
|
|
/** Image paths to copy these bytes from, own path first, then other paths with the same bytes. */
|
|
sources: string[];
|
|
/** Files with the same bytes and mode share a group; later files hardlink to the group's first private copy. */
|
|
group: number;
|
|
};
|
|
|
|
/** Store repeated bytes once: the first private copy of each digest and mode is
|
|
* shared by hardlinks, and a path the image lacks may come from a same-bytes twin. */
|
|
export function providerPackReusePlan(
|
|
files: readonly Pick<FileLayer, "path" | "sha256" | "mode">[],
|
|
sourceFiles: readonly Pick<FileLayer, "path" | "sha256">[] = files,
|
|
): ProviderPackReuseStep[] {
|
|
const pathsBySha = new Map<string, string[]>();
|
|
for (const file of sourceFiles) pathsBySha.set(file.sha256, [...(pathsBySha.get(file.sha256) ?? []), file.path]);
|
|
const groups = new Map<string, number>();
|
|
return files.map(file => {
|
|
const key = `${file.sha256}:${file.mode}`;
|
|
if (!groups.has(key)) groups.set(key, groups.size);
|
|
const twins = (pathsBySha.get(file.sha256) ?? []).filter(path => path !== file.path);
|
|
return { sources: [file.path, ...twins], group: groups.get(key)! };
|
|
});
|
|
}
|
|
|
|
type SelectedFileLayer = { file: FileLayer; index: number };
|
|
|
|
function selectProviderPackFiles(
|
|
files: readonly FileLayer[],
|
|
required: readonly string[] | null,
|
|
options?: { assetsOnly?: boolean },
|
|
): SelectedFileLayer[] {
|
|
return files
|
|
.map((file, index) => ({ file, index }))
|
|
.filter(({ file }) => isProviderAssetPathIncluded(file.path, required, options));
|
|
}
|
|
|
|
function buildProviderPackLayersSpec(
|
|
archive: ProviderPackLayers,
|
|
targetPath: string,
|
|
reuseRoots: readonly string[],
|
|
provider?: PackProvider,
|
|
manifest?: Pick<ProviderPackIdentity, "payload">,
|
|
options?: { assetsOnly?: boolean },
|
|
): { spec: string | null; selectedEntries: SelectedFileLayer[]; required: string[] | null } {
|
|
const required = requiredProviderAssetNames(provider, manifest);
|
|
const selectedEntries = selectProviderPackFiles(archive.files, required, options);
|
|
const selectedFiles = selectedEntries.map(entry => entry.file);
|
|
const plan = providerPackReusePlan(selectedFiles, archive.files);
|
|
const files = selectedFiles.map((file, index) => ({ ...file, ...plan[index] }));
|
|
const spec = Buffer.from(JSON.stringify({ target: targetPath, roots: reuseRoots, files })).toString("base64");
|
|
return { spec: Buffer.byteLength(spec) > 120_000 ? null : spec, selectedEntries, required };
|
|
}
|
|
|
|
export function providerPackLayersArgument(
|
|
archive: ProviderPackLayers,
|
|
targetPath: string,
|
|
reuseRoots: readonly string[],
|
|
provider?: PackProvider,
|
|
manifest?: Pick<ProviderPackIdentity, "payload">,
|
|
) {
|
|
return buildProviderPackLayersSpec(archive, targetPath, reuseRoots, provider, manifest).spec;
|
|
}
|
|
|
|
export async function stageProviderPackLayers(input: {
|
|
archive: ProviderPackLayers;
|
|
runner: CommandManagedRuntimeRunner;
|
|
targetPath: string;
|
|
reuseRoots: readonly string[];
|
|
trace?: NativeRunTrace;
|
|
provider?: PackProvider;
|
|
manifest?: Pick<ProviderPackIdentity, "payload">;
|
|
/** When true, add only the required `provider-assets/<name>` subtrees into an existing verified pack. */
|
|
supplementAssetsOnly?: boolean;
|
|
}): Promise<boolean> {
|
|
const { archive, runner } = input;
|
|
if (!runner.syncIn) throw Error("runner_remote_provider_archive_transport_unavailable");
|
|
const measure = <T>(name: string, fn: () => Promise<T>) => input.trace ? input.trace.measure(name, fn) : fn();
|
|
const supplement = input.supplementAssetsOnly === true;
|
|
const stageDir = supplement ? `${input.targetPath}.assets-${randomUUID()}` : input.targetPath;
|
|
const { spec, selectedEntries, required } = buildProviderPackLayersSpec(
|
|
archive,
|
|
stageDir,
|
|
input.reuseRoots,
|
|
input.provider,
|
|
input.manifest,
|
|
supplement ? { assetsOnly: true } : undefined,
|
|
);
|
|
if (supplement && (!required || required.length === 0)) return false;
|
|
// Respect the per-argument Linux limit; unusual packs retain directory staging.
|
|
if (spec === null) return false;
|
|
const capability = await measure("provider_pack.archive.probe", () => runner.execute({
|
|
command: "sh", args: ["-c", `${providerPackExtractionProbe} && node -e 'process.exit(Number(process.versions.node.split(".")[0])>=18?0:1)'`],
|
|
bypassSession: true, timeoutMs: 10_000,
|
|
}));
|
|
if (capability.exitCode !== 0 || capability.timedOut) return false;
|
|
const scratch = `${input.targetPath}.upload-${randomUUID()}`;
|
|
const temporary = await mkdtemp(join(tmpdir(), "paperclip-provider-layers-"));
|
|
const bundlePath = join(temporary, "selected.tar.zst");
|
|
const remoteArchive = `${scratch}/selected.tar.zst`;
|
|
try {
|
|
const reused = await measure("provider_pack.archive.reuse", () => runner.execute({
|
|
command: "node", args: ["-e", reuseScript, spec], bypassSession: true, timeoutMs: 60_000,
|
|
}));
|
|
if (reused.exitCode !== 0 || reused.timedOut) throw Error("runner_remote_provider_archive_reuse_failed");
|
|
let missing: number[];
|
|
try { missing = JSON.parse(reused.stdout); } catch { throw Error("runner_remote_provider_archive_reuse_failed"); }
|
|
if (!Array.isArray(missing) || new Set(missing).size !== missing.length
|
|
|| missing.some(index => !Number.isSafeInteger(index) || index < 0 || index >= selectedEntries.length)) {
|
|
throw Error("runner_remote_provider_archive_reuse_failed");
|
|
}
|
|
const layers = [
|
|
...missing.map(selectedIndex => {
|
|
const entry = selectedEntries[selectedIndex]!;
|
|
return { name: `${entry.index}.tar.zst`, ...entry.file.archive };
|
|
}),
|
|
{ name: "overlay.tar.zst", ...archive.overlay },
|
|
];
|
|
const excludeFlags = providerAssetExcludeArgs({
|
|
provider: input.provider,
|
|
manifest: input.manifest,
|
|
filePaths: archive.files.map(file => file.path),
|
|
}).map(quote).join(" ");
|
|
// Concatenate independent zstd frames without recompression. One upload
|
|
// avoids a provider round trip for every small missing layer.
|
|
const hash = createHash("sha256");
|
|
await measure("provider_pack.archive.verify_missing", () => pipeline((async function* () {
|
|
for (const layer of layers) {
|
|
const file = await open(`${archive.sourceRoot}/${layer.name}`, constants.O_RDONLY | constants.O_NOFOLLOW)
|
|
.catch(error => { throw invalidArchive("archive_unreadable", error); });
|
|
try {
|
|
const metadata = await file.stat(), layerHash = createHash("sha256");
|
|
if (!metadata.isFile() || metadata.size !== layer.bytes) throw invalidArchive("size_mismatch");
|
|
for await (const chunk of file.createReadStream({ autoClose: false })) {
|
|
layerHash.update(chunk); hash.update(chunk); yield chunk;
|
|
}
|
|
if (layerHash.digest("hex") !== layer.sha256) throw invalidArchive("sha256_mismatch");
|
|
} finally { await file.close(); }
|
|
}
|
|
})(), createWriteStream(bundlePath, { flags: "wx", mode: 0o600 })));
|
|
const sha256 = hash.digest("hex");
|
|
await measure("provider_pack.archive.transfer", () => runner.syncIn!([{
|
|
operationId: `runner-provider-layers-${randomUUID()}`,
|
|
files: [{ kind: "file", sourcePath: bundlePath, targetPath: remoteArchive, mode: 0o600 }],
|
|
}]));
|
|
const installCommands = supplement
|
|
? [
|
|
`test ! -L ${quote(input.targetPath)}; test -d ${quote(input.targetPath)};`,
|
|
`mkdir -p ${quote(`${input.targetPath}/provider-assets`)};`,
|
|
`test ! -L ${quote(`${input.targetPath}/provider-assets`)};`,
|
|
...required!.map(name => [
|
|
`test -d ${quote(`${stageDir}/provider-assets/${name}`)};`,
|
|
`test ! -L ${quote(`${stageDir}/provider-assets/${name}`)};`,
|
|
`rm -rf -- ${quote(`${input.targetPath}/provider-assets/${name}`)};`,
|
|
`mv -- ${quote(`${stageDir}/provider-assets/${name}`)} ${quote(`${input.targetPath}/provider-assets/${name}`)};`,
|
|
].join(" ")),
|
|
]
|
|
: [`chmod 700 ${quote(input.targetPath)};`];
|
|
const result = await measure("provider_pack.archive.extract", () => runner.execute({
|
|
command: "sh", args: ["-c", ["set -eu; umask 077;",
|
|
`test ! -L ${quote(stageDir)}; test -d ${quote(stageDir)};`,
|
|
`test ! -L ${quote(remoteArchive)}; test "$(sha256sum -- ${quote(remoteArchive)} | cut -d ' ' -f 1)" = ${quote(sha256)};`,
|
|
`tar --zstd --ignore-zeros${excludeFlags ? ` ${excludeFlags}` : ""} -xf ${quote(remoteArchive)} --no-same-owner --same-permissions --delay-directory-restore -C ${quote(stageDir)};`,
|
|
...installCommands,
|
|
].join(" ")], bypassSession: true, timeoutMs: 120_000,
|
|
}));
|
|
if (result.exitCode !== 0 || result.timedOut) throw Error("runner_remote_provider_archive_extract_failed");
|
|
return true;
|
|
} finally {
|
|
await rm(temporary, { recursive: true, force: true });
|
|
const cleanupPaths = supplement ? `${quote(scratch)} ${quote(stageDir)}` : quote(scratch);
|
|
await runner.execute({ command: "sh", args: ["-c", `rm -rf -- ${cleanupPaths}`],
|
|
bypassSession: true, timeoutMs: 10_000 }).catch(() => undefined);
|
|
}
|
|
}
|