@yaks/sandbox 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +400 -2
- package/_dist/bubblewrap.d.ts +38 -0
- package/_dist/bubblewrap.d.ts.map +1 -0
- package/_dist/cloudflare.d.ts +136 -0
- package/_dist/cloudflare.d.ts.map +1 -0
- package/_dist/configuration.d.ts +13 -0
- package/_dist/configuration.d.ts.map +1 -0
- package/_dist/docker.d.ts +15 -0
- package/_dist/docker.d.ts.map +1 -0
- package/_dist/effects.d.ts +6 -0
- package/_dist/effects.d.ts.map +1 -0
- package/_dist/lifecycle.d.ts +38 -0
- package/_dist/lifecycle.d.ts.map +1 -0
- package/_dist/mod.d.ts +4 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/provider.d.ts +33 -0
- package/_dist/provider.d.ts.map +1 -0
- package/_dist/pve.d.ts +17 -0
- package/_dist/pve.d.ts.map +1 -0
- package/_dist/recovery.d.ts +71 -0
- package/_dist/recovery.d.ts.map +1 -0
- package/_dist/tools.d.ts +4 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/vocab.d.ts +5 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/archive.js +60 -0
- package/archive.js.map +1 -0
- package/archive.ts +49 -0
- package/bubblewrap.js +495 -0
- package/bubblewrap.js.map +1 -0
- package/bubblewrap.ts +555 -0
- package/cloudflare.js +434 -0
- package/cloudflare.js.map +1 -0
- package/cloudflare.ts +592 -0
- package/configuration.js +84 -0
- package/configuration.js.map +1 -0
- package/configuration.ts +120 -0
- package/deno.json +1 -0
- package/docker.js +149 -0
- package/docker.js.map +1 -0
- package/docker.ts +206 -0
- package/effects.js +86 -0
- package/effects.js.map +1 -0
- package/effects.ts +78 -0
- package/lifecycle.js +153 -0
- package/lifecycle.js.map +1 -0
- package/lifecycle.ts +207 -0
- package/mod.js +6 -0
- package/mod.js.map +1 -0
- package/mod.ts +7 -0
- package/package.json +64 -4
- package/provider.js +11 -0
- package/provider.js.map +1 -0
- package/provider.ts +44 -0
- package/pve.js +197 -0
- package/pve.js.map +1 -0
- package/pve.ts +259 -0
- package/recovery-script.js +187 -0
- package/recovery-script.js.map +1 -0
- package/recovery-script.ts +186 -0
- package/recovery.js +231 -0
- package/recovery.js.map +1 -0
- package/recovery.ts +317 -0
- package/sandbox-runner.js +218 -0
- package/sandbox-runner.js.map +1 -0
- package/sandbox-runner.ts +217 -0
- package/tools.js +42 -0
- package/tools.js.map +1 -0
- package/tools.ts +45 -0
- package/vocab.js +13 -0
- package/vocab.js.map +1 -0
- package/vocab.json +180 -0
- package/vocab.ts +11 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { type Clock } from "@yaks/fp";
|
|
2
|
+
import { type Bundle } from "@yaks/graph";
|
|
3
|
+
import type { SandboxFile, SandboxProvider, SandboxRef } from "./provider.js";
|
|
4
|
+
/** How a command runs in the container: where, for how long at most, and with
|
|
5
|
+
* what beside the container's own environment. */ type Run = {
|
|
6
|
+
cwd?: string;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
env?: Record<string, string>;
|
|
9
|
+
};
|
|
10
|
+
/** One sandbox, as this file asks for it: what the tools do with it, plus the
|
|
11
|
+
* one knob the deploy has no way to set. The SDK's process calls answer
|
|
12
|
+
* objects carrying methods as well; only their data is read here. */ export type Box = {
|
|
13
|
+
getState(): Promise<{
|
|
14
|
+
status: string;
|
|
15
|
+
}>;
|
|
16
|
+
exec(cmd: string, opts?: Run): Promise<{
|
|
17
|
+
stdout: string;
|
|
18
|
+
stderr: string;
|
|
19
|
+
exitCode: number;
|
|
20
|
+
}>;
|
|
21
|
+
startProcess(cmd: string, opts?: Run & {
|
|
22
|
+
autoCleanup?: boolean;
|
|
23
|
+
processId?: string;
|
|
24
|
+
}): Promise<{
|
|
25
|
+
id: string;
|
|
26
|
+
pid?: number;
|
|
27
|
+
}>;
|
|
28
|
+
getProcess(id: string): Promise<{
|
|
29
|
+
pid?: number;
|
|
30
|
+
status: string;
|
|
31
|
+
exitCode?: number;
|
|
32
|
+
} | null>;
|
|
33
|
+
killProcess(id: string): Promise<unknown>;
|
|
34
|
+
getProcessLogs(id: string): Promise<{
|
|
35
|
+
stdout: string;
|
|
36
|
+
stderr: string;
|
|
37
|
+
}>;
|
|
38
|
+
mkdir(path: string, opts?: {
|
|
39
|
+
recursive?: boolean;
|
|
40
|
+
}): Promise<unknown>;
|
|
41
|
+
writeFile(path: string, content: string, opts?: {
|
|
42
|
+
encoding?: string;
|
|
43
|
+
}): unknown;
|
|
44
|
+
readFile(path: string, opts?: {
|
|
45
|
+
encoding?: string;
|
|
46
|
+
}): Promise<{
|
|
47
|
+
content: string;
|
|
48
|
+
}>;
|
|
49
|
+
readBytes(path: string): Promise<Bytes>;
|
|
50
|
+
destroy(): Promise<unknown>;
|
|
51
|
+
setSleepAfter?(after: string): unknown;
|
|
52
|
+
};
|
|
53
|
+
type Bytes = {
|
|
54
|
+
stream: ReadableStream<Uint8Array>;
|
|
55
|
+
size: number;
|
|
56
|
+
};
|
|
57
|
+
/** The sandboxes binding: a Durable Object namespace handing out one by name. */ export type Sandboxes = {
|
|
58
|
+
idFromName(name: string): unknown;
|
|
59
|
+
get(id: unknown): Box;
|
|
60
|
+
};
|
|
61
|
+
/** The deployed image's writable working directory. */ export declare let CWD: string;
|
|
62
|
+
/** Commands have a four-minute ceiling, including background processes. */ export declare let TIMEOUT: number;
|
|
63
|
+
/** An idle workbench releases its container after one minute. */ export declare let NAP: number;
|
|
64
|
+
export declare let SLEEP: string;
|
|
65
|
+
/** How long one call keeps a container awake, in seconds: the longest
|
|
66
|
+
* command, then the nap before it sleeps on its own. */ export declare let HELD: any;
|
|
67
|
+
export declare let POOL_BUSY: string;
|
|
68
|
+
/** Wait for a free slot during startup, before any workspace operation runs.
|
|
69
|
+
* The window gives an idle workbench time to snapshot and release its slot. */ export declare let admitted: <T>(start: () => T | Promise<T>, clock?: Clock) => Promise<T>;
|
|
70
|
+
/** Process status is a short, read-only control request. The HTTP SDK bounds
|
|
71
|
+
* startup retries, but one unresponsive container read can consume minutes.
|
|
72
|
+
* Cancel that read at the transport and try again. The container proxy's
|
|
73
|
+
* plain 500 also means it could not reach the container. Sandbox API errors
|
|
74
|
+
* carry JSON, including a missing process. */ export declare let processStatus: (req: Request, send: (req: Request) => Promise<Response>, clock?: Clock) => Promise<Response>;
|
|
75
|
+
/** The container a group lends one person, by name: one each, so the
|
|
76
|
+
* person's every way in reaches one workbench. The group's id rather than a
|
|
77
|
+
* name of it, since a renamed group keeps its containers. */ export declare let named: (within: string, to: string) => string;
|
|
78
|
+
/** Where a group's lent sandboxes are kept: a graph store's reads and
|
|
79
|
+
* writes, `lent` among its words. */ export type Lending = {
|
|
80
|
+
read(line: string): Bundle[] | Promise<Bundle[]>;
|
|
81
|
+
apply(bundles: Bundle[]): unknown;
|
|
82
|
+
};
|
|
83
|
+
/** One lent sandbox: whom it is lent to, and the second it sleeps by (0 once
|
|
84
|
+
* it is known to be asleep). */ export type Lent = {
|
|
85
|
+
to: string;
|
|
86
|
+
until: number;
|
|
87
|
+
};
|
|
88
|
+
/** Every sandbox the group has lent, awake or asleep: whose editable files
|
|
89
|
+
* must survive group trash, members who have since left included. */ export declare let lending: (store: Lending, within: string) => Promise<Lent[]>;
|
|
90
|
+
/** How many of the group's sandboxes are awake at second `now` beside `to`'s. */ export declare let awakeBeside: (lent: Lent[], to: string, now: number) => number;
|
|
91
|
+
/**
|
|
92
|
+
* `to`'s sandbox in the group, held awake for {@link HELD} more seconds —
|
|
93
|
+
* unless `allowed` others already are, when nothing is written and the answer
|
|
94
|
+
* is how many. The row is written only once its hold is half spent: a build
|
|
95
|
+
* calls faster than its store need hear about it.
|
|
96
|
+
*/ export declare let hold: (store: Lending, within: string, to: string, allowed: number, now?: number) => Promise<{
|
|
97
|
+
held: true;
|
|
98
|
+
} | {
|
|
99
|
+
held: false;
|
|
100
|
+
awake: number;
|
|
101
|
+
}>;
|
|
102
|
+
/** `to`'s sandbox in the group, asleep: a stopped container gives its place
|
|
103
|
+
* back at once rather than when its nap would. */ export declare let slept: (store: Lending, within: string, to: string) => Promise<void>;
|
|
104
|
+
/** Stored outside the container. locked serializes lifecycle calls across
|
|
105
|
+
* hosts; save is durable before it resolves. Disposal receipts must be kept. */ export type CloudflareLifecycle = {
|
|
106
|
+
locked<T>(id: string, act: (receipt: {
|
|
107
|
+
state?: 'provisioning' | 'ready' | 'disposing' | 'released';
|
|
108
|
+
save(state: 'provisioning' | 'ready' | 'disposing' | 'released'): Promise<void>;
|
|
109
|
+
}) => Promise<T>): Promise<T>;
|
|
110
|
+
};
|
|
111
|
+
export type CloudflareOptions = {
|
|
112
|
+
/** Mandatory for durable sandbox lifecycle, unless `ephemeral`. */ lifecycle?: CloudflareLifecycle;
|
|
113
|
+
/** The container's disk does not outlive its {@link NAP}: connect wakes a
|
|
114
|
+
* fresh one from the deployed image and keeps no lifecycle receipts, as a
|
|
115
|
+
* deployed Cloudflare Container does. */ ephemeral?: boolean;
|
|
116
|
+
/** Prepare existing writable storage before each public workspace RPC,
|
|
117
|
+
* including restoration after an ephemeral container wakes. */ prepare?: (ref: SandboxRef, box: Box) => Promise<void>;
|
|
118
|
+
/** Preserve recoverable writable storage, then stop the container. This
|
|
119
|
+
* boundary owns teardown; disposal never calls destroy on its own. */ trash?: (ref: SandboxRef, box: Box) => Promise<void>;
|
|
120
|
+
/** Explicitly restore a durable resource retained by trash. */ restore?: (ref: SandboxRef, box: Box) => Promise<void>;
|
|
121
|
+
env?: () => Promise<Record<string, string>>;
|
|
122
|
+
retry?: <T>(send: () => T | Promise<T>) => Promise<T>;
|
|
123
|
+
clock?: Clock;
|
|
124
|
+
sleepError?: (error: unknown) => void;
|
|
125
|
+
};
|
|
126
|
+
/** Cloudflare's synchronous exec is also used to expand artifact globs. */ export type CloudflareProvider = SandboxProvider & {
|
|
127
|
+
exec(ref: SandboxRef, command: string): ReturnType<Box['exec']>;
|
|
128
|
+
open(ref: SandboxRef, path: string): Promise<Bytes>;
|
|
129
|
+
/** writes one file's bytes, as `export` reads them: an absolute path is
|
|
130
|
+
* kept, a relative one is under {@link CWD}, and its directory is made */ put(ref: SandboxRef, file: SandboxFile): Promise<void>;
|
|
131
|
+
};
|
|
132
|
+
/** A provider bound to one deployed container namespace. Stable request ids
|
|
133
|
+
* are the namespace names, so connect, export and dispose need no live handle.
|
|
134
|
+
* `from`, `image` and addresses are refused: this namespace boots its deployed
|
|
135
|
+
* image, not a graph commit or an existing sandbox. */ export declare let cloudflareProvider: (ns: Sandboxes, options?: CloudflareOptions) => CloudflareProvider;
|
|
136
|
+
//# sourceMappingURL=cloudflare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare.d.ts","sources":["../cloudflare.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Graph } from "@yaks/graph";
|
|
2
|
+
import type { Configuration, SandboxOptions } from "./lifecycle.js";
|
|
3
|
+
export type { Configuration } from "./lifecycle.js";
|
|
4
|
+
export type ConfigurationHost = {
|
|
5
|
+
graph: Graph;
|
|
6
|
+
config?: {
|
|
7
|
+
sandboxes?: Configuration;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
/** Adapter modules export sandboxProvider(host, options, placement). Built-in
|
|
11
|
+
* Docker/PVE bindings use only their machine row's configured local/SSH address.
|
|
12
|
+
* No missing placement becomes the server computer. */ export declare let resolveOptions: (host: ConfigurationHost, options?: Configuration) => Promise<SandboxOptions>;
|
|
13
|
+
//# sourceMappingURL=configuration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sources":["../configuration.ts"],"names":[],"mappings":"AAGA,cAAoB,KAAK,2BAAgC;AAMzD,cAAc,aAAa,EAAE,cAAc,yBAAwB;AACnE,cAAc,aAAa,yBAAwB;AAGnD,YAAY;EACV,OAAO;EACP;IAAW,YAAY;;;AAGzB;;qDAEqD,GACrD,OAAO,YAAI,iBACT,MAAM,mBACN,UAAS,kBACR,QAAQ,gBA+FV"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Graph } from "@yaks/graph";
|
|
2
|
+
import type { ComputerTransport, Workspace } from "@yaks/machine";
|
|
3
|
+
import { type SandboxProvider } from "./provider.js";
|
|
4
|
+
/** Host state is outside the sandbox so the trash receipt and retained
|
|
5
|
+
* sandbox survive disposal; restoration reconnects the same writable storage. */ export type DockerOptions = {
|
|
6
|
+
transport: ComputerTransport;
|
|
7
|
+
state: string;
|
|
8
|
+
root?: string;
|
|
9
|
+
image?: string;
|
|
10
|
+
prepare?: (from: string, workspace: Workspace, root: string) => Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
/** A local sbx adapter, reached through a computer transport (usually SSH).
|
|
13
|
+
* No --cloud, bind mount or agent launch is implicit. sbx exec wakes existing
|
|
14
|
+
* storage; a missing resource is an error rather than permission to recreate. */ export declare let dockerSandboxes: (g: Graph, options: DockerOptions) => SandboxProvider;
|
|
15
|
+
//# sourceMappingURL=docker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docker.d.ts","sources":["../docker.ts"],"names":[],"mappings":"AAEA,cAAc,KAAK,2BAAgC;AACnD,cAAc,iBAAiB,EAAE,SAAS,6BAAkC;AAG5E,SAEE,KAAK,eAAe,wBAGA;AAEtB;+EAC+E,GAC/E,YAAY;EACV,WAAW;EACX,OAAO,MAAM;EACb,OAAO,MAAM;EACb,QAAQ,MAAM;EACd,WAAW,MAAM,MAAM,EAAE,WAAW,WAAW,MAAM,MAAM,KAAK,QAAQ,IAAI;;AA+B9E;;+EAE+E,GAC/E,OAAO,YAAI,kBACT,GAAG,OACH,SAAS,kBACR,gBAoJF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Handler, Handlers } from "@yaks/effects";
|
|
2
|
+
import { type SandboxOptions } from "./lifecycle.js";
|
|
3
|
+
/** At-least-once request uses the preallocated identity; adapter request must
|
|
4
|
+
* reconnect an existing resource, and must never replace a destroyed resource. */ export declare let provisioning: ({}: SandboxOptions) => Handler;
|
|
5
|
+
/** Resolve adapters only when an effect runs, after the graph is open. */ export declare let effects: (host: import("./configuration.js").ConfigurationHost, options?: import("./configuration.js").Configuration) => Handlers;
|
|
6
|
+
//# sourceMappingURL=effects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.d.ts","sources":["../effects.ts"],"names":[],"mappings":"AACA,cAAc,OAAO,EAAE,QAAQ,6BAAkC;AAEjE,SAAyB,KAAK,cAAc,yBAAoC;AAEhF;gFACgF,GAChF,OAAO,YAAI,eACR,IAAe,cAAc,KAAG,QA0DhC;AAEH,wEAAwE,GACxE,OAAO,YAAI,UACT,mCAAmC,mBACnC,uCAAsC,kBACrC,SAKD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Bundle, type Graph } from "@yaks/graph";
|
|
2
|
+
import type { SandboxConnection, SandboxFile, SandboxProvider, SandboxRef } from "./provider.js";
|
|
3
|
+
/** A configured adapter and its explicit computer; omitted only for backends
|
|
4
|
+
* which cannot disclose placement. Never inferred from the executing host. */ export type SandboxBinding = {
|
|
5
|
+
provider: SandboxProvider;
|
|
6
|
+
machine?: string;
|
|
7
|
+
};
|
|
8
|
+
export type SandboxBindings = Record<string, SandboxBinding>;
|
|
9
|
+
export type SandboxOptions = {
|
|
10
|
+
providers: SandboxBindings;
|
|
11
|
+
};
|
|
12
|
+
/** Serializable adapter selection, separate from the module that connects it. */ export type Configuration = {
|
|
13
|
+
providers?: Record<string, SandboxBinding | {
|
|
14
|
+
use: string;
|
|
15
|
+
machine?: string;
|
|
16
|
+
with?: Record<string, unknown>;
|
|
17
|
+
}>;
|
|
18
|
+
};
|
|
19
|
+
export type SandboxNew = {
|
|
20
|
+
id?: string;
|
|
21
|
+
machine?: string;
|
|
22
|
+
provider: string;
|
|
23
|
+
from?: string;
|
|
24
|
+
image?: string;
|
|
25
|
+
};
|
|
26
|
+
/** Resolve only the recorded placement, never a local fallback. */ export declare let sandboxBinding: (row: Bundle, bindings: SandboxBindings) => SandboxBinding;
|
|
27
|
+
export declare let sandboxRef: (row: Bundle) => SandboxRef;
|
|
28
|
+
export declare let sandboxRow: (graph: Pick<Graph, 'get'>, id: string) => Promise<Bundle>;
|
|
29
|
+
/** Persist this intention before provisioning. A caller may supply its durable
|
|
30
|
+
* call-derived id, making a repeated request name the same resource. */ export declare let sandboxNew: (graph: Pick<Graph, 'get' | 'apply'>, bindings: SandboxBindings, request: SandboxNew) => Promise<Bundle>;
|
|
31
|
+
/** Reconnect is never create. Pending, failed and released rows are not usable. */ export declare let sandboxConnect: (graph: Pick<Graph, 'get'>, bindings: SandboxBindings, id: string) => Promise<SandboxConnection>;
|
|
32
|
+
/** Called from a durable tool invocation. A release is recorded only after the
|
|
33
|
+
* provider confirms recoverable trash; repeated disposal never requests a new resource. */ export declare let sandboxDispose: (graph: Pick<Graph, 'get' | 'apply'>, bindings: SandboxBindings, id: string) => Promise<Bundle>;
|
|
34
|
+
/** Restore the retained resource before clearing its trash receipt. */ export declare let sandboxRestore: (graph: Pick<Graph, 'get' | 'apply'>, bindings: SandboxBindings, id: string) => Promise<Bundle>;
|
|
35
|
+
/** Export only from an existing ready resource; relative paths are validated
|
|
36
|
+
* before an adapter is asked to read files. Bytes remain inside the caller's
|
|
37
|
+
* explicit export channel, never read through the host filesystem. */ export declare function sandboxExport(graph: Pick<Graph, 'get'>, bindings: SandboxBindings, id: string, paths: string[]): AsyncIterable<SandboxFile>;
|
|
38
|
+
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sources":["../lifecycle.ts"],"names":[],"mappings":"AACA,SAAS,KAAK,MAAM,EAAa,KAAK,KAAK,2BAA6C;AACxF,cACE,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,UAAU,wBACU;AAGtB;4EAC4E,GAC5E,YAAY;EAAmB,UAAU;EAAiB,UAAU,MAAM;;AAC1E,YAAY,kBAAkB,OAAO,MAAM,EAAE;AAC7C,YAAY;EAAmB,WAAW;;AAC1C,+EAA+E,GAC/E,YAAY;EACV,YAAY,OACV,MAAM,EACN;IACE,KAAK,MAAM;IACX,UAAU,MAAM;IAChB,OAAO,OAAO,MAAM,EAAE,OAAO;;;AAKnC,YAAY;EACV,KAAK,MAAM;EACX,UAAU,MAAM;EAChB,UAAU,MAAM;EAChB,OAAO,MAAM;EACb,QAAQ,MAAM;;AAIhB,iEAAiE,GACjE,OAAO,YAAI,iBACT,KAAK,QACL,UAAU,oBACT,eAWF;AACD,OAAO,YAAI,aAAc,KAAK,WAAS,WAKrC;AACF,OAAO,YAAI,aACT,OAAO,KAAK,OAAO,QACnB,IAAI,MAAM,KACT,QAAQ,QAMV;AAED;sEACsE,GACtE,OAAO,YAAI,aACT,OAAO,KAAK,OAAO,QAAQ,UAC3B,UAAU,iBACV,SAAS,eACR,QAAQ,QAwCV;AAED,iFAAiF,GACjF,OAAO,YAAI,iBACT,OAAO,KAAK,OAAO,QACnB,UAAU,iBACV,IAAI,MAAM,KACT,QAAQ,mBAYV;AAED;yFACyF,GACzF,OAAO,YAAI,iBACT,OAAO,KAAK,OAAO,QAAQ,UAC3B,UAAU,iBACV,IAAI,MAAM,KACT,QAAQ,QA4BV;AAED,qEAAqE,GACrE,OAAO,YAAI,iBACT,OAAO,KAAK,OAAO,QAAQ,UAC3B,UAAU,iBACV,IAAI,MAAM,KACT,QAAQ,QASV;AAED;;oEAEoE,GACpE,OAAO,iBAAgB,cACrB,OAAO,KAAK,OAAO,MAAM,EACzB,UAAU,eAAe,EACzB,IAAI,MAAM,EACV,OAAO,MAAM,EAAE,GACd,cAAc"}
|
package/_dist/mod.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAEA,SAAS,UAAU,qBAAoB;AAEvC,8BAA6B;AAE7B,+BAA8B"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Workspace } from "@yaks/machine";
|
|
2
|
+
/** A durable sandbox locator; address is never a computer connection address. */ export type SandboxRef = {
|
|
3
|
+
id: string;
|
|
4
|
+
address?: string;
|
|
5
|
+
};
|
|
6
|
+
/** Initial provenance is not a backup of subsequent edits. */ export type SandboxRequest = SandboxRef & {
|
|
7
|
+
from?: string;
|
|
8
|
+
image?: string;
|
|
9
|
+
};
|
|
10
|
+
/** A connection to the existing sandbox filesystem. Placement is held by the
|
|
11
|
+
* sandbox's workspace row, not inferred from this connection's implementation. */ export type SandboxConnection = {
|
|
12
|
+
workspace: Workspace;
|
|
13
|
+
root?: string;
|
|
14
|
+
address?: string;
|
|
15
|
+
};
|
|
16
|
+
/** One exported file, read inside the sandbox, not through a host symlink. */ export type SandboxFile = {
|
|
17
|
+
path: string;
|
|
18
|
+
bytes: Uint8Array;
|
|
19
|
+
};
|
|
20
|
+
/** The provider retained this id in trash. A fresh request needs another id. */ export declare class SandboxReleased extends Error {
|
|
21
|
+
}
|
|
22
|
+
/** Configured sandbox lifecycle on an explicit computer (or a backend that
|
|
23
|
+
* cannot disclose placement). connect never creates a replacement resource.
|
|
24
|
+
* dispose retains writable storage in recoverable trash; restore returns it.
|
|
25
|
+
* Neither operation purges storage. Both tolerate repeated calls with the same id. */ export type SandboxProvider = {
|
|
26
|
+
/** A provider may report a retained, released id with {@link SandboxReleased}. */ request?: (request: SandboxRequest) => Promise<SandboxConnection>;
|
|
27
|
+
/** A provider may report a released id with {@link SandboxReleased}. */ connect(ref: SandboxRef): Promise<SandboxConnection>;
|
|
28
|
+
dispose(ref: SandboxRef): Promise<void>;
|
|
29
|
+
restore?(ref: SandboxRef): Promise<void>;
|
|
30
|
+
export(ref: SandboxRef, paths: string[]): AsyncIterable<SandboxFile>;
|
|
31
|
+
};
|
|
32
|
+
/** Export names are relative and stay inside the sandbox's default directory. */ export declare let exportPath: (path: string) => string;
|
|
33
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sources":["../provider.ts"],"names":[],"mappings":"AAEA,cAAc,SAAS,6BAAkC;AAEzD,+EAA+E,GAC/E,YAAY;EAAe,IAAI,MAAM;EAAE,UAAU,MAAM;;AACvD,4DAA4D,GAC5D,YAAY,iBAAiB;EAAe,OAAO,MAAM;EAAE,QAAQ,MAAM;;AACzE;gFACgF,GAChF,YAAY;EACV,WAAW;EACX,OAAO,MAAM;EACb,UAAU,MAAM;;AAElB,4EAA4E,GAC5E,YAAY;EAAgB,MAAM,MAAM;EAAE,OAAO;;AACjD,8EAA8E,GAC9E,OAAO,cAAM,wBAAwB;AAAO;AAE5C;;;oFAGoF,GACpF,YAAY;EACV,gFAAgF,GAChF,WAAW,SAAS,mBAAmB,QAAQ;EAC/C,sEAAsE,GACtE,QAAQ,KAAK,aAAa,QAAQ;EAClC,QAAQ,KAAK,aAAa,QAAQ,IAAI;EACtC,SAAS,KAAK,aAAa,QAAQ,IAAI;EACvC,OAAO,KAAK,YAAY,OAAO,MAAM,KAAK,cAAc;;AAG1D,+EAA+E,GAC/E,OAAO,YAAI,aAAc,MAAM,MAAM,KAAG,MAAM,CAQ7C"}
|
package/_dist/pve.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Graph } from "@yaks/graph";
|
|
2
|
+
import type { ComputerTransport, Workspace } from "@yaks/machine";
|
|
3
|
+
import { type SandboxProvider } from "./provider.js";
|
|
4
|
+
export type PveOptions = {
|
|
5
|
+
/** Usually the transport returned by the configured PVE SSH connector. */ transport: ComputerTransport;
|
|
6
|
+
/** Private, persistent directory on PVE, outside every clone. */ state: string;
|
|
7
|
+
template: number;
|
|
8
|
+
/** Every template volume must already reside on this storage. */ storage: string;
|
|
9
|
+
/** Inclusive range granted for these clones, excluding the template. */ vmidRange: readonly [number, number];
|
|
10
|
+
/** Materialize the initial commit; must tolerate retries after interruption. */ prepare?: (from: string, workspace: Workspace, root: string) => Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
/** Linked clones only, on the template storage. The template needs bash, flock, setsid, base64, python3
|
|
13
|
+
* and /proc for executionWorkspace. Missing/ambiguous clones are never rebuilt.
|
|
14
|
+
* A hash collision refuses the request rather than silently choosing a new id.
|
|
15
|
+
* The configured state directory and VMID grant must remain stable on reconnect.
|
|
16
|
+
* Host locks coordinate this adapter, not unrelated PVE administrators. */ export declare let pveClones: (g: Graph, options: PveOptions) => SandboxProvider;
|
|
17
|
+
//# sourceMappingURL=pve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pve.d.ts","sources":["../pve.ts"],"names":[],"mappings":"AAEA,cAAc,KAAK,2BAAgC;AACnD,cAAc,iBAAiB,EAAE,SAAS,6BAAkC;AAG5E,SAEE,KAAK,eAAe,wBAEA;AAEtB,YAAY;EACV,wEAAwE,GACxE,WAAW;EACX,+DAA+D,GAC/D,OAAO,MAAM;EACb,UAAU,MAAM;EAChB,+DAA+D,GAC/D,SAAS,MAAM;EACf,sEAAsE,GACtE,qBAAqB,MAAM,EAAE,MAAM;EACnC,8EAA8E,GAC9E,WAAW,MAAM,MAAM,EAAE,WAAW,WAAW,MAAM,MAAM,KAAK,QAAQ,IAAI;;AAc9E;;;;yEAIyE,GACzE,OAAO,YAAI,YAAa,GAAG,OAAO,SAAS,eAAa,gBAwNvD"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
type Part = {
|
|
2
|
+
partNumber: number;
|
|
3
|
+
etag: string;
|
|
4
|
+
};
|
|
5
|
+
type State = {
|
|
6
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
7
|
+
put(key: string, value: unknown): Promise<unknown>;
|
|
8
|
+
delete(key: string): Promise<unknown>;
|
|
9
|
+
};
|
|
10
|
+
type Archive = {
|
|
11
|
+
createMultipartUpload(key: string): Promise<{
|
|
12
|
+
uploadId: string;
|
|
13
|
+
uploadPart(part: number, bytes: Uint8Array): Promise<Part>;
|
|
14
|
+
complete(parts: Part[]): Promise<unknown>;
|
|
15
|
+
abort(): Promise<void>;
|
|
16
|
+
}>;
|
|
17
|
+
put(key: string, content: string): Promise<unknown>;
|
|
18
|
+
list(options: {
|
|
19
|
+
prefix: string;
|
|
20
|
+
cursor?: string;
|
|
21
|
+
}): Promise<{
|
|
22
|
+
objects: {
|
|
23
|
+
key: string;
|
|
24
|
+
}[];
|
|
25
|
+
truncated: boolean;
|
|
26
|
+
cursor?: string;
|
|
27
|
+
}>;
|
|
28
|
+
delete(keys: string[]): Promise<unknown>;
|
|
29
|
+
};
|
|
30
|
+
type Box = {
|
|
31
|
+
live(): boolean | Promise<boolean>;
|
|
32
|
+
start?(): Promise<void>;
|
|
33
|
+
exec(command: string): Promise<{
|
|
34
|
+
exitCode: number;
|
|
35
|
+
stdout: string;
|
|
36
|
+
stderr: string;
|
|
37
|
+
}>;
|
|
38
|
+
};
|
|
39
|
+
type Filesystem = {
|
|
40
|
+
live(): boolean | Promise<boolean>;
|
|
41
|
+
start?(): Promise<void>;
|
|
42
|
+
run(mode: string, ...args: string[]): Promise<string>;
|
|
43
|
+
read(): AsyncIterable<Uint8Array>;
|
|
44
|
+
restore(name: string, size: number): Promise<string>;
|
|
45
|
+
};
|
|
46
|
+
type Recovery = {
|
|
47
|
+
prepare(): Promise<void>;
|
|
48
|
+
save(): Promise<void>;
|
|
49
|
+
use<T>(act: () => Promise<T>): Promise<T>;
|
|
50
|
+
idle(busy: () => Promise<boolean>, stop: () => Promise<void>): Promise<void>;
|
|
51
|
+
stop<T>(act: () => Promise<T>): Promise<T>;
|
|
52
|
+
purge(stop: () => Promise<unknown>): Promise<void>;
|
|
53
|
+
reset(): void;
|
|
54
|
+
};
|
|
55
|
+
export declare let RECOVERY_HOST: string;
|
|
56
|
+
export declare let ARCHIVE_PATH: string;
|
|
57
|
+
type Download = {
|
|
58
|
+
get(key: string): Promise<{
|
|
59
|
+
body: ReadableStream<Uint8Array>;
|
|
60
|
+
size: number;
|
|
61
|
+
} | null>;
|
|
62
|
+
};
|
|
63
|
+
/** A container can stream only its own archives through its outbound proxy. */ export declare let snapshot: (bucket: Download, id: string, request: Request) => Promise<Response>;
|
|
64
|
+
export declare let filesystem: (box: Box, read: () => AsyncIterable<Uint8Array>, root?: string) => Filesystem;
|
|
65
|
+
/** Rebatch byte streams for multipart storage without buffering an archive. */ export declare let chunks: (source: AsyncIterable<Uint8Array>, size: number) => AsyncIterable<Uint8Array<ArrayBuffer>>;
|
|
66
|
+
/** Recoverable workbench files, independent of the container SDK. Immutable
|
|
67
|
+
* archives and receipts have no expiry; the DO holds only the current head.
|
|
68
|
+
* A failed archive or head write leaves the container running. An upload cut
|
|
69
|
+
* off where no `catch` runs (the object reset mid-save) is aborted by the
|
|
70
|
+
* bucket's rule for `workbench/` (workers/yak/README.md, bucket setup). */ export declare let recovery: (box: Filesystem, state: State, bucket: Archive, id: string, pause?: (ms: number) => Promise<void>) => Recovery;
|
|
71
|
+
//# sourceMappingURL=recovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery.d.ts","sources":["../recovery.ts"],"names":[],"mappings":"KAKK;EAAS,YAAY,MAAM;EAAE,MAAM,MAAM;;KACzC;EACH,IAAI,GAAG,KAAK,MAAM,GAAG,QAAQ,IAAI,SAAS;EAC1C,IAAI,KAAK,MAAM,EAAE,OAAO,OAAO,GAAG,QAAQ,OAAO;EACjD,OAAO,KAAK,MAAM,GAAG,QAAQ,OAAO;;KAEjC;EACH,sBAAsB,KAAK,MAAM,GAAG;IAClC,UAAU,MAAM;IAChB,WAAW,MAAM,MAAM,EAAE,OAAO,aAAa,QAAQ;IACrD,SAAS,OAAO,SAAS,QAAQ,OAAO;IACxC,SAAS,QAAQ,IAAI;;EAEvB,IAAI,KAAK,MAAM,EAAE,SAAS,MAAM,GAAG,QAAQ,OAAO;EAClD,KAAK;IAAW,QAAQ,MAAM;IAAE,SAAS,MAAM;MAAK;IAClD;MAAW,KAAK,MAAM;;IACtB,WAAW,OAAO;IAClB,SAAS,MAAM;;EAEjB,OAAO,MAAM,MAAM,KAAK,QAAQ,OAAO;;KAEpC;EACH,QAAQ,OAAO,GAAG,QAAQ,OAAO;EACjC,UAAU,QAAQ,IAAI;EACtB,KAAK,SAAS,MAAM,GAAG;IACrB,UAAU,MAAM;IAChB,QAAQ,MAAM;IACd,QAAQ,MAAM;;;KAGb;EACH,QAAQ,OAAO,GAAG,QAAQ,OAAO;EACjC,UAAU,QAAQ,IAAI;EACtB,IAAI,MAAM,MAAM,EAAE,GAAG,MAAM,MAAM,KAAK,QAAQ,MAAM;EACpD,QAAQ,cAAc;EACtB,QAAQ,MAAM,MAAM,EAAE,MAAM,MAAM,GAAG,QAAQ,MAAM;;KAEhD;EACH,WAAW,QAAQ,IAAI;EACvB,QAAQ,QAAQ,IAAI;EACpB,IAAI,GAAG,WAAW,QAAQ,KAAK,QAAQ;EACvC,KAAK,YAAY,QAAQ,OAAO,GAAG,YAAY,QAAQ,IAAI,IAAI,QAAQ,IAAI;EAC3E,KAAK,GAAG,WAAW,QAAQ,KAAK,QAAQ;EACxC,MAAM,YAAY,QAAQ,OAAO,IAAI,QAAQ,IAAI;EACjD,SAAS,IAAI;;AAIf,OAAO,YAAI,sBAA6C;AACxD,OAAO,YAAI,qBAA+C;KAIrD;EACH,IAAI,KAAK,MAAM,GAAG;IAEd,MAAM,eAAe;IACrB,MAAM,MAAM;MACV,IAAI;;AAIZ,6EAA6E,GAC7E,OAAO,YAAI,WACT,QAAQ,UACR,IAAI,MAAM,EACV,SAAS,YACR,QAAQ,UAUV;AAMD,OAAO,YAAI,aACT,KAAK,KACL,YAAY,cAAc,aAC1B,kBACC,WAkBF;AAED,6EAA6E,GAC7E,OAAO,YAAI,SACT,QAAQ,cAAc,aACtB,MAAM,MAAM,KACX,cAAc,WAAW,cAiB3B;AAmDD;;;;yEAIyE,GACzE,OAAO,YAAI,WACT,KAAK,YACL,OAAO,OACP,QAAQ,SACR,IAAI,MAAM,EACV,SAAQ,IAAI,MAAM,KAAK,QAAQ,IAAI,MAClC,SAyHF"}
|
package/_dist/tools.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Runs } from "@yaks/graph/tools";
|
|
2
|
+
import { type Configuration, type ConfigurationHost } from "./configuration.js";
|
|
3
|
+
/** Resolve implementation bindings at invocation, after the graph is open. */ export declare let runs: (host: ConfigurationHost, configuration?: Configuration) => Runs;
|
|
4
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sources":["../tools.ts"],"names":[],"mappings":"AAEA,cAAc,IAAI,iCAAsC;AAExD,SACE,KAAK,aAAa,EAClB,KAAK,iBAAiB,6BAEG;AAE3B,4EAA4E,GAC5E,OAAO,YAAI,OACT,MAAM,mBACN,gBAAe,kBACd,KA8BD"}
|
package/_dist/vocab.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { VocabDoc } from "@yaks/vocab";
|
|
2
|
+
/** Containers, jails and confirmed disposal. */ export declare let sandboxDoc: VocabDoc;
|
|
3
|
+
/** The package description. */ export declare let description: string;
|
|
4
|
+
/** Every vocabulary document this package declares. */ export declare let docs: VocabDoc[];
|
|
5
|
+
//# sourceMappingURL=vocab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AACA,cAAc,QAAQ,2BAAgC;AAItD,8CAA8C,GAC9C,OAAO,YAAI,YAAY,SAA0B;AACjD,6BAA6B,GAC7B,OAAO,YAAI,aAAa,MAAM,CAAuB;AACrD,qDAAqD,GACrD,OAAO,YAAI,MAAM,WAAyB"}
|
package/archive.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as io from "@yaks/file/io";
|
|
2
|
+
import { command } from "@yaks/process/command";
|
|
3
|
+
let stat = (path)=>io.lstat(path).catch((error)=>{
|
|
4
|
+
if (!io.isNotFound(error)) throw error;
|
|
5
|
+
});
|
|
6
|
+
let run = async (program, args)=>{
|
|
7
|
+
let result = await command(program, {
|
|
8
|
+
args,
|
|
9
|
+
stdout: 'null',
|
|
10
|
+
stderr: 'piped'
|
|
11
|
+
}).output();
|
|
12
|
+
if (!result.success) {
|
|
13
|
+
throw new Error(`${program}: ${new TextDecoder().decode(result.stderr).trim()}`);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/** Move a stopped sandbox under its lifecycle lock. The complete destination
|
|
17
|
+
* is published before the source is removed. A retry after publication
|
|
18
|
+
* finishes removing the source, even if that removal was interrupted. */ export let transfer = async (source, into, id)=>{
|
|
19
|
+
let from = await stat(source);
|
|
20
|
+
if (!from) return;
|
|
21
|
+
let to = `${into}/${id}`;
|
|
22
|
+
if (source == to) {
|
|
23
|
+
throw new Error('Sandbox archive must be outside its checkout');
|
|
24
|
+
}
|
|
25
|
+
let parent = await io.stat(into);
|
|
26
|
+
if (!await stat(to)) {
|
|
27
|
+
if (from.dev == parent.dev) {
|
|
28
|
+
await io.rename(source, to);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let stage = `${into}/.transfer-${id}`;
|
|
32
|
+
await io.remove(stage, {
|
|
33
|
+
recursive: true,
|
|
34
|
+
force: true
|
|
35
|
+
});
|
|
36
|
+
try {
|
|
37
|
+
await run('/bin/cp', [
|
|
38
|
+
'-a',
|
|
39
|
+
'--',
|
|
40
|
+
source,
|
|
41
|
+
stage
|
|
42
|
+
]);
|
|
43
|
+
await io.rename(stage, to);
|
|
44
|
+
} finally{
|
|
45
|
+
await io.remove(stage, {
|
|
46
|
+
recursive: true,
|
|
47
|
+
force: true
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
await run('/bin/sync', [
|
|
52
|
+
'-f',
|
|
53
|
+
'--',
|
|
54
|
+
to
|
|
55
|
+
]);
|
|
56
|
+
await io.remove(source, {
|
|
57
|
+
recursive: true
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=archive.js.map
|
package/archive.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archive.js","sources":["./archive.ts"],"names":[],"mappings":"AAAA,YAAY,6BAAkC;AAC9C,SAAS,OAAO,qCAA0C;AAE1D,IAAI,OAAO,CAAC,OACV,GAAG,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG,UAAU,CAAC,QAAQ,MAAM;EACnC;AAEF,IAAI,MAAM,OAAO,SAAiB;EAChC,IAAI,SAAS,MAAM,QAAQ,SAAS;IAClC;IACA,QAAQ;IACR,QAAQ;EACV,GAAG,MAAM;EACT,IAAI,CAAC,OAAO,OAAO,EAAE;IACnB,MAAM,IAAI,MACR,GAAG,QAAQ,EAAE,EAAE,IAAI,cAAc,MAAM,CAAC,OAAO,MAAM,EAAE,IAAI,IAAI;EAEnE;AACF;AAEA;;uEAEuE,GACvE,OAAO,IAAI,WAAW,OAAO,QAAgB,MAAc;EACzD,IAAI,OAAO,MAAM,KAAK;EACtB,IAAI,CAAC,MAAM;EACX,IAAI,KAAK,GAAG,KAAK,CAAC,EAAE,IAAI;EACxB,IAAI,UAAU,IAAI;IAChB,MAAM,IAAI,MAAM;EAClB;EACA,IAAI,SAAS,MAAM,GAAG,IAAI,CAAC;EAC3B,IAAI,CAAC,MAAM,KAAK,KAAK;IACnB,IAAI,KAAK,GAAG,IAAI,OAAO,GAAG,EAAE;MAC1B,MAAM,GAAG,MAAM,CAAC,QAAQ;MACxB;IACF;IACA,IAAI,QAAQ,GAAG,KAAK,WAAW,EAAE,IAAI;IACrC,MAAM,GAAG,MAAM,CAAC,OAAO;MAAE,WAAW;MAAM,OAAO;IAAK;IACtD,IAAI;MACF,MAAM,IAAI,WAAW;QAAC;QAAM;QAAM;QAAQ;OAAM;MAChD,MAAM,GAAG,MAAM,CAAC,OAAO;IACzB,SAAU;MACR,MAAM,GAAG,MAAM,CAAC,OAAO;QAAE,WAAW;QAAM,OAAO;MAAK;IACxD;EACF;EACA,MAAM,IAAI,aAAa;IAAC;IAAM;IAAM;GAAG;EACvC,MAAM,GAAG,MAAM,CAAC,QAAQ;IAAE,WAAW;EAAK;AAC5C,EAAC"}
|
package/archive.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as io from '@yaks/file/io'
|
|
2
|
+
import { command } from '@yaks/process/command'
|
|
3
|
+
|
|
4
|
+
let stat = (path: string) =>
|
|
5
|
+
io.lstat(path).catch((error) => {
|
|
6
|
+
if (!io.isNotFound(error)) throw error
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
let run = async (program: string, args: string[]) => {
|
|
10
|
+
let result = await command(program, {
|
|
11
|
+
args,
|
|
12
|
+
stdout: 'null',
|
|
13
|
+
stderr: 'piped',
|
|
14
|
+
}).output()
|
|
15
|
+
if (!result.success) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
`${program}: ${new TextDecoder().decode(result.stderr).trim()}`,
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Move a stopped sandbox under its lifecycle lock. The complete destination
|
|
23
|
+
* is published before the source is removed. A retry after publication
|
|
24
|
+
* finishes removing the source, even if that removal was interrupted. */
|
|
25
|
+
export let transfer = async (source: string, into: string, id: string) => {
|
|
26
|
+
let from = await stat(source)
|
|
27
|
+
if (!from) return
|
|
28
|
+
let to = `${into}/${id}`
|
|
29
|
+
if (source == to) {
|
|
30
|
+
throw new Error('Sandbox archive must be outside its checkout')
|
|
31
|
+
}
|
|
32
|
+
let parent = await io.stat(into)
|
|
33
|
+
if (!await stat(to)) {
|
|
34
|
+
if (from.dev == parent.dev) {
|
|
35
|
+
await io.rename(source, to)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
let stage = `${into}/.transfer-${id}`
|
|
39
|
+
await io.remove(stage, { recursive: true, force: true })
|
|
40
|
+
try {
|
|
41
|
+
await run('/bin/cp', ['-a', '--', source, stage])
|
|
42
|
+
await io.rename(stage, to)
|
|
43
|
+
} finally {
|
|
44
|
+
await io.remove(stage, { recursive: true, force: true })
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
await run('/bin/sync', ['-f', '--', to])
|
|
48
|
+
await io.remove(source, { recursive: true })
|
|
49
|
+
}
|