@trama-dev/runtime 0.6.1 → 0.8.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/dist/agent-backend.d.ts +100 -0
- package/dist/agent-backend.js +4 -0
- package/dist/agent-host.d.ts +46 -7
- package/dist/agent-host.js +59 -19
- package/dist/agent-hosts.d.ts +8 -0
- package/dist/agent-hosts.js +123 -56
- package/dist/agent.d.ts +18 -5
- package/dist/agent.js +23 -64
- package/dist/bridge-client.d.ts +6 -2
- package/dist/bridge-client.js +7 -1
- package/dist/budget.d.ts +6 -0
- package/dist/budget.js +1 -0
- package/dist/client.d.ts +3 -2
- package/dist/client.js +146 -2
- package/dist/context.js +3 -2
- package/dist/history.d.ts +9 -0
- package/dist/history.js +98 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +73 -41
- package/dist/ipc-server.d.ts +2 -3
- package/dist/ipc-server.js +99 -38
- package/dist/journal-view.d.ts +8 -0
- package/dist/journal-view.js +63 -11
- package/dist/journal.d.ts +10 -4
- package/dist/journal.js +73 -7
- package/dist/merge-deeds.d.ts +22 -0
- package/dist/merge-deeds.js +201 -0
- package/dist/merge-doing.d.ts +9 -0
- package/dist/merge-doing.js +410 -0
- package/dist/merge-settle.d.ts +14 -0
- package/dist/merge-settle.js +166 -0
- package/dist/merge-shared.d.ts +64 -0
- package/dist/merge-shared.js +159 -0
- package/dist/merge.d.ts +150 -0
- package/dist/merge.js +209 -0
- package/dist/model-relay.d.ts +19 -0
- package/dist/model-relay.js +91 -9
- package/dist/model-request.d.ts +9 -0
- package/dist/model-request.js +185 -0
- package/dist/own-tools.d.ts +60 -0
- package/dist/own-tools.js +209 -0
- package/dist/path-guard.js +8 -6
- package/dist/pi-adapter.d.ts +32 -9
- package/dist/pi-adapter.js +198 -51
- package/dist/project.d.ts +39 -0
- package/dist/project.js +270 -0
- package/dist/replace-file.d.ts +13 -2
- package/dist/replace-file.js +23 -6
- package/dist/runner-backend.d.ts +43 -0
- package/dist/runner-backend.js +149 -0
- package/dist/runner-types.d.ts +26 -0
- package/dist/runner.d.ts +10 -125
- package/dist/runner.js +148 -461
- package/dist/schema.d.ts +45 -0
- package/dist/schema.js +113 -0
- package/dist/stopping.js +2 -3
- package/dist/tools.d.ts +8 -1
- package/dist/tools.js +36 -10
- package/dist/tree.d.ts +33 -149
- package/dist/tree.js +43 -1077
- package/dist/types.d.ts +182 -2
- package/dist/workspace.d.ts +28 -1
- package/dist/workspace.js +88 -13
- package/package.json +2 -2
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// What follows, in a merge, from what does not arrive (see merge.ts).
|
|
2
|
+
//
|
|
3
|
+
// It is apart because it touches nothing: it asks nothing of either
|
|
4
|
+
// directory, and all it does is say of more paths that they are left alone
|
|
5
|
+
// (or, of a directory that stays one, that what it was to allow is held
|
|
6
|
+
// back). It is asked again whenever the doing has been refused something, and
|
|
7
|
+
// goes on from where it was: what it has followed up and counted out is its
|
|
8
|
+
// own, and is kept between one asking and the next.
|
|
9
|
+
import { addTo, idOf, inOrder } from "./tree.js";
|
|
10
|
+
import { goesAsADirectory, staysADirectory } from "./merge-deeds.js";
|
|
11
|
+
/** The following up of some deeds. Nothing is followed up until `settle` is called. */
|
|
12
|
+
export function followingUp(deeds, amiss, { before, after }, { partOf, parts }, { refused, leftAlone, tell }) {
|
|
13
|
+
/** Where each file, directory and link is, as the run left things. */
|
|
14
|
+
const nowAt = new Map();
|
|
15
|
+
for (const [path, is] of after) {
|
|
16
|
+
const id = idOf(is);
|
|
17
|
+
if (id !== undefined)
|
|
18
|
+
addTo(nowAt, id, path);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Where the run has what is at a deed's place, if that is to go from there
|
|
22
|
+
* or be taken the place of. (If it is there still, among other places, it
|
|
23
|
+
* has not been moved from there. A directory that stays a directory is not
|
|
24
|
+
* one that goes, whichever directory the run has there: what it holds is
|
|
25
|
+
* seen to path by path.)
|
|
26
|
+
*/
|
|
27
|
+
const wentTo = (deed) => {
|
|
28
|
+
const id = staysADirectory(deed) ? undefined : idOf(before.get(deed.path));
|
|
29
|
+
return (id === undefined ? undefined : nowAt.get(id)) ?? [];
|
|
30
|
+
};
|
|
31
|
+
const deedAt = new Map(deeds.map((deed) => [deed.path, deed]));
|
|
32
|
+
/** By each place the run moved something to, the deeds at the places it moved it from. */
|
|
33
|
+
const cameFrom = new Map();
|
|
34
|
+
/** Of each deed at a place the run moved something from, how many of the places it moved it to may yet arrive. */
|
|
35
|
+
const mayArriveAt = new Map();
|
|
36
|
+
for (const deed of deeds) {
|
|
37
|
+
const all = wentTo(deed);
|
|
38
|
+
if (all.length > 0)
|
|
39
|
+
mayArriveAt.set(deed, all.length);
|
|
40
|
+
for (const to of all)
|
|
41
|
+
addTo(cameFrom, to, deed);
|
|
42
|
+
}
|
|
43
|
+
/** The places the run moved something to, in order. */
|
|
44
|
+
const arrivals = [...cameFrom.keys()].sort();
|
|
45
|
+
/**
|
|
46
|
+
* What follows from what did not arrive, for what was to go from where it
|
|
47
|
+
* was — until nothing more follows. What the run moved goes from where it
|
|
48
|
+
* was only if it arrives where it went: what it holds is not to be in
|
|
49
|
+
* neither place. And a directory goes only if all that is in it goes. Each
|
|
50
|
+
* can bring the other about: what stays in a directory keeps the directory,
|
|
51
|
+
* and a directory that stays is in the way of what was moved to its place.
|
|
52
|
+
* (Each path that did not arrive is followed up once, and each place
|
|
53
|
+
* something was moved to is counted out once.)
|
|
54
|
+
*/
|
|
55
|
+
const followedUp = new Set();
|
|
56
|
+
const countedOut = new Set();
|
|
57
|
+
/** Of the things that are one (see `partOf`), those of which a part has not arrived, or is not as it was. */
|
|
58
|
+
const broken = new Set();
|
|
59
|
+
/**
|
|
60
|
+
* The directories that stay directories, of such things: by the path, what
|
|
61
|
+
* the thing did not arrive for. A directory like that is not left alone
|
|
62
|
+
* with the rest — what else was done in it could not be taken for undone
|
|
63
|
+
* with it — but what it was to be left allowing does not arrive.
|
|
64
|
+
*/
|
|
65
|
+
const heldBack = new Map();
|
|
66
|
+
/** Of paths in order, those that are a given path or under it. */
|
|
67
|
+
const atOrUnder = (sorted, path) => {
|
|
68
|
+
const under = `${path}/`;
|
|
69
|
+
const found = sorted[firstNotBefore(sorted, path)] === path ? [path] : [];
|
|
70
|
+
for (let at = firstNotBefore(sorted, under); at < sorted.length && sorted[at].startsWith(under); at++)
|
|
71
|
+
found.push(sorted[at]);
|
|
72
|
+
return found;
|
|
73
|
+
};
|
|
74
|
+
const settle = () => {
|
|
75
|
+
const toFollowUp = [...refused.keys()].filter((path) => !followedUp.has(path));
|
|
76
|
+
const refuse = (path, why) => {
|
|
77
|
+
if (leftAlone(path))
|
|
78
|
+
return;
|
|
79
|
+
refused.set(path, why());
|
|
80
|
+
toFollowUp.push(path);
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* The things a path is part of do not arrive: it did not, or is not as it
|
|
84
|
+
* was. Says whether anything is held back for that. (What follows from a
|
|
85
|
+
* directory's being held back is followed up in turn, not gone into: a
|
|
86
|
+
* chain of things may be as long as the caller makes it.)
|
|
87
|
+
*/
|
|
88
|
+
const without = (first, how) => {
|
|
89
|
+
let any = false;
|
|
90
|
+
const toDo = [[first, how]];
|
|
91
|
+
for (let next; (next = toDo.pop()) !== undefined;) {
|
|
92
|
+
const [part, which] = next;
|
|
93
|
+
// All the paths of the things it is part of, in order: a path under one that is left alone is left alone
|
|
94
|
+
// with it.
|
|
95
|
+
const others = new Set();
|
|
96
|
+
for (const paths of partOf.get(part) ?? []) {
|
|
97
|
+
if (broken.has(paths))
|
|
98
|
+
continue;
|
|
99
|
+
broken.add(paths);
|
|
100
|
+
for (const other of paths)
|
|
101
|
+
others.add(other);
|
|
102
|
+
}
|
|
103
|
+
for (const other of [...others].sort(inOrder)) {
|
|
104
|
+
const deed = deedAt.get(other);
|
|
105
|
+
if (!deed || leftAlone(other))
|
|
106
|
+
continue;
|
|
107
|
+
any = true;
|
|
108
|
+
if (!staysADirectory(deed)) {
|
|
109
|
+
refuse(other, () => `it is one thing with ${part}, ${which}: it is left as it was`);
|
|
110
|
+
}
|
|
111
|
+
else if (!heldBack.has(other)) {
|
|
112
|
+
heldBack.set(other, `${part}, ${which}`);
|
|
113
|
+
// (And what else it is one thing with does not arrive without what it was to allow.)
|
|
114
|
+
toDo.push([other, "which is not given what it was to allow"]);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return any;
|
|
119
|
+
};
|
|
120
|
+
// A part the run left as it was, and that is not so in the project. (It is told of only if something is
|
|
121
|
+
// held back for it: where the rest is in place already, nothing was left undone.)
|
|
122
|
+
for (const [part, why] of amiss) {
|
|
123
|
+
if (without(part, "which is not as it was in the project"))
|
|
124
|
+
tell(part, `the run left it as it was, but ${why}: what it is one thing with did not arrive`);
|
|
125
|
+
}
|
|
126
|
+
amiss.clear();
|
|
127
|
+
for (let path; (path = toFollowUp.pop()) !== undefined;) {
|
|
128
|
+
followedUp.add(path);
|
|
129
|
+
const stays = path;
|
|
130
|
+
// The directories it is in, which were to go.
|
|
131
|
+
for (let end = path.lastIndexOf("/"); end !== -1; end = path.lastIndexOf("/", end - 1)) {
|
|
132
|
+
const above = deedAt.get(path.slice(0, end));
|
|
133
|
+
if (above && goesAsADirectory(above))
|
|
134
|
+
refuse(above.path, () => `the run removed it, but not all that is in it can go (${stays})`);
|
|
135
|
+
}
|
|
136
|
+
// What was moved to it, or to somewhere under it, has not arrived there.
|
|
137
|
+
for (const to of atOrUnder(arrivals, path)) {
|
|
138
|
+
if (countedOut.has(to))
|
|
139
|
+
continue;
|
|
140
|
+
countedOut.add(to);
|
|
141
|
+
for (const from of cameFrom.get(to)) {
|
|
142
|
+
const left = mayArriveAt.get(from) - 1;
|
|
143
|
+
mayArriveAt.set(from, left);
|
|
144
|
+
if (left === 0)
|
|
145
|
+
refuse(from.path, () => `the run moved what was here to ${wentTo(from).join(", ")}, which did not arrive: it is left as it was`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// What it, or something under it, is one thing with does not arrive without it.
|
|
149
|
+
for (const part of atOrUnder(parts, path))
|
|
150
|
+
without(part, part === path ? "which did not arrive" : `which is under ${path}, which did not arrive`);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
return { settle, heldBack, deedAt };
|
|
154
|
+
}
|
|
155
|
+
/** Where, in a list in order, the first entry is that does not come before a given one. */
|
|
156
|
+
function firstNotBefore(list, given) {
|
|
157
|
+
let low = 0;
|
|
158
|
+
for (let high = list.length; low < high;) {
|
|
159
|
+
const middle = (low + high) >> 1;
|
|
160
|
+
if (list[middle] < given)
|
|
161
|
+
low = middle + 1;
|
|
162
|
+
else
|
|
163
|
+
high = middle;
|
|
164
|
+
}
|
|
165
|
+
return low;
|
|
166
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type Entry, type Tree } from "./tree.js";
|
|
2
|
+
/**
|
|
3
|
+
* What a merge is given: the copy and the real directory, each by its own
|
|
4
|
+
* path; the copy as it was before the run and as the run left it; and the
|
|
5
|
+
* real directory as it was when the copy was made.
|
|
6
|
+
*/
|
|
7
|
+
export interface Given {
|
|
8
|
+
copy: string;
|
|
9
|
+
real: string;
|
|
10
|
+
before: Tree;
|
|
11
|
+
after: Tree;
|
|
12
|
+
seed: Tree;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* What the run changed: the paths, in order and as a set; and what is one
|
|
16
|
+
* thing to the caller, by each path that is a part of such a thing — with
|
|
17
|
+
* those paths, in order.
|
|
18
|
+
*/
|
|
19
|
+
export interface Changes {
|
|
20
|
+
changed: string[];
|
|
21
|
+
isChanged: Set<string>;
|
|
22
|
+
partOf: Map<string, string[][]>;
|
|
23
|
+
parts: string[];
|
|
24
|
+
}
|
|
25
|
+
/** What the run changed, of the copy as it was and as the run left it. It looks at nothing but the two readings. */
|
|
26
|
+
export declare function changesOf(before: Tree, after: Tree, together: string[][]): Changes;
|
|
27
|
+
/**
|
|
28
|
+
* What is told of a merge: what did not arrive, and what there is to say
|
|
29
|
+
* besides. What did not arrive is what the parts go by, too: nothing is done
|
|
30
|
+
* at a path that is left alone.
|
|
31
|
+
*/
|
|
32
|
+
export interface Told {
|
|
33
|
+
refused: Map<string, string>;
|
|
34
|
+
besides: Map<string, string>;
|
|
35
|
+
tell(path: string, what: string): void;
|
|
36
|
+
leftAlone(path: string): boolean;
|
|
37
|
+
underOne(path: string, of: {
|
|
38
|
+
has(path: string): boolean;
|
|
39
|
+
}): boolean;
|
|
40
|
+
}
|
|
41
|
+
/** What is told of a merge, with nothing told yet. */
|
|
42
|
+
export declare function telling(): Told;
|
|
43
|
+
/** What the run left, as the real directory is to have it — and whether a place has it already. */
|
|
44
|
+
export interface Left {
|
|
45
|
+
stagedFile(path: string): string;
|
|
46
|
+
wanted(path: string, is: Entry): Entry;
|
|
47
|
+
holdsBytes(there: Entry, place: string, want: Entry & {
|
|
48
|
+
kind: "file";
|
|
49
|
+
}, path: string): boolean;
|
|
50
|
+
holds(there: Entry | undefined, place: string, want: Entry, path: string): boolean;
|
|
51
|
+
}
|
|
52
|
+
/** What the run left in a copy. (A file of the copy that may not be read is made readable when it is asked for.) */
|
|
53
|
+
export declare function leftBy({ copy, real, after }: Pick<Given, "copy" | "real" | "after">): Left;
|
|
54
|
+
/** The directories of the real one that a merge opens, and what each is to be left allowing. */
|
|
55
|
+
export interface Opened {
|
|
56
|
+
open(dir: string): void;
|
|
57
|
+
toClose: Map<string, {
|
|
58
|
+
id: string | undefined;
|
|
59
|
+
mode: number;
|
|
60
|
+
has: number;
|
|
61
|
+
}>;
|
|
62
|
+
}
|
|
63
|
+
/** The directories of a real directory that are opened, with none opened yet. */
|
|
64
|
+
export declare function opening(real: string): Opened;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// What a merge is given, and what its parts have between them (see merge.ts).
|
|
2
|
+
//
|
|
3
|
+
// The parts are the finding out, the following up and the doing. Each has
|
|
4
|
+
// much that is its own, and that is kept in it. What more than one of them
|
|
5
|
+
// needs is here, and it is four things: what the run changed, which is asked
|
|
6
|
+
// of the two readings of the copy and of nothing else; what is told of the
|
|
7
|
+
// merge, which every part adds to; what the run left, as it is to be in the
|
|
8
|
+
// real directory; and the directories of the real one that are opened. Each
|
|
9
|
+
// is made once, by mergeTree, and given to the parts that need it.
|
|
10
|
+
import { chmodSync } from "fs";
|
|
11
|
+
import { dirname, join } from "path";
|
|
12
|
+
import { linksOf } from "./path-guard.js";
|
|
13
|
+
import { ITSELF, addTo, entryAt, idOf, inOrder, same, sameBytes } from "./tree.js";
|
|
14
|
+
/** What the run changed, of the copy as it was and as the run left it. It looks at nothing but the two readings. */
|
|
15
|
+
export function changesOf(before, after, together) {
|
|
16
|
+
/**
|
|
17
|
+
* Whether what is at a path, though it looks the same, is something the run
|
|
18
|
+
* moved there from another place. (Something new that looks the same is no
|
|
19
|
+
* change: nothing depends on its being there.)
|
|
20
|
+
*/
|
|
21
|
+
const wasSomewhere = new Set([...before.values()].map(idOf));
|
|
22
|
+
const movedHere = (path) => {
|
|
23
|
+
const id = idOf(after.get(path));
|
|
24
|
+
return id !== undefined && id !== idOf(before.get(path)) && wasSomewhere.has(id);
|
|
25
|
+
};
|
|
26
|
+
// Sorted, a path comes before every path under it.
|
|
27
|
+
const changed = [...new Set([...before.keys(), ...after.keys()])]
|
|
28
|
+
.filter((path) => !same(before.get(path), after.get(path)) || movedHere(path))
|
|
29
|
+
.sort(inOrder);
|
|
30
|
+
const isChanged = new Set(changed);
|
|
31
|
+
/**
|
|
32
|
+
* What is one thing to the caller (see `together`), as paths: by each path
|
|
33
|
+
* where the copy has a part of such a thing — had it before the run, or has
|
|
34
|
+
* it now — the things it is a part of, each as all its paths.
|
|
35
|
+
*/
|
|
36
|
+
const partOf = new Map();
|
|
37
|
+
if (together.length > 0) {
|
|
38
|
+
const where = new Map();
|
|
39
|
+
for (const tree of [before, after]) {
|
|
40
|
+
for (const [path, entry] of tree) {
|
|
41
|
+
const id = idOf(entry);
|
|
42
|
+
if (id === undefined)
|
|
43
|
+
continue;
|
|
44
|
+
const those = where.get(id);
|
|
45
|
+
if (those)
|
|
46
|
+
those.add(path);
|
|
47
|
+
else
|
|
48
|
+
where.set(id, new Set([path]));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const ids of together) {
|
|
52
|
+
const paths = [...new Set(ids.flatMap((id) => [...(where.get(id) ?? [])]))];
|
|
53
|
+
for (const part of paths)
|
|
54
|
+
addTo(partOf, part, paths);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const parts = [...partOf.keys()].sort();
|
|
58
|
+
return { changed, isChanged, partOf, parts };
|
|
59
|
+
}
|
|
60
|
+
/** What is told of a merge, with nothing told yet. */
|
|
61
|
+
export function telling() {
|
|
62
|
+
/** What did not arrive, and why: found out beforehand, or — once things are being done — told by the system. */
|
|
63
|
+
const refused = new Map();
|
|
64
|
+
/** Whether a path is under one of some paths. */
|
|
65
|
+
const underOne = (path, of) => {
|
|
66
|
+
for (let end = path.lastIndexOf("/"); end !== -1; end = path.lastIndexOf("/", end - 1)) {
|
|
67
|
+
if (of.has(path.slice(0, end)))
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
return path !== ITSELF && of.has(ITSELF);
|
|
71
|
+
};
|
|
72
|
+
/** Whether a path is one of those that did not arrive, or under one. */
|
|
73
|
+
const leftAlone = (path) => refused.has(path) || underOne(path, refused);
|
|
74
|
+
/** What there is to say besides what did not arrive (see above): by the path, what. */
|
|
75
|
+
const besides = new Map();
|
|
76
|
+
const tell = (path, what) => besides.set(path, besides.has(path) ? `${besides.get(path)} — and ${what}` : what);
|
|
77
|
+
return { refused, besides, tell, leftAlone, underOne };
|
|
78
|
+
}
|
|
79
|
+
/** What the run left in a copy. (A file of the copy that may not be read is made readable when it is asked for.) */
|
|
80
|
+
export function leftBy({ copy, real, after }) {
|
|
81
|
+
const said = linksOf(copy);
|
|
82
|
+
/** What a link the run left at a path says in the real directory. */
|
|
83
|
+
const inReal = (path, text) => {
|
|
84
|
+
const rest = said.sinceRoot(join(copy, dirname(path)), text);
|
|
85
|
+
return rest === undefined ? text : real + rest;
|
|
86
|
+
};
|
|
87
|
+
/** The file the run left at a path. One it left unreadable is read all the same. */
|
|
88
|
+
const stagedFile = (path) => {
|
|
89
|
+
const staged = join(copy, path);
|
|
90
|
+
const left = after.get(path);
|
|
91
|
+
if (left?.kind === "file" && (left.mode & 0o400) === 0)
|
|
92
|
+
chmodSync(staged, left.mode | 0o400);
|
|
93
|
+
return staged;
|
|
94
|
+
};
|
|
95
|
+
/** What the run left at a path, as it is to be in the real directory — refused if it is nothing that can be put there. */
|
|
96
|
+
const wanted = (path, is) => {
|
|
97
|
+
if (is.kind === "other") {
|
|
98
|
+
throw new Error("the run left there what is not content — a pipe, a socket, a device, a link whose words are not text — and it is not carried into the project");
|
|
99
|
+
}
|
|
100
|
+
return is.kind === "link" ? { ...is, text: inReal(path, is.text) } : is;
|
|
101
|
+
};
|
|
102
|
+
/** Whether a file of the real directory holds what the file the run left at a path holds. One that may not be read is not known to. */
|
|
103
|
+
const sameAlready = new Map();
|
|
104
|
+
const holdsBytes = (there, place, want, path) => {
|
|
105
|
+
if (there.kind !== "file" || there.size !== want.size)
|
|
106
|
+
return false;
|
|
107
|
+
let known = sameAlready.get(path);
|
|
108
|
+
if (known === undefined) {
|
|
109
|
+
try {
|
|
110
|
+
known = sameBytes(stagedFile(path), place);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
known = false;
|
|
114
|
+
}
|
|
115
|
+
sameAlready.set(path, known);
|
|
116
|
+
}
|
|
117
|
+
return known;
|
|
118
|
+
};
|
|
119
|
+
/** Whether a place already holds what is wanted at a path. */
|
|
120
|
+
const holds = (there, place, want, path) => {
|
|
121
|
+
if (want.kind === "file")
|
|
122
|
+
return there?.kind === "file" && there.mode === want.mode && holdsBytes(there, place, want, path);
|
|
123
|
+
if (want.kind === "dir")
|
|
124
|
+
return there?.kind === "dir" && there.mode === want.mode;
|
|
125
|
+
return want.kind === "link" && there?.kind === "link" && there.text === want.text;
|
|
126
|
+
};
|
|
127
|
+
return { stagedFile, wanted, holdsBytes, holds };
|
|
128
|
+
}
|
|
129
|
+
/** The directories of a real directory that are opened, with none opened yet. */
|
|
130
|
+
export function opening(real) {
|
|
131
|
+
/**
|
|
132
|
+
* Directories of the real one opened to be looked into or changed, and
|
|
133
|
+
* those this merge makes: what each is to be left allowing — what it
|
|
134
|
+
* allowed, until what the run left it allowing arrives.
|
|
135
|
+
*/
|
|
136
|
+
const opened = new Set();
|
|
137
|
+
/**
|
|
138
|
+
* Each with which directory it is, what it is to be left allowing, and what
|
|
139
|
+
* this merge has it allowing for now (-1: not known — it was made, and
|
|
140
|
+
* could not then be given what it was to allow while it is filled).
|
|
141
|
+
*/
|
|
142
|
+
const toClose = new Map();
|
|
143
|
+
const open = (dir) => {
|
|
144
|
+
if (opened.has(dir))
|
|
145
|
+
return;
|
|
146
|
+
const place = join(real, dir);
|
|
147
|
+
const there = entryAt(place);
|
|
148
|
+
if (there?.kind === "dir") {
|
|
149
|
+
const closing = { id: there.id, mode: there.mode, has: there.mode };
|
|
150
|
+
toClose.set(dir, closing);
|
|
151
|
+
if ((there.mode | 0o700) !== there.mode) {
|
|
152
|
+
chmodSync(place, there.mode | 0o700);
|
|
153
|
+
closing.has = there.mode | 0o700;
|
|
154
|
+
}
|
|
155
|
+
} // (if it is no directory, what is done in it will say so)
|
|
156
|
+
opened.add(dir); // only now: if it could not be opened, the next to need it open is told so too
|
|
157
|
+
};
|
|
158
|
+
return { open, toClose };
|
|
159
|
+
}
|
package/dist/merge.d.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { type Tree } from "./tree.js";
|
|
2
|
+
/** Something a run did in a copy that did not reach the real directory, and why. */
|
|
3
|
+
export interface Unmerged {
|
|
4
|
+
path: string;
|
|
5
|
+
why: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Carry what a run did to a copy back into the directory it is a copy of.
|
|
9
|
+
*
|
|
10
|
+
* @param stagedDir - the copy, as the run left it
|
|
11
|
+
* @param realDir - the directory it was copied from
|
|
12
|
+
* @param before - the copy as it was before the run (readTree)
|
|
13
|
+
* @param seed - the real directory as it was when the copy was made (copyTree)
|
|
14
|
+
* @param together - things that are one thing to the caller: each list the
|
|
15
|
+
* `id`s (see Entry) of the files, links and directories that are one
|
|
16
|
+
*
|
|
17
|
+
* What the run did is where the copy differs from what it was: a file, a
|
|
18
|
+
* directory or a link made, removed, changed, or put where something of
|
|
19
|
+
* another kind was; permissions changed — those of the directory itself
|
|
20
|
+
* among them, which is a directory like any in it: only that it is neither
|
|
21
|
+
* made nor removed. Each difference is carried over on
|
|
22
|
+
* one condition: the place in the real directory is still as it was when the
|
|
23
|
+
* copy was made — and so is the directory it is in. If not, somebody else —
|
|
24
|
+
* the user, another run of the same project — has been there since, and
|
|
25
|
+
* theirs is kept. A place that already holds what the run left needs nothing
|
|
26
|
+
* done, whoever made it so.
|
|
27
|
+
*
|
|
28
|
+
* There is no path this leaves out. Where the caller has itself put
|
|
29
|
+
* something into the real directory since the copy was made, it says so in
|
|
30
|
+
* `seed`: the place is then as the seed has it, and what the run did there is
|
|
31
|
+
* carried over like anything else.
|
|
32
|
+
*
|
|
33
|
+
* All of that is found out before anything is done. What cannot arrive is
|
|
34
|
+
* then left alone, with everything under it; and a directory the run removed,
|
|
35
|
+
* or put something else in the place of, goes only if all that is in it goes
|
|
36
|
+
* — if anything in it stays, or it holds something the run never saw, the
|
|
37
|
+
* directory stays whole. What the run moved — a file, a link, a directory —
|
|
38
|
+
* goes from where it was only if it arrives where the run moved it: what it
|
|
39
|
+
* holds is not to be in neither place. (What was moved is known by its `id`,
|
|
40
|
+
* see Entry. What the run copied and then removed is a new file, and is not
|
|
41
|
+
* known to be the old one's.) And what the caller says is one thing — a
|
|
42
|
+
* link, say, with the file that makes it lead somewhere: the things in one
|
|
43
|
+
* list of `together`, each known by what it is, at every path where the copy
|
|
44
|
+
* had it before the run or has it now — arrives together or not at all: if
|
|
45
|
+
* one of those paths is left alone, nothing is done at any of them. A part
|
|
46
|
+
* the run left as it was has nothing to arrive, but the rest leans on it: if
|
|
47
|
+
* it is not, in the project, as it was when the copy was made, that is told
|
|
48
|
+
* of it, and the rest does not arrive. (So that all this holds where the
|
|
49
|
+
* system refuses in the doing, what is done at such a path is only what can
|
|
50
|
+
* be taken back: a file there is not written into but has the new one put in
|
|
51
|
+
* its place, and what is to go from there is moved aside first, as what is
|
|
52
|
+
* taken the place of is. A directory among them that stays a directory is
|
|
53
|
+
* not left alone with the rest — what else the run did in it could not be
|
|
54
|
+
* taken for undone with it — but what it was to be left allowing does not
|
|
55
|
+
* arrive either, and that is told of it. And a part the run left as it was,
|
|
56
|
+
* and that is not so in the project, is told of besides, as that: nothing
|
|
57
|
+
* under it is left alone for it — and nothing is told of it where nothing is
|
|
58
|
+
* held back for it.) So what is returned as not arrived is as it
|
|
59
|
+
* was, at that path and under it. That holds where the system refuses, in
|
|
60
|
+
* the doing, what had been found possible — see how it is done, below — as
|
|
61
|
+
* long as it does not also refuse to put back what was moved aside; then
|
|
62
|
+
* the report says where that is.
|
|
63
|
+
*
|
|
64
|
+
* Some things are told of besides, which are not that. What was moved aside
|
|
65
|
+
* to go, or made ready and not needed, and which the system will not have
|
|
66
|
+
* removed, is told of at the name it is left under — a path that is none of
|
|
67
|
+
* the run's. A directory the run removed which the system will not remove,
|
|
68
|
+
* or not with all that was in it, holds what is left, as it would had the
|
|
69
|
+
* run removed it there, and is told of so. A directory or a file that could
|
|
70
|
+
* not be given, at the end, what it is to allow is told of for that: what
|
|
71
|
+
* it holds has arrived, unless that is told of itself. A file that could not
|
|
72
|
+
* be written into, and had a new one put in its place, is told of for that.
|
|
73
|
+
* (If the system will not have the new one put there either, the file did
|
|
74
|
+
* not arrive, and the report says that what it held may be damaged, and
|
|
75
|
+
* where what it was to hold is.)
|
|
76
|
+
*
|
|
77
|
+
* Finding out is looking, and a directory that is closed cannot be looked
|
|
78
|
+
* into. One of the real directory's — or the directory itself — is opened
|
|
79
|
+
* for it, as it is for what is then done in it, and one of the copy's is
|
|
80
|
+
* opened to be read: both are this merge's to open. Each is left, at the end,
|
|
81
|
+
* allowing what the run left it allowing — or, if that did not arrive, what
|
|
82
|
+
* it allowed. (One that somebody else gave other permissions since the copy
|
|
83
|
+
* was made is theirs, and is not opened: nothing is made or removed in it.)
|
|
84
|
+
*
|
|
85
|
+
* A path is a name, and the real directory has the last word on its names:
|
|
86
|
+
* its file system may take "Notes.txt" and "notes.txt" for one. A path of
|
|
87
|
+
* the tree whose place holds something, though the directory does not list
|
|
88
|
+
* the name as the tree spells it, is such a second spelling — the run
|
|
89
|
+
* spelled a name anew, or made one beside another on a file system that
|
|
90
|
+
* tells them apart. To a tree that is one entry removed and another made; in
|
|
91
|
+
* the real directory the two are one place, and removing the one would
|
|
92
|
+
* remove the other. Neither is touched: nothing is done to what is there
|
|
93
|
+
* under any name the run changed, and each is told of as not arrived. (What
|
|
94
|
+
* is there is known by what it is. All the names of a file that has several
|
|
95
|
+
* are therefore left, where one would have done.) If what is there is a
|
|
96
|
+
* directory, nothing is done in it either: a path through it is a path
|
|
97
|
+
* through the other, and what the run left under the two names is in one
|
|
98
|
+
* place. And two names the run made where nothing was, which the directory
|
|
99
|
+
* turns out to take for one when the second is put there: neither is put.
|
|
100
|
+
* (That can only be seen in the putting. If the first was not put, for a
|
|
101
|
+
* reason of its own, the second is — and what is told of the first is then
|
|
102
|
+
* true of the name as the run spelled it, not as the directory takes it.)
|
|
103
|
+
* The same is asked of the way to a path: a directory on it that the real
|
|
104
|
+
* one no longer lists as the tree spells it — somebody spelled it anew — is
|
|
105
|
+
* not the tree's directory any more, and nothing is done in it.
|
|
106
|
+
*
|
|
107
|
+
* What is to be done is done so that nothing is lost by its being done in
|
|
108
|
+
* part. A file or a link that is to be where something is, is made beside
|
|
109
|
+
* the place first. Then what the run made is made, a directory before what
|
|
110
|
+
* goes in it. What is in the place of it is not removed but moved aside,
|
|
111
|
+
* under a name of its own beside the place, and what was made beside the
|
|
112
|
+
* place is moved in. (Only a directory that stays a directory, and a file
|
|
113
|
+
* the run wrote into that can be written into, stay and are changed where
|
|
114
|
+
* they are. A file that is written into has what it is to hold made beside
|
|
115
|
+
* it first all the same: if the system will not have the writing — which it
|
|
116
|
+
* may have begun — that takes its place.) Where the system will not have a thing done, that
|
|
117
|
+
* thing is left alone like what was found impossible beforehand, with what
|
|
118
|
+
* follows from it — and what follows may be that something already done is
|
|
119
|
+
* not to stand: what the run moved from there did not arrive where it went.
|
|
120
|
+
* Then what was put there is removed again, and what was moved aside comes
|
|
121
|
+
* back. Only when all that is settled does what was moved aside go for good,
|
|
122
|
+
* and what the run removed, where it is. (A runner that is stopped in the
|
|
123
|
+
* middle leaves what it had moved aside, or made ready, where it is: under
|
|
124
|
+
* names that begin with .trama-tmp-.) It is where the run ended that is
|
|
125
|
+
* carried over, not the steps by which it got there.
|
|
126
|
+
*
|
|
127
|
+
* A file the run wrote into is written into, if it may be, and stays the
|
|
128
|
+
* file it is — as does one that holds what the run left already, and has
|
|
129
|
+
* only what it allows changed. Where the run put another file in the place,
|
|
130
|
+
* or the file may not be written into, or the system will not have it
|
|
131
|
+
* written into after all, a new one is put in its place — and then a second
|
|
132
|
+
* name of the old file is none of the new one, and holds whatever the
|
|
133
|
+
* writing left. A link is written as the run wrote it
|
|
134
|
+
* — the run took its copy for the directory itself — unless its way comes to
|
|
135
|
+
* the copy from outside: by the copy's full path, or out of the copy and
|
|
136
|
+
* back in by its name. What such a link says from there on is said of the
|
|
137
|
+
* real directory, wherever that leads from there. So a link the copy
|
|
138
|
+
* was given in other words than the directory's own (see copyTree), if the
|
|
139
|
+
* run moved it, is merged in those words: it names what the run found it to
|
|
140
|
+
* name, which is not always what the directory's own words would name from
|
|
141
|
+
* the new place. And a link the run made that climbs out of its directory
|
|
142
|
+
* with ".." and does not come back says the same in the real directory, and
|
|
143
|
+
* names from there what it names from there.
|
|
144
|
+
*
|
|
145
|
+
* Nothing is thrown. What could not be carried over is returned, each path
|
|
146
|
+
* with the reason, so that a run whose work did not all arrive is not passed
|
|
147
|
+
* off as one whose work did. Under a path that did not arrive, what was not
|
|
148
|
+
* looked at for that reason is not listed: it is as it was, with the path.
|
|
149
|
+
*/
|
|
150
|
+
export declare function mergeTree(stagedDir: string, realDir: string, before: Tree, seed: Tree, together?: string[][]): Unmerged[];
|