@amalgm/shell 0.1.164-main.41592210691 → 0.1.164-main.41637822660
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/apply-displaced-tree.d.ts +63 -0
- package/dist/apply-displaced-tree.js +148 -0
- package/dist/apply-displaced-tree.js.map +1 -0
- package/dist/apply-fingerprint.d.ts +39 -0
- package/dist/apply-fingerprint.js +84 -0
- package/dist/apply-fingerprint.js.map +1 -0
- package/dist/apply-git-storage.d.ts +18 -8
- package/dist/apply-git-storage.js +44 -50
- package/dist/apply-git-storage.js.map +1 -1
- package/dist/apply-kept.d.ts +10 -0
- package/dist/apply-kept.js +34 -19
- package/dist/apply-kept.js.map +1 -1
- package/dist/apply-showing.d.ts +11 -5
- package/dist/apply-showing.js +38 -6
- package/dist/apply-showing.js.map +1 -1
- package/dist/apply-window-ground.d.ts +3 -1
- package/dist/apply-window-ground.js +5 -2
- package/dist/apply-window-ground.js.map +1 -1
- package/dist/apply-window-host.d.ts +4 -1
- package/dist/apply-window-host.js +210 -110
- package/dist/apply-window-host.js.map +1 -1
- package/dist/apply-window-recovery.js +3 -2
- package/dist/apply-window-recovery.js.map +1 -1
- package/dist/apply-window-reveal.d.ts +9 -3
- package/dist/apply-window-reveal.js +33 -16
- package/dist/apply-window-reveal.js.map +1 -1
- package/dist/apply-window-rows.d.ts +4 -0
- package/dist/apply-window-rows.js +1 -1
- package/dist/apply-window-rows.js.map +1 -1
- package/dist/cli.js +17 -11
- package/dist/cli.js.map +1 -1
- package/dist/content-clock.d.ts +5 -2
- package/dist/content-clock.js +10 -5
- package/dist/content-clock.js.map +1 -1
- package/dist/drive/computer.d.ts +17 -0
- package/dist/drive/computer.js +50 -0
- package/dist/drive/computer.js.map +1 -0
- package/dist/drive/mount.d.ts +3 -3
- package/dist/drive/mount.js +1 -1
- package/dist/drive/mount.js.map +1 -1
- package/dist/drive/nfs/apple-double.js +1 -0
- package/dist/drive/nfs/apple-double.js.map +1 -1
- package/dist/drive/nfs/nfs3.js +7 -2
- package/dist/drive/nfs/nfs3.js.map +1 -1
- package/dist/drive/operations.d.ts +8 -3
- package/dist/drive/operations.js +20 -11
- package/dist/drive/operations.js.map +1 -1
- package/dist/machine-host.d.ts +2 -1
- package/dist/machine-host.js.map +1 -1
- package/examinations/native-service.mjs +29 -4
- package/npm-shrinkwrap.json +6 -6
- package/package.json +5 -5
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type FingerprintClock, type FingerprintOptions } from "./apply-fingerprint.js";
|
|
2
|
+
import { type Remainder } from "./apply-kept.js";
|
|
3
|
+
import type { ContentStamp } from "./content-clock.js";
|
|
4
|
+
import type { GroundRow } from "./ground-row.js";
|
|
5
|
+
export interface DisplacedTreeManifest {
|
|
6
|
+
readonly contract: "amalgm.apply-displaced-tree@2";
|
|
7
|
+
/** The clock the fingerprint was taken under. */
|
|
8
|
+
readonly clock: FingerprintClock | null;
|
|
9
|
+
/** Every name beneath the directory but `aside` (apply-fingerprint.ts). */
|
|
10
|
+
readonly digest: string;
|
|
11
|
+
/** What a matching Verify keeps rather than lets go: the topmost local
|
|
12
|
+
* remainder and each computer-only directory, with the shared container
|
|
13
|
+
* it belongs to. */
|
|
14
|
+
readonly aside: readonly Remainder[];
|
|
15
|
+
}
|
|
16
|
+
export type DisplacedTreeProof = {
|
|
17
|
+
readonly kind: "proved";
|
|
18
|
+
readonly manifest: DisplacedTreeManifest;
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: "differs";
|
|
21
|
+
readonly reason: string;
|
|
22
|
+
};
|
|
23
|
+
type Reads = Pick<FingerprintOptions, "onRead" | "onBytes">;
|
|
24
|
+
/**
|
|
25
|
+
* Proves the directory at `source`, O's `owner`, holds exactly O's `rows`
|
|
26
|
+
* beneath it, and takes its manifest under `stamp`, the clock stamped before
|
|
27
|
+
* the walk. `aside` is its topmost local remainder; `shows` reads whether a
|
|
28
|
+
* leaf, link, reference or repository stands as its O row says.
|
|
29
|
+
*/
|
|
30
|
+
export declare function proveDisplacedTree(input: {
|
|
31
|
+
readonly source: string;
|
|
32
|
+
readonly owner: string;
|
|
33
|
+
readonly rows: readonly GroundRow[];
|
|
34
|
+
readonly aside: readonly Remainder[];
|
|
35
|
+
readonly stamp: ContentStamp;
|
|
36
|
+
readonly shows: (row: GroundRow, path: string) => Promise<boolean>;
|
|
37
|
+
} & Reads): Promise<DisplacedTreeProof>;
|
|
38
|
+
/** Whether the copy at `displaced`, taken from `source`, still holds every
|
|
39
|
+
* name its manifest signed, read under the clock it was signed under, whose
|
|
40
|
+
* qualification the caller proves still stands. Nothing displaced has
|
|
41
|
+
* nothing to lose. */
|
|
42
|
+
export declare function displacedTreeShows(displaced: string, source: string, manifest: DisplacedTreeManifest, reads?: Reads): Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* Brings a source its member set aside home: to `home` when nothing stands
|
|
45
|
+
* there and `homeFree` holds, since the member's own reveal no longer holds
|
|
46
|
+
* it. Otherwise a person's object holds its home, and each name beneath a
|
|
47
|
+
* directory is kept for `owner`, the container it was (apply-kept.ts); a
|
|
48
|
+
* file or link set aside is O, which its final guard proved, and goes with
|
|
49
|
+
* the window. Names the directories owed a flush, and whether anything was
|
|
50
|
+
* kept; nothing displaced has nothing to bring.
|
|
51
|
+
*/
|
|
52
|
+
export declare function bringDisplacedHome(input: {
|
|
53
|
+
readonly displaced: string;
|
|
54
|
+
readonly home: string;
|
|
55
|
+
readonly homeFree: boolean;
|
|
56
|
+
readonly root: string;
|
|
57
|
+
readonly owner: string;
|
|
58
|
+
readonly attemptId: string;
|
|
59
|
+
}): {
|
|
60
|
+
readonly flush: readonly string[];
|
|
61
|
+
readonly kept: boolean;
|
|
62
|
+
};
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/** The directory a received result displaces whole: a Leave's container, or
|
|
2
|
+
* a container a leaf, link or reference replaces. It moves aside into its
|
|
3
|
+
* window's control tree and goes only at the durability point, so Apply
|
|
4
|
+
* deletes nothing beneath it that a person wrote.
|
|
5
|
+
*
|
|
6
|
+
* - The final guard stamps its root's content clock, then walks every name
|
|
7
|
+
* beneath it by Detect's walk law (src/detection/root-examination.ts) and
|
|
8
|
+
* proves each is O: a name O does not hold, a row O holds that stands
|
|
9
|
+
* nowhere, a parent, type or object that differs, or a leaf, link,
|
|
10
|
+
* reference or repository whose ground shows another result is a person's
|
|
11
|
+
* change, which Detect records before Apply looks again.
|
|
12
|
+
* - The same walk takes the tree's fingerprint (apply-fingerprint.ts), which
|
|
13
|
+
* the receipt binds before any effect. Each name joins it before its
|
|
14
|
+
* ground is read, so a write after that read differs from it.
|
|
15
|
+
* - The reveal only takes the directory aside. Its member's Verify takes the
|
|
16
|
+
* copy's fingerprint again before it judges anything else, and the copy
|
|
17
|
+
* goes only when that member's Verify matches. Every other answer brings
|
|
18
|
+
* it home first (bringDisplacedHome), so Verify's next read finds the
|
|
19
|
+
* person's version, which Detect records as the newest result.
|
|
20
|
+
* - Local remainder (apply-kept.ts) and each computer-only `.amalgm` or
|
|
21
|
+
* `.private` beneath it are set aside: the walk neither compares nor
|
|
22
|
+
* digests them, and only a matching Verify keeps them.
|
|
23
|
+
*
|
|
24
|
+
* Residuals: a writer holding a file open, or a shell whose working
|
|
25
|
+
* directory is inside the copy, can still write after Verify's read and
|
|
26
|
+
* before the durability point. A root that leaves between the reveal and
|
|
27
|
+
* Verify keeps the copy in its own control tree, which nothing reads until
|
|
28
|
+
* the root returns. */
|
|
29
|
+
import { basename, dirname, join, relative } from "node:path";
|
|
30
|
+
import { isLocalOnlyPath } from "@amalgm/core/identity";
|
|
31
|
+
import { classifyDirectory, CONTAINERS, isRepositoryMetadataEntry } from "@amalgm/live";
|
|
32
|
+
import { clockBoundary, fingerprintClock, fingerprintTree } from "./apply-fingerprint.js";
|
|
33
|
+
import { keepAside } from "./apply-kept.js";
|
|
34
|
+
import { moveWithoutReplacing } from "./apply-spelling.js";
|
|
35
|
+
import { listAgain, railChanged } from "./detection/walk-law.js";
|
|
36
|
+
import { marksRepository, observeGitMarker } from "./git/marker.js";
|
|
37
|
+
import { optionalLstat } from "./physical-path-witness.js";
|
|
38
|
+
import { physicalKey } from "./source-signature.js";
|
|
39
|
+
/**
|
|
40
|
+
* Proves the directory at `source`, O's `owner`, holds exactly O's `rows`
|
|
41
|
+
* beneath it, and takes its manifest under `stamp`, the clock stamped before
|
|
42
|
+
* the walk. `aside` is its topmost local remainder; `shows` reads whether a
|
|
43
|
+
* leaf, link, reference or repository stands as its O row says.
|
|
44
|
+
*/
|
|
45
|
+
export async function proveDisplacedTree(input) {
|
|
46
|
+
const aside = [...input.aside];
|
|
47
|
+
const skipped = new Set(aside.map(({ path }) => relative(input.source, path)));
|
|
48
|
+
const byPath = new Map(input.rows.map(row => [row.absolutePath, row]));
|
|
49
|
+
const reached = new Set();
|
|
50
|
+
// The O container each walked directory is; Git's own storage beneath a
|
|
51
|
+
// repository is digested but never compared.
|
|
52
|
+
const owners = new Map([[input.source, input.owner]]);
|
|
53
|
+
const skips = (relativePath, parent) => {
|
|
54
|
+
if (skipped.has(relativePath))
|
|
55
|
+
return true;
|
|
56
|
+
const owner = owners.get(parent);
|
|
57
|
+
if (!owner || !isLocalOnlyPath(basename(relativePath)))
|
|
58
|
+
return false;
|
|
59
|
+
aside.push({ owner, path: join(input.source, relativePath) });
|
|
60
|
+
skipped.add(relativePath);
|
|
61
|
+
return true;
|
|
62
|
+
};
|
|
63
|
+
const clock = fingerprintClock(input.stamp);
|
|
64
|
+
const walked = await fingerprintTree(input.source, { clock: clockBoundary(clock), skips, onRead: input.onRead,
|
|
65
|
+
onBytes: input.onBytes, visit: async ({ path, parent, stats }) => {
|
|
66
|
+
const owner = owners.get(parent);
|
|
67
|
+
if (!owner || isRepositoryMetadataEntry(basename(path))) {
|
|
68
|
+
if (stats.isDirectory())
|
|
69
|
+
owners.set(path, null);
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const supported = stats.isDirectory() || stats.isFile() || stats.isSymbolicLink();
|
|
73
|
+
const row = byPath.get(path);
|
|
74
|
+
if (!row)
|
|
75
|
+
return supported ? `${path} is a name O does not hold` : null;
|
|
76
|
+
if (row.parentUUID !== owner)
|
|
77
|
+
return `${path} stands under another parent`;
|
|
78
|
+
if (!supported)
|
|
79
|
+
return `${path} is no longer a file, folder or link`;
|
|
80
|
+
const type = stats.isDirectory() ? classifyDirectory({ repository: marksRepository(observeGitMarker(path)) }) : row.type;
|
|
81
|
+
if (railChanged(row.type, type))
|
|
82
|
+
return `${path} changed type`;
|
|
83
|
+
reached.add(row.uuid);
|
|
84
|
+
if (stats.isDirectory() && CONTAINERS.has(row.type)) {
|
|
85
|
+
if (physicalKey(stats) !== row.physicalKey)
|
|
86
|
+
return `${path} is another directory`;
|
|
87
|
+
if (row.type === "repo.git" && !await input.shows(row, path))
|
|
88
|
+
return `${path} shows another repository state`;
|
|
89
|
+
owners.set(path, row.uuid);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
return await input.shows(row, path) ? null : `${path} shows another result`;
|
|
93
|
+
} });
|
|
94
|
+
if ("differs" in walked)
|
|
95
|
+
return { kind: "differs", reason: walked.differs };
|
|
96
|
+
const kept = (path) => {
|
|
97
|
+
for (let at = relative(input.source, path); at !== "." && at !== ""; at = dirname(at))
|
|
98
|
+
if (skipped.has(at))
|
|
99
|
+
return true;
|
|
100
|
+
return false;
|
|
101
|
+
};
|
|
102
|
+
const absent = input.rows.find(row => !reached.has(row.uuid) && !kept(row.absolutePath));
|
|
103
|
+
if (absent)
|
|
104
|
+
return { kind: "differs", reason: `${absent.absolutePath} is gone` };
|
|
105
|
+
return { kind: "proved", manifest: { contract: "amalgm.apply-displaced-tree@2", clock, digest: walked.digest, aside } };
|
|
106
|
+
}
|
|
107
|
+
/** Whether the copy at `displaced`, taken from `source`, still holds every
|
|
108
|
+
* name its manifest signed, read under the clock it was signed under, whose
|
|
109
|
+
* qualification the caller proves still stands. Nothing displaced has
|
|
110
|
+
* nothing to lose. */
|
|
111
|
+
export async function displacedTreeShows(displaced, source, manifest, reads = {}) {
|
|
112
|
+
// A manifest of another contract proves nothing.
|
|
113
|
+
if (manifest.contract !== "amalgm.apply-displaced-tree@2")
|
|
114
|
+
return false;
|
|
115
|
+
if (!optionalLstat(displaced)?.isDirectory())
|
|
116
|
+
return true;
|
|
117
|
+
const skipped = new Set(manifest.aside.map(({ path }) => relative(source, path)));
|
|
118
|
+
const walked = await fingerprintTree(displaced, { clock: clockBoundary(manifest.clock),
|
|
119
|
+
skips: relativePath => skipped.has(relativePath), ...reads });
|
|
120
|
+
return "digest" in walked && walked.digest === manifest.digest;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Brings a source its member set aside home: to `home` when nothing stands
|
|
124
|
+
* there and `homeFree` holds, since the member's own reveal no longer holds
|
|
125
|
+
* it. Otherwise a person's object holds its home, and each name beneath a
|
|
126
|
+
* directory is kept for `owner`, the container it was (apply-kept.ts); a
|
|
127
|
+
* file or link set aside is O, which its final guard proved, and goes with
|
|
128
|
+
* the window. Names the directories owed a flush, and whether anything was
|
|
129
|
+
* kept; nothing displaced has nothing to bring.
|
|
130
|
+
*/
|
|
131
|
+
export function bringDisplacedHome(input) {
|
|
132
|
+
const stats = optionalLstat(input.displaced);
|
|
133
|
+
if (!stats)
|
|
134
|
+
return { flush: [], kept: false };
|
|
135
|
+
if (input.homeFree && moveWithoutReplacing(input.displaced, input.home)) {
|
|
136
|
+
return { flush: [dirname(input.displaced), dirname(input.home)], kept: false };
|
|
137
|
+
}
|
|
138
|
+
if (!stats.isDirectory())
|
|
139
|
+
return { flush: [], kept: false };
|
|
140
|
+
const flush = new Set();
|
|
141
|
+
for (const name of listAgain(input.displaced) ?? []) {
|
|
142
|
+
for (const directory of keepAside({ root: input.root, attemptId: input.attemptId, owner: input.owner,
|
|
143
|
+
from: join(input.displaced, name), name }))
|
|
144
|
+
flush.add(directory);
|
|
145
|
+
}
|
|
146
|
+
return { flush: [...flush], kept: true };
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=apply-displaced-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-displaced-tree.js","sourceRoot":"","sources":["../src/apply-displaced-tree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;uBA2BuB;AACvB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAC9B,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAkB,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAoBpD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,KAOhC;IACP,MAAM,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/E,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,C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CAAC;QACxE,OAAO,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACjF,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;QAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAC5D,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;QACpD,KAAK,MAAM,SAAS,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK;YAClG,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;YAAE,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type BigIntStats } from "node:fs";
|
|
2
|
+
import { type ContentBoundary, type ContentStamp } from "./content-clock.js";
|
|
3
|
+
export interface TreeEntry {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly parent: string;
|
|
6
|
+
readonly stats: BigIntStats;
|
|
7
|
+
}
|
|
8
|
+
export interface FingerprintOptions {
|
|
9
|
+
/** The clock stamped before the first walk; null proves no leaf. */
|
|
10
|
+
readonly clock: ContentBoundary | null;
|
|
11
|
+
/** Names neither digested nor descended into. */
|
|
12
|
+
readonly skips?: (relativePath: string, parent: string) => boolean;
|
|
13
|
+
/** Read after an entry joins the digest; the first difference it names
|
|
14
|
+
* ends the walk. */
|
|
15
|
+
readonly visit?: (entry: TreeEntry) => Promise<string | null>;
|
|
16
|
+
/** Hears each leaf read for its content. */
|
|
17
|
+
readonly onRead?: () => void;
|
|
18
|
+
/** Hears each piece of a file read for its content. */
|
|
19
|
+
readonly onBytes?: (bytes: number) => void;
|
|
20
|
+
}
|
|
21
|
+
export type Fingerprint = {
|
|
22
|
+
readonly digest: string;
|
|
23
|
+
} | {
|
|
24
|
+
readonly differs: string;
|
|
25
|
+
};
|
|
26
|
+
/** The stamp a fingerprint was first taken under, as a receipt holds it:
|
|
27
|
+
* null when it proved no leaf. Taking it again under a qualification that no
|
|
28
|
+
* longer stands proves nothing (content-clock.ts qualificationStands). */
|
|
29
|
+
export interface FingerprintClock {
|
|
30
|
+
readonly ns: string;
|
|
31
|
+
readonly dev: string;
|
|
32
|
+
readonly qualification: string;
|
|
33
|
+
readonly roots: readonly string[];
|
|
34
|
+
}
|
|
35
|
+
export declare const fingerprintClock: ({ boundary, roots }: ContentStamp) => FingerprintClock | null;
|
|
36
|
+
export declare const clockBoundary: (clock: FingerprintClock | null) => ContentBoundary | null;
|
|
37
|
+
/** Walks every name beneath `top` that `skips` leaves alone, in one fixed
|
|
38
|
+
* order, and digests it. */
|
|
39
|
+
export declare function fingerprintTree(top: string, options: FingerprintOptions): Promise<Fingerprint>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** The fingerprint of a tree Apply sets aside: one digest over every name
|
|
2
|
+
* beneath it, taken by one walk, compared by taking it again
|
|
3
|
+
* (apply-displaced-tree.ts, apply-git-storage.ts).
|
|
4
|
+
*
|
|
5
|
+
* - Each name joins the digest by its full source signature; a directory by
|
|
6
|
+
* its object alone, since moving a name in or out restamps its times, and
|
|
7
|
+
* the names beneath it answer for its membership.
|
|
8
|
+
* - The content clock is stamped before the walk (content-clock.ts). A leaf
|
|
9
|
+
* whose signature the clock proves keeps its content while its signature
|
|
10
|
+
* stays equal, so it is never read. Any other leaf, one written too
|
|
11
|
+
* recently for its change time to prove anything, joins by its content as
|
|
12
|
+
* well: a file by the hash of its bytes, a link by its target.
|
|
13
|
+
* - Taking the fingerprint again under the same clock reads the same leaves,
|
|
14
|
+
* so equal digests mean equal names, objects and contents, with no wait.
|
|
15
|
+
*
|
|
16
|
+
* The walk lists every directory itself, sorted, and never follows a link. */
|
|
17
|
+
import { createHash } from "node:crypto";
|
|
18
|
+
import { join, relative, sep } from "node:path";
|
|
19
|
+
import { sightingUnder } from "./content-clock.js";
|
|
20
|
+
import { hashContentFile } from "./content-cache-host.js";
|
|
21
|
+
import { listAgain, WALK_TURN_ENTRIES } from "./detection/walk-law.js";
|
|
22
|
+
import { readLinkTarget } from "./link-target.js";
|
|
23
|
+
import { optionalLstat } from "./physical-path-witness.js";
|
|
24
|
+
import { contentProven, physicalKey, sourceSignature } from "./source-signature.js";
|
|
25
|
+
import { sha256Hex } from "./sha256.js";
|
|
26
|
+
import { turnBoundary } from "./turns.js";
|
|
27
|
+
export const fingerprintClock = ({ boundary, roots }) => boundary === null ? null : { ns: boundary.ns, dev: boundary.dev.toString(), qualification: boundary.qualification, roots };
|
|
28
|
+
export const clockBoundary = (clock) => clock === null ? null : { ns: clock.ns, dev: BigInt(clock.dev), qualification: clock.qualification };
|
|
29
|
+
/** The content an unproven leaf joins with, or null when it no longer reads
|
|
30
|
+
* as the object its signature named. */
|
|
31
|
+
async function contentOf(entry, options) {
|
|
32
|
+
const { path, stats } = entry;
|
|
33
|
+
if (!stats.isFile() && !stats.isSymbolicLink())
|
|
34
|
+
return "";
|
|
35
|
+
if (contentProven(sourceSignature(stats), sightingUnder(options.clock, stats)))
|
|
36
|
+
return "";
|
|
37
|
+
options.onRead?.();
|
|
38
|
+
try {
|
|
39
|
+
return stats.isSymbolicLink() ? `l:${sha256Hex(Buffer.from(readLinkTarget(path), "utf8"))}`
|
|
40
|
+
: `c:${await hashContentFile(path, options.onBytes)}`;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (["ENOENT", "ENOTDIR", "EACCES", "EPERM", "EISDIR", "EINVAL"].includes(error.code ?? ""))
|
|
44
|
+
return null;
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Walks every name beneath `top` that `skips` leaves alone, in one fixed
|
|
49
|
+
* order, and digests it. */
|
|
50
|
+
export async function fingerprintTree(top, options) {
|
|
51
|
+
const digest = createHash("sha256");
|
|
52
|
+
const pending = [top];
|
|
53
|
+
let entries = 0;
|
|
54
|
+
while (pending.length > 0) {
|
|
55
|
+
const directory = pending.pop();
|
|
56
|
+
const names = listAgain(directory);
|
|
57
|
+
if (names === null)
|
|
58
|
+
return { differs: `${directory} can no longer be listed` };
|
|
59
|
+
for (const name of names) {
|
|
60
|
+
const path = join(directory, name);
|
|
61
|
+
const relativePath = relative(top, path);
|
|
62
|
+
if (options.skips?.(relativePath, directory))
|
|
63
|
+
continue;
|
|
64
|
+
const stats = optionalLstat(path);
|
|
65
|
+
if (!stats)
|
|
66
|
+
return { differs: `${path} left as Apply read it` };
|
|
67
|
+
const entry = { path, parent: directory, stats };
|
|
68
|
+
const content = await contentOf(entry, options);
|
|
69
|
+
if (content === null)
|
|
70
|
+
return { differs: `${path} can no longer be read` };
|
|
71
|
+
digest.update(`${relativePath.split(sep).join("/")}\0${stats.isDirectory() ? `d:${physicalKey(stats)}` : sourceSignature(stats)}`
|
|
72
|
+
+ `\0${content}\n`);
|
|
73
|
+
const difference = await options.visit?.(entry);
|
|
74
|
+
if (difference)
|
|
75
|
+
return { differs: difference };
|
|
76
|
+
if (stats.isDirectory())
|
|
77
|
+
pending.push(path);
|
|
78
|
+
if (++entries % WALK_TURN_ENTRIES === 0)
|
|
79
|
+
await turnBoundary();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return { digest: digest.digest("hex") };
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=apply-fingerprint.js.map
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C;YAChD,IAAI,UAAU;gBAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;YAC/C,IAAI,KAAK,CAAC,WAAW,EAAE;gBAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5C,IAAI,EAAE,OAAO,GAAG,iBAAiB,KAAK,CAAC;gBAAE,MAAM,YAAY,EAAE,CAAC;QAChE,CAAC;IACH,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { type FingerprintClock, type FingerprintOptions } from "./apply-fingerprint.js";
|
|
2
|
+
import type { ContentStamp } from "./content-clock.js";
|
|
1
3
|
/** The displaced marker's name in its intent's control tree. */
|
|
2
4
|
export declare const DISPLACED_GIT = "displaced-git";
|
|
3
5
|
export interface GitStorageManifest {
|
|
4
|
-
readonly contract: "amalgm.apply-git-storage@
|
|
6
|
+
readonly contract: "amalgm.apply-git-storage@2";
|
|
5
7
|
/** The marker's own object. A rename may restamp the moved object's times,
|
|
6
8
|
* so only its device and inode are compared; a gitfile keeps its text. */
|
|
7
9
|
readonly marker: {
|
|
@@ -13,16 +15,24 @@ export interface GitStorageManifest {
|
|
|
13
15
|
readonly path: string;
|
|
14
16
|
readonly object: string;
|
|
15
17
|
};
|
|
16
|
-
/**
|
|
17
|
-
readonly
|
|
18
|
+
/** The clock the fingerprint was taken under. */
|
|
19
|
+
readonly clock: FingerprintClock | null;
|
|
20
|
+
/** Every name beneath the storage directory (apply-fingerprint.ts). */
|
|
21
|
+
readonly digest: string;
|
|
18
22
|
}
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
type Reads = Pick<FingerprintOptions, "onRead" | "onBytes">;
|
|
24
|
+
/** The manifest of `worktree`'s Git storage as it stands now, under `stamp`. */
|
|
25
|
+
export declare function captureGitStorage(worktree: string, stamp: ContentStamp, reads?: Reads): Promise<GitStorageManifest | null>;
|
|
21
26
|
/** Moves the worktree's marker into control while it is the manifest's own
|
|
22
27
|
* object. Storage already displaced, or removed by a person, leaves nothing
|
|
23
28
|
* to move; any other marker is ground the bound read must judge first. */
|
|
24
29
|
export declare function displaceGitStorage(control: string, worktree: string, manifest: GitStorageManifest): void;
|
|
25
30
|
/** Whether the storage displaced into `control` is still the manifest's O.
|
|
26
|
-
* Storage a person
|
|
27
|
-
*
|
|
28
|
-
export declare function keptStorageIsO(control: string,
|
|
31
|
+
* Storage that never left, because a person removed it first, has nothing to
|
|
32
|
+
* lose. */
|
|
33
|
+
export declare function keptStorageIsO(control: string, manifest: GitStorageManifest, reads?: Reads): Promise<boolean>;
|
|
34
|
+
/** Returns storage displaced into `control` to `worktree`, durably. False
|
|
35
|
+
* when another `.git` stands there, so the caller keeps it rather than lets
|
|
36
|
+
* the durability point take it. */
|
|
37
|
+
export declare function returnGitStorage(control: string, worktree: string): boolean;
|
|
38
|
+
export {};
|
|
@@ -3,53 +3,37 @@
|
|
|
3
3
|
* they stand, each on its own channel. Apply never deletes a person's Git
|
|
4
4
|
* write.
|
|
5
5
|
*
|
|
6
|
-
* - The final guard
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* - The final guard stamps its root's content clock, then takes the
|
|
7
|
+
* storage's fingerprint (apply-fingerprint.ts) before its fresh repository
|
|
8
|
+
* observation proves the storage is O, so any Git write after that
|
|
9
|
+
* observation differs from the fingerprint.
|
|
9
10
|
* - The receipt binds that manifest before any effect. It is the only
|
|
10
11
|
* evidence of which storage is O.
|
|
11
12
|
* - The reveal moves the marker into control only while it is the manifest's
|
|
12
13
|
* own object.
|
|
13
|
-
* - Verify
|
|
14
|
-
* (keptStorageIsO). Unchanged storage is the O the cloud
|
|
15
|
-
* goes with the window's control tree at the durability
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
14
|
+
* - Verify takes the displaced storage's fingerprint again before it judges
|
|
15
|
+
* anything else (keptStorageIsO). Unchanged storage is the O the cloud
|
|
16
|
+
* already holds and goes with the window's control tree at the durability
|
|
17
|
+
* point, once its member matches. Changed storage, and storage whose member
|
|
18
|
+
* answers anything else, is brought home (returnGitStorage): a person's
|
|
19
|
+
* Git write the durability point would otherwise destroy returns to its
|
|
20
|
+
* folder, the member stays owed, and Detect records it as the repository's
|
|
21
|
+
* newest result.
|
|
20
22
|
*
|
|
21
23
|
* A gitfile marker names storage outside the worktree. The rename moves only
|
|
22
24
|
* the marker, so the manifest also holds that storage's absolute address. */
|
|
23
|
-
import {
|
|
25
|
+
import { readFileSync, renameSync } from "node:fs";
|
|
24
26
|
import { join } from "node:path";
|
|
27
|
+
import { clockBoundary, fingerprintClock, fingerprintTree } from "./apply-fingerprint.js";
|
|
28
|
+
import { moveWithoutReplacing } from "./apply-spelling.js";
|
|
25
29
|
import { flushDirectory } from "./flush.js";
|
|
26
30
|
import { gitStorageDirectory } from "./git-binding.js";
|
|
27
31
|
import { optionalLstat } from "./physical-path-witness.js";
|
|
28
|
-
import { physicalKey
|
|
29
|
-
import { turnBoundary } from "./turns.js";
|
|
32
|
+
import { physicalKey } from "./source-signature.js";
|
|
30
33
|
/** The displaced marker's name in its intent's control tree. */
|
|
31
34
|
export const DISPLACED_GIT = "displaced-git";
|
|
32
|
-
/**
|
|
33
|
-
async function
|
|
34
|
-
const entries = {};
|
|
35
|
-
const pending = [""];
|
|
36
|
-
while (pending.length > 0) {
|
|
37
|
-
const relativePath = pending.pop();
|
|
38
|
-
for (const name of readdirSync(join(directory, relativePath)).sort()) {
|
|
39
|
-
const child = relativePath ? `${relativePath}/${name}` : name;
|
|
40
|
-
const stats = optionalLstat(join(directory, child));
|
|
41
|
-
if (!stats)
|
|
42
|
-
throw new Error("Git storage changed while Apply read its manifest");
|
|
43
|
-
entries[child] = sourceSignature(stats);
|
|
44
|
-
if (stats.isDirectory())
|
|
45
|
-
pending.push(child);
|
|
46
|
-
await turnBoundary();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return entries;
|
|
50
|
-
}
|
|
51
|
-
/** The manifest of `worktree`'s Git storage as it stands now. */
|
|
52
|
-
export async function captureGitStorage(worktree) {
|
|
35
|
+
/** The manifest of `worktree`'s Git storage as it stands now, under `stamp`. */
|
|
36
|
+
export async function captureGitStorage(worktree, stamp, reads = {}) {
|
|
53
37
|
const markerPath = join(worktree, ".git");
|
|
54
38
|
const marker = optionalLstat(markerPath);
|
|
55
39
|
if (!marker)
|
|
@@ -58,15 +42,22 @@ export async function captureGitStorage(worktree) {
|
|
|
58
42
|
const storage = optionalLstat(directory);
|
|
59
43
|
if (!storage?.isDirectory())
|
|
60
44
|
throw new Error("Apply found no Git storage directory to displace");
|
|
45
|
+
const clock = fingerprintClock(stamp);
|
|
46
|
+
const taken = await fingerprintTree(directory, { clock: clockBoundary(clock), ...reads });
|
|
47
|
+
if ("differs" in taken)
|
|
48
|
+
return null;
|
|
61
49
|
return {
|
|
62
|
-
contract: "amalgm.apply-git-storage@
|
|
50
|
+
contract: "amalgm.apply-git-storage@2",
|
|
63
51
|
marker: { object: physicalKey(marker), gitfile: marker.isFile() ? readFileSync(markerPath, "utf8") : null },
|
|
64
52
|
storage: { path: directory, object: physicalKey(storage) },
|
|
65
|
-
|
|
53
|
+
clock, digest: taken.digest,
|
|
66
54
|
};
|
|
67
55
|
}
|
|
68
56
|
/** Whether `marker` is the manifest's own marker over exactly its storage. */
|
|
69
|
-
async function gitStorageUnchanged(marker, manifest) {
|
|
57
|
+
async function gitStorageUnchanged(marker, manifest, reads) {
|
|
58
|
+
// A manifest of another contract proves nothing.
|
|
59
|
+
if (manifest.contract !== "amalgm.apply-git-storage@2")
|
|
60
|
+
return false;
|
|
70
61
|
const stats = optionalLstat(marker);
|
|
71
62
|
if (!stats || physicalKey(stats) !== manifest.marker.object)
|
|
72
63
|
return false;
|
|
@@ -77,10 +68,8 @@ async function gitStorageUnchanged(marker, manifest) {
|
|
|
77
68
|
const storage = optionalLstat(directory);
|
|
78
69
|
if (!storage?.isDirectory() || physicalKey(storage) !== manifest.storage.object)
|
|
79
70
|
return false;
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
return names.length === Object.keys(manifest.entries).length
|
|
83
|
-
&& names.every(name => manifest.entries[name] === entries[name]);
|
|
71
|
+
const taken = await fingerprintTree(directory, { clock: clockBoundary(manifest.clock), ...reads });
|
|
72
|
+
return "digest" in taken && taken.digest === manifest.digest;
|
|
84
73
|
}
|
|
85
74
|
/** Moves the worktree's marker into control while it is the manifest's own
|
|
86
75
|
* object. Storage already displaced, or removed by a person, leaves nothing
|
|
@@ -99,18 +88,23 @@ export function displaceGitStorage(control, worktree, manifest) {
|
|
|
99
88
|
flushDirectory(worktree);
|
|
100
89
|
}
|
|
101
90
|
/** Whether the storage displaced into `control` is still the manifest's O.
|
|
102
|
-
* Storage a person
|
|
103
|
-
*
|
|
104
|
-
export async function keptStorageIsO(control,
|
|
91
|
+
* Storage that never left, because a person removed it first, has nothing to
|
|
92
|
+
* lose. */
|
|
93
|
+
export async function keptStorageIsO(control, manifest, reads = {}) {
|
|
94
|
+
const displaced = join(control, DISPLACED_GIT);
|
|
95
|
+
return !optionalLstat(displaced) || await gitStorageUnchanged(displaced, manifest, reads);
|
|
96
|
+
}
|
|
97
|
+
/** Returns storage displaced into `control` to `worktree`, durably. False
|
|
98
|
+
* when another `.git` stands there, so the caller keeps it rather than lets
|
|
99
|
+
* the durability point take it. */
|
|
100
|
+
export function returnGitStorage(control, worktree) {
|
|
105
101
|
const displaced = join(control, DISPLACED_GIT);
|
|
106
|
-
if (!optionalLstat(displaced)
|
|
102
|
+
if (!optionalLstat(displaced))
|
|
107
103
|
return true;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
throw new Error(`A person's Git write in ${displaced} cannot return to ${worktree}: another .git stands there`);
|
|
111
|
-
renameSync(displaced, marker);
|
|
104
|
+
if (!moveWithoutReplacing(displaced, join(worktree, ".git")))
|
|
105
|
+
return false;
|
|
112
106
|
flushDirectory(control);
|
|
113
107
|
flushDirectory(worktree);
|
|
114
|
-
return
|
|
108
|
+
return true;
|
|
115
109
|
}
|
|
116
110
|
//# sourceMappingURL=apply-git-storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-git-storage.js","sourceRoot":"","sources":["../src/apply-git-storage.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"apply-git-storage.js","sourceRoot":"","sources":["../src/apply-git-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;6EAuB6E;AAC7E,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAC9B,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,gEAAgE;AAChE,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;AAiB7C,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,QAAgB,EAAE,KAAmB,EAAE,QAAe,EAAE;IAE9F,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;IACzC,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IACvE,MAAM,EAAE,SAAS,EAAE,GAAG,mBAAmB,CAAC,QAAQ,CAAC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AAC;IACxB,cAAc,CAAC,QAAQ,CAAC,CAAC;AAC3B,CAAC;AAED;;WAEW;AACX,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAe,EAAE,QAA4B,EAAE,QAAe,EAAE;IACnG,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC/C,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,MAAM,mBAAmB,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;AAC5F,CAAC;AAED;;mCAEmC;AACnC,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,QAAgB;IAChE,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC/C,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3C,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3E,cAAc,CAAC,OAAO,CAAC,CAAC;IACxB,cAAc,CAAC,QAAQ,CAAC,CAAC;IACzB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/apply-kept.d.ts
CHANGED
|
@@ -17,6 +17,16 @@ export declare function keepRemainder(input: {
|
|
|
17
17
|
readonly displaced: string;
|
|
18
18
|
readonly remainder: readonly Remainder[];
|
|
19
19
|
}): string[];
|
|
20
|
+
/** Moves `from` into its owner's keep as `name`, under this attempt or a
|
|
21
|
+
* fresh sibling of it where the name is taken, and names the directories
|
|
22
|
+
* owed a flush; none when nothing stands at `from`. */
|
|
23
|
+
export declare function keepAside(input: {
|
|
24
|
+
readonly root: string;
|
|
25
|
+
readonly attemptId: string;
|
|
26
|
+
readonly owner: string;
|
|
27
|
+
readonly from: string;
|
|
28
|
+
readonly name: string;
|
|
29
|
+
}): string[];
|
|
20
30
|
/** Returns each name kept for `owner` into `container`, its address in this
|
|
21
31
|
* root, wherever `free` holds, and names the directories owed a flush: every
|
|
22
32
|
* keep still standing with the container, so a return repeated after a crash
|