@trama-dev/runtime 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/abort.d.ts +12 -0
- package/dist/abort.js +31 -0
- package/dist/agent-backend.d.ts +0 -6
- package/dist/agent-backend.js +1 -21
- package/dist/agent.d.ts +16 -1
- package/dist/agent.js +108 -35
- package/dist/bridge-client.js +44 -14
- package/dist/child-process.js +9 -9
- package/dist/client.d.ts +2 -1
- package/dist/client.js +5 -15
- package/dist/context.d.ts +36 -7
- package/dist/context.js +83 -92
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +2 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +84 -53
- package/dist/ipc-server.d.ts +4 -4
- package/dist/ipc-server.js +104 -137
- package/dist/journal-view.js +12 -4
- package/dist/journal.d.ts +15 -5
- package/dist/journal.js +209 -77
- package/dist/meta.d.ts +18 -0
- package/dist/meta.js +29 -0
- package/dist/path-guard.d.ts +128 -19
- package/dist/path-guard.js +384 -68
- package/dist/pi-adapter.d.ts +7 -6
- package/dist/pi-adapter.js +15 -26
- package/dist/replace-file.d.ts +31 -0
- package/dist/replace-file.js +75 -0
- package/dist/runner.d.ts +17 -31
- package/dist/runner.js +414 -201
- package/dist/serializable.d.ts +10 -4
- package/dist/serializable.js +56 -31
- package/dist/stopping.d.ts +4 -1
- package/dist/stopping.js +48 -10
- package/dist/tools.js +40 -10
- package/dist/tree.d.ts +234 -0
- package/dist/tree.js +1409 -0
- package/dist/types.d.ts +6 -3
- package/dist/workspace.d.ts +7 -0
- package/dist/workspace.js +93 -104
- package/package.json +1 -1
package/dist/serializable.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Recursively check that a value is strictly JSON-serializable.
|
|
3
3
|
* Throws TypeError with the path to the offending value.
|
|
4
|
-
*
|
|
5
|
-
* Uses a stack (ancestor chain) instead of a flat set so that shared-but-
|
|
6
|
-
* non-circular structures like { a: shared, b: shared } pass validation.
|
|
7
4
|
*/
|
|
8
|
-
export declare function assertSerializable(value: unknown, path: string
|
|
5
|
+
export declare function assertSerializable(value: unknown, path: string): void;
|
|
6
|
+
/** What a parsed JSON value is, for saying what was found where an object was expected. */
|
|
7
|
+
export declare const describeJson: (value: unknown) => string;
|
|
8
|
+
export declare const isJsonObject: (value: unknown) => value is Record<string, unknown>;
|
|
9
|
+
/**
|
|
10
|
+
* Log data as a log line will hold it: what JSON makes of it — or, where JSON
|
|
11
|
+
* can make nothing of it (a circular reference, a BigInt), a note that says
|
|
12
|
+
* so. A log call does not fail over what it was handed.
|
|
13
|
+
*/
|
|
14
|
+
export declare function toLogData(data: unknown): unknown;
|
package/dist/serializable.js
CHANGED
|
@@ -1,41 +1,66 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Recursively check that a value is strictly JSON-serializable.
|
|
3
3
|
* Throws TypeError with the path to the offending value.
|
|
4
|
-
*
|
|
5
|
-
* Uses a stack (ancestor chain) instead of a flat set so that shared-but-
|
|
6
|
-
* non-circular structures like { a: shared, b: shared } pass validation.
|
|
7
4
|
*/
|
|
8
|
-
export function assertSerializable(value, path
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
export function assertSerializable(value, path) {
|
|
6
|
+
// The objects on the way down to the value being checked. An ancestor chain
|
|
7
|
+
// rather than a set of everything seen, so that a structure that is shared
|
|
8
|
+
// but not circular — { a: shared, b: shared } — passes.
|
|
9
|
+
const ancestors = new Set();
|
|
10
|
+
const check = (value, path) => {
|
|
11
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
12
|
+
return;
|
|
13
|
+
if (typeof value === "number") {
|
|
14
|
+
if (!Number.isFinite(value))
|
|
15
|
+
throw new TypeError(`${path} is not JSON-serializable (${value})`);
|
|
16
|
+
return;
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
if (typeof value !== "object") {
|
|
19
|
+
throw new TypeError(`${path} is not JSON-serializable (${typeof value})`);
|
|
20
|
+
}
|
|
21
|
+
if (ancestors.has(value)) {
|
|
22
|
+
throw new TypeError(`${path} contains a circular reference`);
|
|
23
|
+
}
|
|
24
|
+
ancestors.add(value);
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
for (let i = 0; i < value.length; i++)
|
|
27
|
+
check(value[i], `${path}[${i}]`);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const proto = Object.getPrototypeOf(value);
|
|
31
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
32
|
+
const name = value.constructor?.name ?? "unknown";
|
|
33
|
+
throw new TypeError(`${path} is not a plain object (${name})`);
|
|
34
|
+
}
|
|
35
|
+
for (const [k, v] of Object.entries(value))
|
|
36
|
+
check(v, `${path}.${k}`);
|
|
28
37
|
}
|
|
29
38
|
ancestors.delete(value);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
};
|
|
40
|
+
check(value, path);
|
|
41
|
+
}
|
|
42
|
+
/** What a parsed JSON value is, for saying what was found where an object was expected. */
|
|
43
|
+
export const describeJson = (value) => Array.isArray(value) ? "an array" : value === null ? "null" : typeof value;
|
|
44
|
+
export const isJsonObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45
|
+
/**
|
|
46
|
+
* Log data as a log line will hold it: what JSON makes of it — or, where JSON
|
|
47
|
+
* can make nothing of it (a circular reference, a BigInt), a note that says
|
|
48
|
+
* so. A log call does not fail over what it was handed.
|
|
49
|
+
*/
|
|
50
|
+
export function toLogData(data) {
|
|
51
|
+
try {
|
|
52
|
+
const text = JSON.stringify(data);
|
|
53
|
+
return text === undefined ? undefined : JSON.parse(text);
|
|
36
54
|
}
|
|
37
|
-
|
|
38
|
-
|
|
55
|
+
catch {
|
|
56
|
+
let described;
|
|
57
|
+
// An object with no prototype cannot even be turned into text.
|
|
58
|
+
try {
|
|
59
|
+
described = String(data);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
described = Object.prototype.toString.call(data);
|
|
63
|
+
}
|
|
64
|
+
return { __trama_unserializable: described };
|
|
39
65
|
}
|
|
40
|
-
ancestors.delete(value);
|
|
41
66
|
}
|
package/dist/stopping.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Send a signal to a whole process group. Children spawned with `detached: true`
|
|
3
3
|
* lead their own group, so this also reaches whatever they started in the background.
|
|
4
|
-
* Signal 0 only probes. Returns false if the group no longer exists
|
|
4
|
+
* Signal 0 only probes. Returns false if the group no longer exists — or
|
|
5
|
+
* holds nothing that can be signalled, which is the same to one who means to
|
|
6
|
+
* stop it. (macOS says so of a group whose last members have exited and are
|
|
7
|
+
* yet to be reaped; to wait for such a group is to wait for nothing.)
|
|
5
8
|
*/
|
|
6
9
|
export declare function signalGroup(pgid: number, signal: NodeJS.Signals | 0): boolean;
|
|
7
10
|
/**
|
package/dist/stopping.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
// Nothing here listens for a signal or for the process exiting: the process
|
|
24
24
|
// that hosts a runner keeps its own way of handling both.
|
|
25
25
|
import { spawn } from "child_process";
|
|
26
|
-
import
|
|
26
|
+
import * as fs from "fs";
|
|
27
27
|
/** How long a process group gets to exit after SIGTERM before it is sent SIGKILL. */
|
|
28
28
|
const KILL_GRACE_MS = 5000;
|
|
29
29
|
const STOP_POLL_MS = 25;
|
|
@@ -32,7 +32,10 @@ const KILL_SETTLE_MS = 1000;
|
|
|
32
32
|
/**
|
|
33
33
|
* Send a signal to a whole process group. Children spawned with `detached: true`
|
|
34
34
|
* lead their own group, so this also reaches whatever they started in the background.
|
|
35
|
-
* Signal 0 only probes. Returns false if the group no longer exists
|
|
35
|
+
* Signal 0 only probes. Returns false if the group no longer exists — or
|
|
36
|
+
* holds nothing that can be signalled, which is the same to one who means to
|
|
37
|
+
* stop it. (macOS says so of a group whose last members have exited and are
|
|
38
|
+
* yet to be reaped; to wait for such a group is to wait for nothing.)
|
|
36
39
|
*/
|
|
37
40
|
export function signalGroup(pgid, signal) {
|
|
38
41
|
try {
|
|
@@ -43,15 +46,49 @@ export function signalGroup(pgid, signal) {
|
|
|
43
46
|
return false;
|
|
44
47
|
}
|
|
45
48
|
}
|
|
49
|
+
// --- Removing what was made ---
|
|
50
|
+
/**
|
|
51
|
+
* Remove a directory tree, whatever has been done to it since it was made. A
|
|
52
|
+
* tree with a directory in it that may not be written to — a copy of a project
|
|
53
|
+
* that has one, or one a program made so — cannot be emptied as it stands; so
|
|
54
|
+
* where removing it fails, its directories are opened first.
|
|
55
|
+
*
|
|
56
|
+
* It runs in two processes, here and in the watchdog, which is handed its
|
|
57
|
+
* text: it may use nothing but its arguments.
|
|
58
|
+
*/
|
|
59
|
+
function removeTree(fs, dir) {
|
|
60
|
+
const remove = () => fs.rmSync(dir, { recursive: true, force: true });
|
|
61
|
+
try {
|
|
62
|
+
return remove();
|
|
63
|
+
}
|
|
64
|
+
catch { /* opened below, and tried once more */ }
|
|
65
|
+
const open = (at) => {
|
|
66
|
+
try {
|
|
67
|
+
fs.chmodSync(at, 0o700);
|
|
68
|
+
for (const entry of fs.readdirSync(at, { withFileTypes: true })) {
|
|
69
|
+
if (entry.isDirectory())
|
|
70
|
+
open(at + "/" + entry.name); // not a link to one: only this tree is touched
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch { /* what cannot be opened stays as it is */ }
|
|
74
|
+
};
|
|
75
|
+
open(dir);
|
|
76
|
+
try {
|
|
77
|
+
remove();
|
|
78
|
+
}
|
|
79
|
+
catch { /* left for the OS to reap */ }
|
|
80
|
+
}
|
|
46
81
|
// --- The watchdog ---
|
|
47
82
|
// Run by the watchdog process: the same policy as stopGroups below. A group
|
|
48
83
|
// the runner had already asked to stop is not asked a second time.
|
|
49
84
|
const WATCHDOG = `
|
|
50
|
-
const
|
|
85
|
+
const fs = require("fs");
|
|
86
|
+
${removeTree}
|
|
87
|
+
${signalGroup}
|
|
51
88
|
const { grace, settle, poll } = JSON.parse(process.argv[1]);
|
|
52
89
|
const lists = { g: new Set(), d: new Set(), asked: new Set() };
|
|
53
|
-
const alive = (pgid) =>
|
|
54
|
-
const signal =
|
|
90
|
+
const alive = (pgid) => signalGroup(pgid, 0);
|
|
91
|
+
const signal = signalGroup;
|
|
55
92
|
|
|
56
93
|
let unread = "";
|
|
57
94
|
process.stdin.setEncoding("utf8");
|
|
@@ -69,7 +106,7 @@ const takeOver = () => {
|
|
|
69
106
|
if (leaving) return;
|
|
70
107
|
leaving = true;
|
|
71
108
|
const finish = () => {
|
|
72
|
-
for (const dir of lists.d)
|
|
109
|
+
for (const dir of lists.d) removeTree(fs, dir);
|
|
73
110
|
process.exit(0);
|
|
74
111
|
};
|
|
75
112
|
let left = [...lists.g].filter(alive);
|
|
@@ -110,9 +147,13 @@ function startWatchdog() {
|
|
|
110
147
|
let child;
|
|
111
148
|
try {
|
|
112
149
|
const timings = { grace: KILL_GRACE_MS, settle: KILL_SETTLE_MS, poll: STOP_POLL_MS };
|
|
150
|
+
// It is this file's own few lines, and is to start whatever this process was started with:
|
|
151
|
+
// not with what NODE_OPTIONS would have it load first, or wait for (a debugger, say).
|
|
152
|
+
const { NODE_OPTIONS: _options, ...env } = process.env;
|
|
113
153
|
child = spawn(process.execPath, ["-e", WATCHDOG, JSON.stringify(timings)], {
|
|
114
154
|
detached: true, // a signal sent to this process's group must not reach it
|
|
115
155
|
stdio: ["pipe", "ignore", "ignore"],
|
|
156
|
+
env,
|
|
116
157
|
});
|
|
117
158
|
}
|
|
118
159
|
catch {
|
|
@@ -179,10 +220,7 @@ export function removeWithThisProcess(dir) {
|
|
|
179
220
|
}
|
|
180
221
|
/** Remove a temp directory. Best-effort: failing to clean up must never change a run's outcome. */
|
|
181
222
|
export function removeTempDir(dir) {
|
|
182
|
-
|
|
183
|
-
rmSync(dir, { recursive: true, force: true });
|
|
184
|
-
}
|
|
185
|
-
catch { /* left for the OS to reap */ }
|
|
223
|
+
removeTree(fs, dir);
|
|
186
224
|
}
|
|
187
225
|
// --- Stopping, while this process is there to see it through ---
|
|
188
226
|
/** Groups this process has asked to stop and is still watching. */
|
package/dist/tools.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
|
-
import { readFileSync, writeFileSync
|
|
2
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
3
3
|
import { resolve, dirname } from "path";
|
|
4
|
-
import { guardPath } from "./path-guard.js";
|
|
4
|
+
import { guardPath, makeDirsIn, projectAt, realRootOf } from "./path-guard.js";
|
|
5
5
|
import { superviseChild } from "./child-process.js";
|
|
6
|
+
import { messageOf } from "./errors.js";
|
|
6
7
|
import { signalGroup, stopGroups, stopWithThisProcess } from "./stopping.js";
|
|
7
8
|
const MAX_FETCH_BODY = 10 * 1024 * 1024; // 10 MB
|
|
8
9
|
const DEFAULT_SHELL_TIMEOUT = 30_000;
|
|
@@ -78,7 +79,11 @@ export function createTools(projectDir, signal) {
|
|
|
78
79
|
},
|
|
79
80
|
async write(path, content) {
|
|
80
81
|
const target = guardPath(normalizedProjectDir, path); // before mkdir — no side effects outside the project
|
|
81
|
-
|
|
82
|
+
// (Asked to write the project itself, the system refuses a directory. Where the project is gone it is refused
|
|
83
|
+
// either way, as any write is: this only says of the project what is otherwise said of "the directory".)
|
|
84
|
+
if (target === realRootOf(normalizedProjectDir))
|
|
85
|
+
projectAt(normalizedProjectDir);
|
|
86
|
+
makeDirsIn(normalizedProjectDir, dirname(target));
|
|
82
87
|
writeFileSync(target, content);
|
|
83
88
|
},
|
|
84
89
|
async shell(command, options = {}) {
|
|
@@ -106,9 +111,7 @@ export function createTools(projectDir, signal) {
|
|
|
106
111
|
}
|
|
107
112
|
catch (spawnError) {
|
|
108
113
|
// Failed to start (e.g. cwd does not exist) — a result, not an exception.
|
|
109
|
-
|
|
110
|
-
untrack(pgid);
|
|
111
|
-
return { exitCode: 1, stdout: "", stderr: spawnError.message };
|
|
114
|
+
return { exitCode: 1, stdout: "", stderr: messageOf(spawnError) };
|
|
112
115
|
}
|
|
113
116
|
},
|
|
114
117
|
async fetch(url, options = {}) {
|
|
@@ -118,10 +121,37 @@ export function createTools(projectDir, signal) {
|
|
|
118
121
|
body: options.body,
|
|
119
122
|
signal,
|
|
120
123
|
});
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
124
|
+
let body;
|
|
125
|
+
if (response.body) {
|
|
126
|
+
const reader = response.body.getReader();
|
|
127
|
+
const decoder = new TextDecoder("utf-8");
|
|
128
|
+
let text = "";
|
|
129
|
+
let truncated = false;
|
|
130
|
+
try {
|
|
131
|
+
for (;;) {
|
|
132
|
+
const { done, value } = await reader.read();
|
|
133
|
+
if (done)
|
|
134
|
+
break;
|
|
135
|
+
text += decoder.decode(value, { stream: true });
|
|
136
|
+
if (text.length > MAX_FETCH_BODY) {
|
|
137
|
+
truncated = true;
|
|
138
|
+
await reader.cancel();
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (!truncated)
|
|
143
|
+
text += decoder.decode();
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
reader.releaseLock();
|
|
147
|
+
}
|
|
148
|
+
body = truncated
|
|
149
|
+
? text.slice(0, MAX_FETCH_BODY) + "\n[trama] response body truncated at 10MB"
|
|
150
|
+
: text;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
body = ""; // (an answer that has no body: to a HEAD, say)
|
|
154
|
+
}
|
|
125
155
|
const headers = {};
|
|
126
156
|
response.headers.forEach((v, k) => { headers[k] = v; });
|
|
127
157
|
return { status: response.status, body, headers };
|
package/dist/tree.d.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What is at one path. `id` says which file, directory or link it is: it
|
|
3
|
+
* stays the same through being written to, renamed, or given other
|
|
4
|
+
* permissions, and nothing else has it. (It is the system's numbers for it —
|
|
5
|
+
* its device's, and its own on that — and a file system may give a number
|
|
6
|
+
* again once what had it is gone: what was removed can so be taken for what
|
|
7
|
+
* was made after it.)
|
|
8
|
+
*/
|
|
9
|
+
export type Entry =
|
|
10
|
+
/** `stamp` is different after any change to the file — to what it holds or to what it allows — and cannot be set by a program. */
|
|
11
|
+
{
|
|
12
|
+
kind: "file";
|
|
13
|
+
mode: number;
|
|
14
|
+
size: number;
|
|
15
|
+
stamp: string;
|
|
16
|
+
id: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "dir";
|
|
19
|
+
mode: number;
|
|
20
|
+
id: string;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "link";
|
|
23
|
+
text: string;
|
|
24
|
+
id: string;
|
|
25
|
+
}
|
|
26
|
+
/** A pipe, a socket, a device, a link that says nothing a path can be made of: one end of something else, not content. */
|
|
27
|
+
| {
|
|
28
|
+
kind: "other";
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* What a directory is and holds: the directory itself, as ".", and every path
|
|
32
|
+
* under it ("/" between the names) — a directory before what is in it.
|
|
33
|
+
*/
|
|
34
|
+
export type Tree = Map<string, Entry>;
|
|
35
|
+
/** What is at a path — the path itself, not what a link there leads to. Undefined if nothing is. */
|
|
36
|
+
export declare function entryAt(path: string): Entry | undefined;
|
|
37
|
+
/** What a directory is and holds. The directory must be there, and all of it readable. */
|
|
38
|
+
export declare function readTree(dir: string): Tree;
|
|
39
|
+
/**
|
|
40
|
+
* Make `toDir` — an empty directory — what `fromDir` is: allowing what it
|
|
41
|
+
* allows and holding what it holds. Returns what that was: the directory, and
|
|
42
|
+
* each entry as it was when it was copied. `leaveOut` names
|
|
43
|
+
* what is no part of it; those entries are neither copied nor returned.
|
|
44
|
+
*
|
|
45
|
+
* What a directory holds is its files, its directories with what they allow,
|
|
46
|
+
* and its links. What is not content is not carried over, though the tree
|
|
47
|
+
* returned says it is there. The directory itself is one of its directories
|
|
48
|
+
* in this: the copy is left allowing what it allows — to its owner, and to
|
|
49
|
+
* everybody else. (So a copy that is to be nobody else's is made in a
|
|
50
|
+
* directory that is nobody else's.)
|
|
51
|
+
*
|
|
52
|
+
* A link is made to name, in the copy, what it names here: the same place in
|
|
53
|
+
* the copy if that is under `fromDir`, and the same place outside it if not.
|
|
54
|
+
* Most links do that as they are written, and are kept so — but for the
|
|
55
|
+
* letters of a name the copy does not have as it is written, where its file
|
|
56
|
+
* system tells apart what this one takes for one name. Not one whose
|
|
57
|
+
* way steps out of the directory over its top with "..", or into it from
|
|
58
|
+
* outside: from the copy's place those words lead somewhere else — or back
|
|
59
|
+
* into the original, where what was done through the link in the copy would
|
|
60
|
+
* be done to the original. Such a link is rewritten. If its way comes to the
|
|
61
|
+
* directory from outside and stays in it, what it says from there on is said
|
|
62
|
+
* of the directory, and is kept, said of the copy: only the part that comes
|
|
63
|
+
* to the directory is replaced, and a link of the directory on the rest of
|
|
64
|
+
* the way is still passed through in the copy, wherever it then leads. If
|
|
65
|
+
* not — the way ends outside — the link is made to name the place itself.
|
|
66
|
+
* A link whose way cannot be followed here names nothing that can be told,
|
|
67
|
+
* and is not carried over. Whether it can be is asked of this reading, and of
|
|
68
|
+
* the system: a link the system will not follow — too many links on its way,
|
|
69
|
+
* a name too long — is not carried either, whatever it says, since a copy of
|
|
70
|
+
* it could come to be followed where a link on its way is rewritten shorter.
|
|
71
|
+
* Nor is one whose rewritten words the system will not have for a link.
|
|
72
|
+
*
|
|
73
|
+
* The tree returned is read in the same pass that copies, each entry before
|
|
74
|
+
* it is copied. So the copy never holds what the tree does not know of; and
|
|
75
|
+
* an entry that changes while it is copied is in the tree as it was before,
|
|
76
|
+
* which is the side to err on — it will not be taken for untouched later.
|
|
77
|
+
*/
|
|
78
|
+
export declare function copyTree(fromDir: string, toDir: string, leaveOut?: (at: string, entry: Entry) => boolean): Tree;
|
|
79
|
+
/**
|
|
80
|
+
* The path a reading of `dir` has for a place: each step by the name its
|
|
81
|
+
* directory lists for it, and "." for the directory itself. Undefined if
|
|
82
|
+
* nothing is there, or the place is not in `dir`. The place is named without
|
|
83
|
+
* links.
|
|
84
|
+
*/
|
|
85
|
+
export declare function pathAsListed(dir: string, place: string): string | undefined;
|
|
86
|
+
/** Something a run did in a copy that did not reach the real directory, and why. */
|
|
87
|
+
export interface Unmerged {
|
|
88
|
+
path: string;
|
|
89
|
+
why: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Carry what a run did to a copy back into the directory it is a copy of.
|
|
93
|
+
*
|
|
94
|
+
* @param stagedDir - the copy, as the run left it
|
|
95
|
+
* @param realDir - the directory it was copied from
|
|
96
|
+
* @param before - the copy as it was before the run (readTree)
|
|
97
|
+
* @param seed - the real directory as it was when the copy was made (copyTree)
|
|
98
|
+
* @param together - things that are one thing to the caller: each list the
|
|
99
|
+
* `id`s (see Entry) of the files, links and directories that are one
|
|
100
|
+
*
|
|
101
|
+
* What the run did is where the copy differs from what it was: a file, a
|
|
102
|
+
* directory or a link made, removed, changed, or put where something of
|
|
103
|
+
* another kind was; permissions changed — those of the directory itself
|
|
104
|
+
* among them, which is a directory like any in it: only that it is neither
|
|
105
|
+
* made nor removed. Each difference is carried over on
|
|
106
|
+
* one condition: the place in the real directory is still as it was when the
|
|
107
|
+
* copy was made — and so is the directory it is in. If not, somebody else —
|
|
108
|
+
* the user, another run of the same project — has been there since, and
|
|
109
|
+
* theirs is kept. A place that already holds what the run left needs nothing
|
|
110
|
+
* done, whoever made it so.
|
|
111
|
+
*
|
|
112
|
+
* There is no path this leaves out. Where the caller has itself put
|
|
113
|
+
* something into the real directory since the copy was made, it says so in
|
|
114
|
+
* `seed`: the place is then as the seed has it, and what the run did there is
|
|
115
|
+
* carried over like anything else.
|
|
116
|
+
*
|
|
117
|
+
* All of that is found out before anything is done. What cannot arrive is
|
|
118
|
+
* then left alone, with everything under it; and a directory the run removed,
|
|
119
|
+
* or put something else in the place of, goes only if all that is in it goes
|
|
120
|
+
* — if anything in it stays, or it holds something the run never saw, the
|
|
121
|
+
* directory stays whole. What the run moved — a file, a link, a directory —
|
|
122
|
+
* goes from where it was only if it arrives where the run moved it: what it
|
|
123
|
+
* holds is not to be in neither place. (What was moved is known by its `id`,
|
|
124
|
+
* see Entry. What the run copied and then removed is a new file, and is not
|
|
125
|
+
* known to be the old one's.) And what the caller says is one thing — a
|
|
126
|
+
* link, say, with the file that makes it lead somewhere: the things in one
|
|
127
|
+
* list of `together`, each known by what it is, at every path where the copy
|
|
128
|
+
* had it before the run or has it now — arrives together or not at all: if
|
|
129
|
+
* one of those paths is left alone, nothing is done at any of them. A part
|
|
130
|
+
* the run left as it was has nothing to arrive, but the rest leans on it: if
|
|
131
|
+
* it is not, in the project, as it was when the copy was made, that is told
|
|
132
|
+
* of it, and the rest does not arrive. (So that all this holds where the
|
|
133
|
+
* system refuses in the doing, what is done at such a path is only what can
|
|
134
|
+
* be taken back: a file there is not written into but has the new one put in
|
|
135
|
+
* its place, and what is to go from there is moved aside first, as what is
|
|
136
|
+
* taken the place of is. A directory among them that stays a directory is
|
|
137
|
+
* not left alone with the rest — what else the run did in it could not be
|
|
138
|
+
* taken for undone with it — but what it was to be left allowing does not
|
|
139
|
+
* arrive either, and that is told of it. And a part the run left as it was,
|
|
140
|
+
* and that is not so in the project, is told of besides, as that: nothing
|
|
141
|
+
* under it is left alone for it — and nothing is told of it where nothing is
|
|
142
|
+
* held back for it.) So what is returned as not arrived is as it
|
|
143
|
+
* was, at that path and under it. That holds where the system refuses, in
|
|
144
|
+
* the doing, what had been found possible — see how it is done, below — as
|
|
145
|
+
* long as it does not also refuse to put back what was moved aside; then
|
|
146
|
+
* the report says where that is.
|
|
147
|
+
*
|
|
148
|
+
* Some things are told of besides, which are not that. What was moved aside
|
|
149
|
+
* to go, or made ready and not needed, and which the system will not have
|
|
150
|
+
* removed, is told of at the name it is left under — a path that is none of
|
|
151
|
+
* the run's. A directory the run removed which the system will not remove,
|
|
152
|
+
* or not with all that was in it, holds what is left, as it would had the
|
|
153
|
+
* run removed it there, and is told of so. A directory or a file that could
|
|
154
|
+
* not be given, at the end, what it is to allow is told of for that: what
|
|
155
|
+
* it holds has arrived, unless that is told of itself. A file that could not
|
|
156
|
+
* be written into, and had a new one put in its place, is told of for that.
|
|
157
|
+
* (If the system will not have the new one put there either, the file did
|
|
158
|
+
* not arrive, and the report says that what it held may be damaged, and
|
|
159
|
+
* where what it was to hold is.)
|
|
160
|
+
*
|
|
161
|
+
* Finding out is looking, and a directory that is closed cannot be looked
|
|
162
|
+
* into. One of the real directory's — or the directory itself — is opened
|
|
163
|
+
* for it, as it is for what is then done in it, and one of the copy's is
|
|
164
|
+
* opened to be read: both are this merge's to open. Each is left, at the end,
|
|
165
|
+
* allowing what the run left it allowing — or, if that did not arrive, what
|
|
166
|
+
* it allowed. (One that somebody else gave other permissions since the copy
|
|
167
|
+
* was made is theirs, and is not opened: nothing is made or removed in it.)
|
|
168
|
+
*
|
|
169
|
+
* A path is a name, and the real directory has the last word on its names:
|
|
170
|
+
* its file system may take "Notes.txt" and "notes.txt" for one. A path of
|
|
171
|
+
* the tree whose place holds something, though the directory does not list
|
|
172
|
+
* the name as the tree spells it, is such a second spelling — the run
|
|
173
|
+
* spelled a name anew, or made one beside another on a file system that
|
|
174
|
+
* tells them apart. To a tree that is one entry removed and another made; in
|
|
175
|
+
* the real directory the two are one place, and removing the one would
|
|
176
|
+
* remove the other. Neither is touched: nothing is done to what is there
|
|
177
|
+
* under any name the run changed, and each is told of as not arrived. (What
|
|
178
|
+
* is there is known by what it is. All the names of a file that has several
|
|
179
|
+
* are therefore left, where one would have done.) If what is there is a
|
|
180
|
+
* directory, nothing is done in it either: a path through it is a path
|
|
181
|
+
* through the other, and what the run left under the two names is in one
|
|
182
|
+
* place. And two names the run made where nothing was, which the directory
|
|
183
|
+
* turns out to take for one when the second is put there: neither is put.
|
|
184
|
+
* (That can only be seen in the putting. If the first was not put, for a
|
|
185
|
+
* reason of its own, the second is — and what is told of the first is then
|
|
186
|
+
* true of the name as the run spelled it, not as the directory takes it.)
|
|
187
|
+
* The same is asked of the way to a path: a directory on it that the real
|
|
188
|
+
* one no longer lists as the tree spells it — somebody spelled it anew — is
|
|
189
|
+
* not the tree's directory any more, and nothing is done in it.
|
|
190
|
+
*
|
|
191
|
+
* What is to be done is done so that nothing is lost by its being done in
|
|
192
|
+
* part. A file or a link that is to be where something is, is made beside
|
|
193
|
+
* the place first. Then what the run made is made, a directory before what
|
|
194
|
+
* goes in it. What is in the place of it is not removed but moved aside,
|
|
195
|
+
* under a name of its own beside the place, and what was made beside the
|
|
196
|
+
* place is moved in. (Only a directory that stays a directory, and a file
|
|
197
|
+
* the run wrote into that can be written into, stay and are changed where
|
|
198
|
+
* they are. A file that is written into has what it is to hold made beside
|
|
199
|
+
* it first all the same: if the system will not have the writing — which it
|
|
200
|
+
* may have begun — that takes its place.) Where the system will not have a thing done, that
|
|
201
|
+
* thing is left alone like what was found impossible beforehand, with what
|
|
202
|
+
* follows from it — and what follows may be that something already done is
|
|
203
|
+
* not to stand: what the run moved from there did not arrive where it went.
|
|
204
|
+
* Then what was put there is removed again, and what was moved aside comes
|
|
205
|
+
* back. Only when all that is settled does what was moved aside go for good,
|
|
206
|
+
* and what the run removed, where it is. (A runner that is stopped in the
|
|
207
|
+
* middle leaves what it had moved aside, or made ready, where it is: under
|
|
208
|
+
* names that begin with .trama-tmp-.) It is where the run ended that is
|
|
209
|
+
* carried over, not the steps by which it got there.
|
|
210
|
+
*
|
|
211
|
+
* A file the run wrote into is written into, if it may be, and stays the
|
|
212
|
+
* file it is — as does one that holds what the run left already, and has
|
|
213
|
+
* only what it allows changed. Where the run put another file in the place,
|
|
214
|
+
* or the file may not be written into, or the system will not have it
|
|
215
|
+
* written into after all, a new one is put in its place — and then a second
|
|
216
|
+
* name of the old file is none of the new one, and holds whatever the
|
|
217
|
+
* writing left. A link is written as the run wrote it
|
|
218
|
+
* — the run took its copy for the directory itself — unless its way comes to
|
|
219
|
+
* the copy from outside: by the copy's full path, or out of the copy and
|
|
220
|
+
* back in by its name. What such a link says from there on is said of the
|
|
221
|
+
* real directory, wherever that leads from there. So a link the copy
|
|
222
|
+
* was given in other words than the directory's own (see copyTree), if the
|
|
223
|
+
* run moved it, is merged in those words: it names what the run found it to
|
|
224
|
+
* name, which is not always what the directory's own words would name from
|
|
225
|
+
* the new place. And a link the run made that climbs out of its directory
|
|
226
|
+
* with ".." and does not come back says the same in the real directory, and
|
|
227
|
+
* names from there what it names from there.
|
|
228
|
+
*
|
|
229
|
+
* Nothing is thrown. What could not be carried over is returned, each path
|
|
230
|
+
* with the reason, so that a run whose work did not all arrive is not passed
|
|
231
|
+
* off as one whose work did. Under a path that did not arrive, what was not
|
|
232
|
+
* looked at for that reason is not listed: it is as it was, with the path.
|
|
233
|
+
*/
|
|
234
|
+
export declare function mergeTree(stagedDir: string, realDir: string, before: Tree, seed: Tree, together?: string[][]): Unmerged[];
|