@feigi/fleet-ctl 3.154.8 → 3.155.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/package.json +1 -1
- package/scripts/evict-tree.mjs +52 -23
- package/scripts/reclaim-scratch.mjs +11 -5
- package/scripts/review-core.mjs +6 -4
package/package.json
CHANGED
package/scripts/evict-tree.mjs
CHANGED
|
@@ -14,12 +14,21 @@
|
|
|
14
14
|
// A TREE, for `evictTrees(root)`, is a directory that holds `.git` at its own
|
|
15
15
|
// top level and whose `git rev-parse --show-toplevel` resolves, by realpath,
|
|
16
16
|
// to that same directory. A directory that resolves to an enclosing repository
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
17
|
+
// is never stripped, and git is never asked about a directory with no `.git`.
|
|
18
|
+
// A directory that holds a `.git` of its own but that git does not resolve to
|
|
19
|
+
// itself — git errors, times out or exits non-zero (an unreadable `.git`, a
|
|
20
|
+
// `.git` with no HEAD, dubious ownership), the realpath comparison throws, or
|
|
21
|
+
// git names another top-level — is SKIPPED: not evicted, and named with its
|
|
22
|
+
// reason in `skipped`, never in `failed`. So is a directory the walk cannot
|
|
23
|
+
// look in for a `.git` (any error but ENOENT or ENOTDIR — a parent with no
|
|
24
|
+
// search permission), or cannot list because of EACCES or EPERM, the root
|
|
25
|
+
// included; a directory with more than one reason is named once, the reasons
|
|
26
|
+
// joined. A directory with no `.git` of its own, and one whose listing fails
|
|
27
|
+
// with ENOENT or ENOTDIR, are neither. The walk goes down from `root` at any
|
|
28
|
+
// depth and never follows a symlink, never enters a `.git`, and never enters a
|
|
29
|
+
// path it removes (or, in a dry run, would remove) as ignored, so a repository
|
|
30
|
+
// inside `node_modules` goes with that directory and is not a tree of its own,
|
|
31
|
+
// nor skipped. A skipped directory does not stop the walk.
|
|
23
32
|
//
|
|
24
33
|
// No status check, no mark, no restore: a tree is evicted whatever `git status`
|
|
25
34
|
// says. A claim tree's status check and its mark are evict.mjs's own.
|
|
@@ -87,39 +96,57 @@ export function removeIgnored(tree, ignored) {
|
|
|
87
96
|
return errors.length ? `could not remove ${errors.join("; ")}` : null;
|
|
88
97
|
}
|
|
89
98
|
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
|
|
99
|
+
// What `dir` is to the walk: `{tree: false}` when it holds no `.git` of its
|
|
100
|
+
// own, `{tree: true}` when it does and git answers for this directory rather
|
|
101
|
+
// than for an enclosing repository, and `{skip}` — why — when it holds one and
|
|
102
|
+
// git does not, or when looking for one fails for any reason but its absence.
|
|
103
|
+
function treeVerdict(dir) {
|
|
93
104
|
try {
|
|
94
105
|
lstatSync(join(dir, ".git"));
|
|
95
|
-
} catch {
|
|
96
|
-
return false;
|
|
106
|
+
} catch (e) {
|
|
107
|
+
if (e.code === "ENOENT" || e.code === "ENOTDIR") return { tree: false };
|
|
108
|
+
return { skip: `cannot look for a .git in it (${e.code ?? e.message})` };
|
|
97
109
|
}
|
|
98
110
|
const r = git(dir, ["rev-parse", "--show-toplevel"]);
|
|
99
|
-
if (r.error || r.status !== 0) return
|
|
111
|
+
if (r.error || r.status !== 0) return { skip: `git rev-parse --show-toplevel did not answer for it (${how(r)})` };
|
|
112
|
+
const top = r.stdout.replace(/\n$/, "");
|
|
100
113
|
try {
|
|
101
|
-
|
|
102
|
-
} catch {
|
|
103
|
-
return
|
|
114
|
+
if (realpathSync(top) === realpathSync(dir)) return { tree: true };
|
|
115
|
+
} catch (e) {
|
|
116
|
+
return { skip: `comparing git's top-level ${top} with it failed (${e.code ?? e.message})` };
|
|
104
117
|
}
|
|
118
|
+
return { skip: `git resolves it to the top-level ${top}, not to itself` };
|
|
105
119
|
}
|
|
106
120
|
|
|
121
|
+
const byPath = (a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
122
|
+
|
|
107
123
|
/**
|
|
108
|
-
* Evict every tree under `root`, `root` itself included:
|
|
124
|
+
* Evict every tree under `root`, `root` itself included:
|
|
125
|
+
* `{evicted, failed, skipped}`.
|
|
109
126
|
* `evicted` is `[{path, ignored}]` for each tree that held ignored paths — in a
|
|
110
127
|
* dry run, what `apply` would remove — and a tree holding none is in neither.
|
|
111
128
|
* `failed` is `[{path, error}]`: a tree whose ignored paths cannot be listed or
|
|
112
129
|
* all removed, or a directory whose listing fails for any reason but its being
|
|
113
|
-
* gone, not a directory, or unreadable.
|
|
130
|
+
* gone, not a directory, or unreadable. `skipped` is `[{path, reason}]`: a
|
|
131
|
+
* directory the walk cannot evaluate, and so leaves as it is — one that holds
|
|
132
|
+
* a `.git` of its own which git does not resolve to that directory (rev-parse
|
|
133
|
+
* errors, times out or exits non-zero, the realpath comparison throws, or
|
|
134
|
+
* another top-level), one it cannot look in for a `.git`, and one whose listing
|
|
135
|
+
* fails with EACCES or EPERM, each named once with every reason it has. Never a
|
|
136
|
+
* failure, and never a path inside an ignored directory the walk removes.
|
|
137
|
+
* Best-effort: the walk goes on.
|
|
114
138
|
*/
|
|
115
139
|
export function evictTrees(root, { apply }) {
|
|
116
140
|
const evicted = [];
|
|
117
141
|
const failed = [];
|
|
142
|
+
const skipped = [];
|
|
118
143
|
const skip = new Set();
|
|
119
144
|
const stack = [root];
|
|
120
145
|
while (stack.length) {
|
|
121
146
|
const dir = stack.pop();
|
|
122
|
-
|
|
147
|
+
const verdict = treeVerdict(dir);
|
|
148
|
+
const reasons = verdict.skip === undefined ? [] : [verdict.skip];
|
|
149
|
+
if (verdict.tree) {
|
|
123
150
|
let ignored;
|
|
124
151
|
try {
|
|
125
152
|
ignored = ignoredPaths(dir);
|
|
@@ -139,16 +166,18 @@ export function evictTrees(root, { apply }) {
|
|
|
139
166
|
entries = readdirSync(dir, { withFileTypes: true });
|
|
140
167
|
} catch (e) {
|
|
141
168
|
// A directory the walk cannot list or search holds no tree it can reach:
|
|
142
|
-
// skipped, as freshUnder() skips one it cannot read, and never
|
|
143
|
-
|
|
144
|
-
|
|
169
|
+
// skipped and named, as freshUnder() skips one it cannot read, and never
|
|
170
|
+
// a failure.
|
|
171
|
+
if (e.code === "EACCES" || e.code === "EPERM") reasons.push(`cannot list it (${e.code})`);
|
|
172
|
+
else if (e.code !== "ENOENT" && e.code !== "ENOTDIR") failed.push({ path: dir, error: `cannot list it (${e.code ?? e.message})` });
|
|
145
173
|
}
|
|
174
|
+
if (reasons.length > 0) skipped.push({ path: dir, reason: reasons.join("; ") });
|
|
175
|
+
if (entries === undefined) continue;
|
|
146
176
|
for (const e of entries) {
|
|
147
177
|
if (e.name === ".git" || !e.isDirectory()) continue;
|
|
148
178
|
const path = join(dir, e.name);
|
|
149
179
|
if (!skip.has(path)) stack.push(path);
|
|
150
180
|
}
|
|
151
181
|
}
|
|
152
|
-
|
|
153
|
-
return { evicted: evicted.sort(byPath), failed: failed.sort(byPath) };
|
|
182
|
+
return { evicted: evicted.sort(byPath), failed: failed.sort(byPath), skipped: skipped.sort(byPath) };
|
|
154
183
|
}
|
|
@@ -121,7 +121,12 @@
|
|
|
121
121
|
// The sibling pass's kept entries also carry "idle": true when nothing under
|
|
122
122
|
// the key was found modified within the retention, false otherwise.
|
|
123
123
|
// `--pr` mode adds `"evicted":[{"path","reason","ignored"}]` after `removed`:
|
|
124
|
-
// each tree that held ignored paths, `ignored` naming them
|
|
124
|
+
// each tree that held ignored paths, `ignored` naming them, and
|
|
125
|
+
// `"skipped":[{"path","reason"}]` after `failed`: each directory in a kept run
|
|
126
|
+
// root that evict-tree.mjs could not evaluate — one with a `.git` git does not
|
|
127
|
+
// resolve to it, one it cannot look in for a `.git`, or one it cannot list for
|
|
128
|
+
// EACCES or EPERM. A skipped directory is never in `failed`, so the snapshot
|
|
129
|
+
// step's marker, which reads `failed`, does not fire for it.
|
|
125
130
|
// `ledger` is the file read, or null when none was (`--pr` mode, or
|
|
126
131
|
// `--after-rotate` with no file) — so "never read" stays distinct from "read
|
|
127
132
|
// and found empty". A dry run prints the same receipt with "applied":false,
|
|
@@ -686,8 +691,9 @@ function main() {
|
|
|
686
691
|
|
|
687
692
|
const now = Date.now();
|
|
688
693
|
let ledger = null;
|
|
689
|
-
// `--pr` mode's evictions
|
|
690
|
-
|
|
694
|
+
// `--pr` mode's evictions and skipped directories, in its receipt only.
|
|
695
|
+
const evicted = [];
|
|
696
|
+
const skipped = [];
|
|
691
697
|
let remove;
|
|
692
698
|
let kept = [];
|
|
693
699
|
const failed = [];
|
|
@@ -700,11 +706,11 @@ function main() {
|
|
|
700
706
|
failed.push({ path: parent, error: e.message });
|
|
701
707
|
}
|
|
702
708
|
// `--pr` mode also evicts the trees in every run root it keeps.
|
|
703
|
-
evicted = [];
|
|
704
709
|
for (const run of kept) {
|
|
705
710
|
const done = evictTrees(run.path, { apply });
|
|
706
711
|
for (const t of done.evicted) evicted.push({ path: t.path, reason: "a tree in a kept review run root", ignored: t.ignored });
|
|
707
712
|
failed.push(...done.failed);
|
|
713
|
+
skipped.push(...done.skipped);
|
|
708
714
|
}
|
|
709
715
|
} else if (siblings) {
|
|
710
716
|
if (apply) {
|
|
@@ -759,7 +765,7 @@ function main() {
|
|
|
759
765
|
if (error === null) removed.push(entry);
|
|
760
766
|
else failed.push({ path: entry.path, error });
|
|
761
767
|
}
|
|
762
|
-
const receipt = { applied: apply, ledger, removed, ...(
|
|
768
|
+
const receipt = { applied: apply, ledger, removed, ...(pr === null ? {} : { evicted }), kept, failed, ...(pr === null ? {} : { skipped }) };
|
|
763
769
|
writeAll(1, `${JSON.stringify(receipt)}\n`);
|
|
764
770
|
}
|
|
765
771
|
|
package/scripts/review-core.mjs
CHANGED
|
@@ -993,10 +993,11 @@ function standaloneScratchRoot() {
|
|
|
993
993
|
* run root of this PR, it evicts every tree in that run root: the snapshot and
|
|
994
994
|
* each specialist's and refuter's copy lose every path git ignores in them,
|
|
995
995
|
* and nothing restores them. The run root's other files stay, review.json
|
|
996
|
-
* among them. A failed eviction,
|
|
997
|
-
*
|
|
998
|
-
*
|
|
999
|
-
*
|
|
996
|
+
* among them. A failed eviction, a directory the eviction skips, and a
|
|
997
|
+
* reported run root it refuses to touch, are logged — a skip worded as a skip,
|
|
998
|
+
* not a failure; none of them, nor a log that throws, changes what the review
|
|
999
|
+
* returns or throws. A snapshot step that reported no run root evicts nothing
|
|
1000
|
+
* and logs nothing.
|
|
1000
1001
|
*/
|
|
1001
1002
|
export async function runReview(host, args) {
|
|
1002
1003
|
const run = { partition: null, runRoot: null };
|
|
@@ -1041,6 +1042,7 @@ function evictRunRoot(log, { partition, runRoot }) {
|
|
|
1041
1042
|
}
|
|
1042
1043
|
const done = evictTrees(runRoot, { apply: true });
|
|
1043
1044
|
for (const f of done.failed) say(`eviction at the end of the review failed in ${f.path}: ${f.error}`);
|
|
1045
|
+
for (const s of done.skipped) say(`eviction at the end of the review skipped ${s.path}: ${s.reason}`);
|
|
1044
1046
|
} catch (e) {
|
|
1045
1047
|
say(`eviction at the end of the review failed in ${runRoot}: ${e?.message ?? e}`);
|
|
1046
1048
|
}
|