@indigoai-us/hq-cloud 6.18.108 → 6.18.109
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/cli/rescue-core.d.ts +64 -1
- package/dist/cli/rescue-core.d.ts.map +1 -1
- package/dist/cli/rescue-core.js +225 -119
- package/dist/cli/rescue-core.js.map +1 -1
- package/dist/cli/rescue-native-copy.d.ts +88 -0
- package/dist/cli/rescue-native-copy.d.ts.map +1 -0
- package/dist/cli/rescue-native-copy.js +823 -0
- package/dist/cli/rescue-native-copy.js.map +1 -0
- package/dist/ignore.d.ts +5 -1
- package/dist/ignore.d.ts.map +1 -1
- package/dist/ignore.js +32 -2
- package/dist/ignore.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -26,6 +26,33 @@ interface Config {
|
|
|
26
26
|
verifyRestoredSnapshot: string;
|
|
27
27
|
restoreSnapshot: string;
|
|
28
28
|
}
|
|
29
|
+
type RunResult = {
|
|
30
|
+
status: number;
|
|
31
|
+
stdout: string;
|
|
32
|
+
stderr: string;
|
|
33
|
+
error: Error | undefined;
|
|
34
|
+
signal: NodeJS.Signals | null;
|
|
35
|
+
};
|
|
36
|
+
export declare const GIT_BATCH_CHUNK_SIZE = 4096;
|
|
37
|
+
export declare class GitBatchError extends Error {
|
|
38
|
+
readonly args: string[];
|
|
39
|
+
readonly result: RunResult;
|
|
40
|
+
readonly chunkStart: number;
|
|
41
|
+
readonly chunkLength: number;
|
|
42
|
+
constructor(args: string[], result: RunResult, chunkStart: number, chunkLength: number);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Feed `inputs` to a line-oriented git batch command and return exactly one
|
|
46
|
+
* output line per input, in order. Inputs are sent in chunks so no single
|
|
47
|
+
* child ever produces more output than spawnSync will buffer, and any chunk
|
|
48
|
+
* that fails (non-zero exit, signal, spawn error, short output) throws instead
|
|
49
|
+
* of returning a partial result.
|
|
50
|
+
*/
|
|
51
|
+
export declare function runGitBatch(args: string[], inputs: readonly string[], opts?: {
|
|
52
|
+
cwd?: string;
|
|
53
|
+
env?: NodeJS.ProcessEnv;
|
|
54
|
+
chunkSize?: number;
|
|
55
|
+
}): string[];
|
|
29
56
|
/** Read an environment value without relying on Windows' case-insensitive proxy. */
|
|
30
57
|
export declare function envValue(env: NodeJS.ProcessEnv, name: string): string | undefined;
|
|
31
58
|
/**
|
|
@@ -73,8 +100,28 @@ interface RsyncLauncher {
|
|
|
73
100
|
* report it as present but not executable instead of launching it.
|
|
74
101
|
*/
|
|
75
102
|
export declare function findRsyncOnPath(entries: string[], env: NodeJS.ProcessEnv): RsyncPathCandidate | undefined;
|
|
76
|
-
/** The overlay
|
|
103
|
+
/** The rsync overlay; do not allocate a recovery copy when it cannot run. */
|
|
77
104
|
export declare function requireWorkingRsync(env: NodeJS.ProcessEnv, err: (s: string) => void): RsyncLauncher;
|
|
105
|
+
/** How the overlay copies the release into the HQ root. */
|
|
106
|
+
export type OverlayCopyEngine = {
|
|
107
|
+
kind: "rsync";
|
|
108
|
+
launcher: RsyncLauncher;
|
|
109
|
+
} | {
|
|
110
|
+
kind: "native";
|
|
111
|
+
};
|
|
112
|
+
/** Environment variable that forces an overlay engine: `native` or `rsync`. */
|
|
113
|
+
export declare const COPY_ENGINE_ENV = "HQ_RESCUE_COPY_ENGINE";
|
|
114
|
+
/**
|
|
115
|
+
* Choose the overlay copy engine before any snapshot is allocated.
|
|
116
|
+
*
|
|
117
|
+
* A working rsync is used as before. When rsync is not on PATH at all, the
|
|
118
|
+
* overlay uses the built-in file copy (./rescue-native-copy.ts) with the same
|
|
119
|
+
* filters, instead of failing with exit 127. An rsync that is on PATH but
|
|
120
|
+
* broken still fails the preflight, as before. `HQ_RESCUE_COPY_ENGINE=rsync`
|
|
121
|
+
* keeps the old rsync-only behaviour; `HQ_RESCUE_COPY_ENGINE=native` uses
|
|
122
|
+
* the built-in copy even when rsync works.
|
|
123
|
+
*/
|
|
124
|
+
export declare function selectOverlayCopyEngine(env: NodeJS.ProcessEnv, out: (s: string) => void, err: (s: string) => void): OverlayCopyEngine;
|
|
78
125
|
/**
|
|
79
126
|
* Git with `core.symlinks=false` (the Git for Windows default when the user
|
|
80
127
|
* lacks the symlink privilege) checks a mode-120000 entry out as a regular
|
|
@@ -395,6 +442,15 @@ interface ReconcileCtx {
|
|
|
395
442
|
* rescue's posture elsewhere.
|
|
396
443
|
*/
|
|
397
444
|
export declare function reconcileClaudeSettings(ctx: ReconcileCtx, preRescueSettingsJson: string | null, out: (s: string) => void, err: (s: string) => void): void;
|
|
445
|
+
/**
|
|
446
|
+
* Blob SHA for each local file, in order; "" where the file could not be
|
|
447
|
+
* hashed. `git hash-object --stdin-paths` stops at the first file it cannot
|
|
448
|
+
* open (a cloud placeholder, a permission-denied file, one deleted mid-walk),
|
|
449
|
+
* so a chunk that fails is retried one file at a time. That bounds the
|
|
450
|
+
* per-file spawns to one chunk, and an unhashable file simply stays out of
|
|
451
|
+
* the map, which classifyOne treats as a local edit.
|
|
452
|
+
*/
|
|
453
|
+
export declare function hashLocalFilesInChunks(absPaths: readonly string[], env: NodeJS.ProcessEnv | undefined, warn: (msg: string) => void, chunkSize?: number): string[];
|
|
398
454
|
/** Format the exact safe command presented in a breaker diagnostic. */
|
|
399
455
|
export declare function formatRecoveryCommand(hqRoot: string, backupRoot: string, verifyRestoredSnapshot?: string): string;
|
|
400
456
|
/** Format the manifest-aware command that restores links as well as files. */
|
|
@@ -433,5 +489,12 @@ export type RescueStagingChoice = {
|
|
|
433
489
|
* location shares the HQ root's filesystem, fall back to `os.tmpdir()`.
|
|
434
490
|
*/
|
|
435
491
|
export declare function resolveRescueStagingRoot(hqRoot: string, backupRoot: string, statSync?: typeof fs.statSync, tmpdir?: string, mkdirSync?: typeof fs.mkdirSync): RescueStagingChoice;
|
|
492
|
+
/**
|
|
493
|
+
* Protect one path from the overlay with an exact rsync exclude. rsync reads
|
|
494
|
+
* backslash escapes only in a pattern that holds a wildcard (`*`, `?`, `[`,
|
|
495
|
+
* or the `/***` suffix of a recursive entry), so escape only then; a plain
|
|
496
|
+
* name with a backslash is compared literally and must stay as it is.
|
|
497
|
+
*/
|
|
498
|
+
export declare function appendLiteralRsyncExclude(excludeList: string, rel: string, recursive?: boolean): void;
|
|
436
499
|
export {};
|
|
437
500
|
//# sourceMappingURL=rescue-core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rescue-core.d.ts","sourceRoot":"","sources":["../../src/cli/rescue-core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rescue-core.d.ts","sourceRoot":"","sources":["../../src/cli/rescue-core.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAGzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAQ7B,OAAO,EAOL,KAAK,gBAAgB,EAEtB,MAAM,oBAAoB,CAAC;AAK5B,OAAO,EAAuB,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAWnF,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,KAAK,mBAAmB,GAAG,CACzB,OAAO,EAAE,MAAM,EAAE,EACjB,oBAAoB,EAAE,MAAM,EAC5B,gBAAgB,CAAC,EAAE,MAAM,EAAE,KACxB,IAAI,CAAC;AA+FV,UAAU,MAAM;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,OAAO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B,EACtG,QAAQ,GAAE,OAAO,EAAE,CAAC,QAAsB,EAC1C,QAAQ,GAAE,MAAM,CAAC,QAA2B,EAC5C,WAAW,GAAE,mBAAoC;AACjD;;;;GAIG;AACH,UAAU,GAAE,MAAoB,GAC/B,OAAO,CAmGT;AA+GD,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ,GAAG,oBAAoB,GAAG,iBAAiB,CAAC;CAC7D,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,QAAQ,GAAE,OAAO,EAAE,CAAC,QAAsB,EAC1C,MAAM,GAAE,MAAoB,EAC5B,SAAS,GAAE,OAAO,EAAE,CAAC,SAAwB,GAC5C,mBAAmB,CAarB;AA6mBD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,SAAS,UAAQ,GAChB,IAAI,CAQN"}
|
package/dist/cli/rescue-core.js
CHANGED
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
* `git` (clone/checkout/hash-object/cat-file/ls-tree/show/log) and `rsync`
|
|
9
9
|
* (the overlay) — are still invoked as subprocesses. YAML stamp reads and
|
|
10
10
|
* writes are handled in-process so a rescue does not depend on optional YAML
|
|
11
|
-
* executables being present. Reimplementing git's blob hashing
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* executables being present. Reimplementing git's blob hashing in pure JS
|
|
12
|
+
* would *increase* the risk of behavioural drift, so the port reuses git's
|
|
13
|
+
* exact commands. When rsync is not on PATH (a stock Windows install), the
|
|
14
|
+
* overlay runs the built-in copy in ./rescue-native-copy.ts with the same
|
|
15
|
+
* rsync argument vector; see {@link selectOverlayCopyEngine}.
|
|
14
16
|
*
|
|
15
17
|
* Behaviour (classification outcomes, on-disk results, log lines, exit codes)
|
|
16
18
|
* is preserved 1:1 with the legacy script. See the original script's header in
|
|
@@ -38,6 +40,7 @@ import { assertRescuePathTypeUnchanged, isRescueTransientDirectory, rescueSnapsh
|
|
|
38
40
|
import { applyBackupPrune, canonicalRootHash, inventoryManagedSnapshots, isManagedSnapshotManifest, } from "../backup-prune.js";
|
|
39
41
|
import { makeRestoreProbePath, makeRestoreStagePath, } from "../restore-staging.js";
|
|
40
42
|
import { readCoreSourceStamp, writeCoreSourceStamp } from "./core-source-stamp.js";
|
|
43
|
+
import { rsyncFilterRuleMatches, runNativeOverlay } from "./rescue-native-copy.js";
|
|
41
44
|
import { chooseRescueGit, GIT_VERSION_PROBE_TIMEOUT_MS, gitTooOldMessage, parseGitVersion, pinGitFirstOnPath, RESCUE_MIN_GIT_VERSION, } from "./rescue-git.js";
|
|
42
45
|
const MAX_CLONE_FILES_PER_BATCH = 200;
|
|
43
46
|
const MAX_CLONE_BATCH_PATH_BYTES = 64 * 1024;
|
|
@@ -133,6 +136,7 @@ function runWithSpawnError(cmd, args, opts = {}) {
|
|
|
133
136
|
input: opts.input,
|
|
134
137
|
encoding: "utf-8",
|
|
135
138
|
...(typeof opts.timeout === "number" ? { timeout: opts.timeout } : {}),
|
|
139
|
+
...(typeof opts.maxBuffer === "number" ? { maxBuffer: opts.maxBuffer } : {}),
|
|
136
140
|
});
|
|
137
141
|
return {
|
|
138
142
|
status: res.status ?? (res.error ? 127 : 1),
|
|
@@ -142,6 +146,57 @@ function runWithSpawnError(cmd, args, opts = {}) {
|
|
|
142
146
|
signal: res.signal,
|
|
143
147
|
};
|
|
144
148
|
}
|
|
149
|
+
export const GIT_BATCH_CHUNK_SIZE = 4096;
|
|
150
|
+
const GIT_BATCH_MAX_BUFFER = 256 * 1024 * 1024;
|
|
151
|
+
export class GitBatchError extends Error {
|
|
152
|
+
args;
|
|
153
|
+
result;
|
|
154
|
+
chunkStart;
|
|
155
|
+
chunkLength;
|
|
156
|
+
constructor(args, result, chunkStart, chunkLength) {
|
|
157
|
+
const detail = result.error?.message ??
|
|
158
|
+
(result.signal ? `killed by ${result.signal}` : `exit ${result.status}`);
|
|
159
|
+
super(`git ${args.join(" ")} failed on inputs ${chunkStart}..${chunkStart + chunkLength - 1}: ${detail}${result.stderr.trim() ? `\n${result.stderr.trim()}` : ""}`);
|
|
160
|
+
this.args = args;
|
|
161
|
+
this.result = result;
|
|
162
|
+
this.chunkStart = chunkStart;
|
|
163
|
+
this.chunkLength = chunkLength;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Feed `inputs` to a line-oriented git batch command and return exactly one
|
|
168
|
+
* output line per input, in order. Inputs are sent in chunks so no single
|
|
169
|
+
* child ever produces more output than spawnSync will buffer, and any chunk
|
|
170
|
+
* that fails (non-zero exit, signal, spawn error, short output) throws instead
|
|
171
|
+
* of returning a partial result.
|
|
172
|
+
*/
|
|
173
|
+
export function runGitBatch(args, inputs, opts = {}) {
|
|
174
|
+
const chunkSize = Math.max(1, opts.chunkSize ?? GIT_BATCH_CHUNK_SIZE);
|
|
175
|
+
const lines = [];
|
|
176
|
+
for (let start = 0; start < inputs.length; start += chunkSize) {
|
|
177
|
+
const chunk = inputs.slice(start, start + chunkSize);
|
|
178
|
+
const res = run("git", args, {
|
|
179
|
+
cwd: opts.cwd,
|
|
180
|
+
env: opts.env,
|
|
181
|
+
input: chunk.join("\n") + "\n",
|
|
182
|
+
maxBuffer: GIT_BATCH_MAX_BUFFER,
|
|
183
|
+
});
|
|
184
|
+
if (res.status !== 0 || res.error || res.signal) {
|
|
185
|
+
throw new GitBatchError(args, res, start, chunk.length);
|
|
186
|
+
}
|
|
187
|
+
const out = res.stdout.endsWith("\n") ? res.stdout.slice(0, -1) : res.stdout;
|
|
188
|
+
const got = out === "" ? [] : out.split("\n");
|
|
189
|
+
if (got.length !== chunk.length) {
|
|
190
|
+
throw new GitBatchError(args, {
|
|
191
|
+
...res,
|
|
192
|
+
stderr: `expected ${chunk.length} output lines, got ${got.length}`,
|
|
193
|
+
}, start, chunk.length);
|
|
194
|
+
}
|
|
195
|
+
for (const line of got)
|
|
196
|
+
lines.push(line);
|
|
197
|
+
}
|
|
198
|
+
return lines;
|
|
199
|
+
}
|
|
145
200
|
/** Read an environment value without relying on Windows' case-insensitive proxy. */
|
|
146
201
|
export function envValue(env, name) {
|
|
147
202
|
for (const [key, value] of Object.entries(env)) {
|
|
@@ -490,8 +545,8 @@ function buildRsyncLauncher(candidatePath) {
|
|
|
490
545
|
}
|
|
491
546
|
return { command: "rsync", leadingArgs: [] };
|
|
492
547
|
}
|
|
493
|
-
/**
|
|
494
|
-
|
|
548
|
+
/** Find rsync on PATH and run `rsync --version` through the overlay's launcher. */
|
|
549
|
+
function probeRsync(env) {
|
|
495
550
|
const resolvedPath = envValue(env, "PATH");
|
|
496
551
|
const entries = pathEntries(resolvedPath);
|
|
497
552
|
const foundRsync = findRsyncOnPath(entries, env);
|
|
@@ -500,8 +555,60 @@ export function requireWorkingRsync(env, err) {
|
|
|
500
555
|
env,
|
|
501
556
|
});
|
|
502
557
|
const output = `${probe.stdout}\n${probe.stderr}`;
|
|
503
|
-
|
|
504
|
-
|
|
558
|
+
const working = probe.status === 0 && /\brsync\b.*\bversion\b/i.test(output);
|
|
559
|
+
return { launcher, foundRsync, entries, resolvedPath, probe, output, working };
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* rsync is absent, not broken: no candidate on PATH and the launch failed
|
|
563
|
+
* with ENOENT. A present but unexecutable, failing, or unrecognised rsync is
|
|
564
|
+
* not "absent" and still stops the rescue.
|
|
565
|
+
*/
|
|
566
|
+
function rsyncIsMissing(result) {
|
|
567
|
+
const code = result.probe.error && "code" in result.probe.error
|
|
568
|
+
? result.probe.error.code
|
|
569
|
+
: undefined;
|
|
570
|
+
return result.foundRsync === undefined && code === "ENOENT";
|
|
571
|
+
}
|
|
572
|
+
/** The rsync overlay; do not allocate a recovery copy when it cannot run. */
|
|
573
|
+
export function requireWorkingRsync(env, err) {
|
|
574
|
+
const result = probeRsync(env);
|
|
575
|
+
if (result.working)
|
|
576
|
+
return result.launcher;
|
|
577
|
+
return reportRsyncPreflightFailure(result, err);
|
|
578
|
+
}
|
|
579
|
+
/** Environment variable that forces an overlay engine: `native` or `rsync`. */
|
|
580
|
+
export const COPY_ENGINE_ENV = "HQ_RESCUE_COPY_ENGINE";
|
|
581
|
+
/**
|
|
582
|
+
* Choose the overlay copy engine before any snapshot is allocated.
|
|
583
|
+
*
|
|
584
|
+
* A working rsync is used as before. When rsync is not on PATH at all, the
|
|
585
|
+
* overlay uses the built-in file copy (./rescue-native-copy.ts) with the same
|
|
586
|
+
* filters, instead of failing with exit 127. An rsync that is on PATH but
|
|
587
|
+
* broken still fails the preflight, as before. `HQ_RESCUE_COPY_ENGINE=rsync`
|
|
588
|
+
* keeps the old rsync-only behaviour; `HQ_RESCUE_COPY_ENGINE=native` uses
|
|
589
|
+
* the built-in copy even when rsync works.
|
|
590
|
+
*/
|
|
591
|
+
export function selectOverlayCopyEngine(env, out, err) {
|
|
592
|
+
const forced = (envValue(env, COPY_ENGINE_ENV) ?? "").trim().toLowerCase();
|
|
593
|
+
if (forced === "native") {
|
|
594
|
+
out(`==> Copy engine: built-in file copy (${COPY_ENGINE_ENV}=native)\n`);
|
|
595
|
+
return { kind: "native" };
|
|
596
|
+
}
|
|
597
|
+
if (forced !== "" && forced !== "rsync") {
|
|
598
|
+
err(`error: ${COPY_ENGINE_ENV} must be "native" or "rsync" (got ${JSON.stringify(boundedDiagnostic(forced, 64))}).\n`);
|
|
599
|
+
throw new ExitError(2);
|
|
600
|
+
}
|
|
601
|
+
const result = probeRsync(env);
|
|
602
|
+
if (result.working)
|
|
603
|
+
return { kind: "rsync", launcher: result.launcher };
|
|
604
|
+
if (forced === "" && rsyncIsMissing(result)) {
|
|
605
|
+
out("==> Copy engine: built-in file copy (rsync not found on PATH)\n");
|
|
606
|
+
return { kind: "native" };
|
|
607
|
+
}
|
|
608
|
+
return reportRsyncPreflightFailure(result, err);
|
|
609
|
+
}
|
|
610
|
+
/** Print the rsync preflight diagnostic and stop the rescue. */
|
|
611
|
+
function reportRsyncPreflightFailure({ foundRsync, entries, resolvedPath, probe, output }, err) {
|
|
505
612
|
err("error: rsync preflight failed before any safety snapshot was allocated.\n");
|
|
506
613
|
if (probe.error) {
|
|
507
614
|
const errorDetail = "code" in probe.error && typeof probe.error.code === "string"
|
|
@@ -531,7 +638,7 @@ export function requireWorkingRsync(env, err) {
|
|
|
531
638
|
: "(none)";
|
|
532
639
|
err(` rsync found at: ${foundRsyncDiagnostic}\n`);
|
|
533
640
|
err(` resolved PATH: ${boundedDiagnostic(resolvedPath ?? "(unset)", 1024)}\n`);
|
|
534
|
-
err(" Install or repair rsync and retry. On Windows, install the Cygwin rsync package with the Cygwin installer and add its bin directory to PATH.\n");
|
|
641
|
+
err(" Install or repair rsync and retry. Or set HQ_RESCUE_COPY_ENGINE=native to use the built-in file copy instead. On Windows, install the Cygwin rsync package with the Cygwin installer and add its bin directory to PATH.\n");
|
|
535
642
|
throw new ExitError(probe.status || 127);
|
|
536
643
|
}
|
|
537
644
|
// fs predicates mirroring bash test operators.
|
|
@@ -817,7 +924,15 @@ export function parseRescueArgs(argv) {
|
|
|
817
924
|
" [--no-backup] [--backup-dir DIR] [--cloud-update]\n" +
|
|
818
925
|
" [--dry-run] [--yes] [--recover-snapshots]\n" +
|
|
819
926
|
" [--verify-restored-snapshot SNAPSHOT]\n" +
|
|
820
|
-
" [--restore-snapshot SNAPSHOT]\n"
|
|
927
|
+
" [--restore-snapshot SNAPSHOT]\n" +
|
|
928
|
+
"\n" +
|
|
929
|
+
"environment:\n" +
|
|
930
|
+
" HQ_RESCUE_COPY_ENGINE=native|rsync\n" +
|
|
931
|
+
" How the release is copied into the HQ root. Unset: rsync when it\n" +
|
|
932
|
+
" works, the built-in file copy when rsync is not on PATH; a broken\n" +
|
|
933
|
+
" rsync stops the update. rsync: require rsync (exit 127 when it is\n" +
|
|
934
|
+
" missing). native: always use the built-in file copy. Any other\n" +
|
|
935
|
+
" value exits 2.\n");
|
|
821
936
|
throw new ExitError(1);
|
|
822
937
|
};
|
|
823
938
|
let narrowCsv = "";
|
|
@@ -1635,10 +1750,12 @@ export function realpathOrExit(p, err) {
|
|
|
1635
1750
|
}
|
|
1636
1751
|
}
|
|
1637
1752
|
}
|
|
1638
|
-
function reportRsyncFailure(status, phase, stderr, err) {
|
|
1753
|
+
function reportRsyncFailure(status, phase, stderr, err, engine = "rsync") {
|
|
1639
1754
|
if (stderr)
|
|
1640
1755
|
err(stderr);
|
|
1641
|
-
|
|
1756
|
+
// The built-in copy returns rsync's status codes (23 = some entries were
|
|
1757
|
+
// not copied), so the failure kinds and the restore path stay the same.
|
|
1758
|
+
err(`${engine === "native" ? "built-in file copy" : "rsync"} status ${status} during ${phase}\n`);
|
|
1642
1759
|
err(`HQ_RESCUE_FAILURE_KIND=${status === 23 || status === 24 ? "rsync-partial" : "rsync-failed"}\n`);
|
|
1643
1760
|
}
|
|
1644
1761
|
function hashRecoveryTree(root, rootRel) {
|
|
@@ -1803,66 +1920,6 @@ export function rsyncWindowsEnv(env, platform = process.platform) {
|
|
|
1803
1920
|
}
|
|
1804
1921
|
return next;
|
|
1805
1922
|
}
|
|
1806
|
-
/** One `--include=`/`--exclude=` rule as rsync's receiver filter applies it. */
|
|
1807
|
-
function rsyncFilterRuleMatches(rawPattern, rel, isDir) {
|
|
1808
|
-
let pattern = rawPattern;
|
|
1809
|
-
let tripleStar = false;
|
|
1810
|
-
if (pattern.endsWith("/***")) {
|
|
1811
|
-
tripleStar = true;
|
|
1812
|
-
pattern = pattern.slice(0, -4);
|
|
1813
|
-
}
|
|
1814
|
-
else if (pattern.endsWith("/")) {
|
|
1815
|
-
if (!isDir)
|
|
1816
|
-
return false;
|
|
1817
|
-
pattern = pattern.replace(/\/+$/, "");
|
|
1818
|
-
}
|
|
1819
|
-
const anchored = pattern.startsWith("/");
|
|
1820
|
-
if (anchored)
|
|
1821
|
-
pattern = pattern.replace(/^\/+/, "");
|
|
1822
|
-
if (pattern.length === 0)
|
|
1823
|
-
return false;
|
|
1824
|
-
let body = "";
|
|
1825
|
-
for (let i = 0; i < pattern.length; i++) {
|
|
1826
|
-
const ch = pattern[i];
|
|
1827
|
-
if (ch === "*") {
|
|
1828
|
-
if (pattern[i + 1] === "*") {
|
|
1829
|
-
body += ".*";
|
|
1830
|
-
i++;
|
|
1831
|
-
}
|
|
1832
|
-
else {
|
|
1833
|
-
body += "[^/]*";
|
|
1834
|
-
}
|
|
1835
|
-
}
|
|
1836
|
-
else if (ch === "?") {
|
|
1837
|
-
body += "[^/]";
|
|
1838
|
-
}
|
|
1839
|
-
else if (ch === "[") {
|
|
1840
|
-
const close = pattern.indexOf("]", i + 1);
|
|
1841
|
-
if (close < 0) {
|
|
1842
|
-
body += "\\[";
|
|
1843
|
-
}
|
|
1844
|
-
else {
|
|
1845
|
-
body += pattern.slice(i, close + 1).replace(/\\/g, "\\\\");
|
|
1846
|
-
i = close;
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
else {
|
|
1850
|
-
body += ch.replace(/[.+^${}()|\\]/g, "\\$&");
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
1853
|
-
if (tripleStar)
|
|
1854
|
-
body += "(/.*)?";
|
|
1855
|
-
const hasSlash = pattern.includes("/") || tripleStar;
|
|
1856
|
-
let source;
|
|
1857
|
-
if (anchored)
|
|
1858
|
-
source = `^${body}$`;
|
|
1859
|
-
else if (hasSlash)
|
|
1860
|
-
source = `^(.*/)?${body}$`;
|
|
1861
|
-
else
|
|
1862
|
-
source = `^${body}$`;
|
|
1863
|
-
const subject = !anchored && !hasSlash ? rel.slice(rel.lastIndexOf("/") + 1) : rel;
|
|
1864
|
-
return new RegExp(source).test(subject);
|
|
1865
|
-
}
|
|
1866
1923
|
/**
|
|
1867
1924
|
* The rsync filter list for the full (preserve-list) overlay.
|
|
1868
1925
|
*
|
|
@@ -2179,7 +2236,21 @@ function releaseLinkPointsAtStaging(destination, srcDir) {
|
|
|
2179
2236
|
return true;
|
|
2180
2237
|
return absolutePathIsInside(path.resolve(path.dirname(destination), linkText), srcDir);
|
|
2181
2238
|
}
|
|
2182
|
-
|
|
2239
|
+
/**
|
|
2240
|
+
* Run one overlay call. `args` is the full rsync argument vector, ending with
|
|
2241
|
+
* the Cygwin-form source and destination. The built-in copy reads the same
|
|
2242
|
+
* options and filters and takes the native `srcDir` and `hqRoot` paths.
|
|
2243
|
+
*/
|
|
2244
|
+
function runOverlayCopy(engine, args, srcDir, hqRoot, env) {
|
|
2245
|
+
if (engine.kind === "rsync") {
|
|
2246
|
+
return run(engine.launcher.command, [...engine.launcher.leadingArgs, ...args], {
|
|
2247
|
+
env: rsyncWindowsEnv(env),
|
|
2248
|
+
});
|
|
2249
|
+
}
|
|
2250
|
+
const result = runNativeOverlay(srcDir, hqRoot, args.slice(0, -2));
|
|
2251
|
+
return { ...result, error: undefined, signal: null };
|
|
2252
|
+
}
|
|
2253
|
+
function recoveryProof(unresolved, cfg, hqRoot, srcDir, srcSha, copyEngine, rsyncExcludes, env) {
|
|
2183
2254
|
const newest = [...unresolved].sort((left, right) => right.entry.completedMs - left.entry.completedMs ||
|
|
2184
2255
|
right.entry.createdMs - left.entry.createdMs ||
|
|
2185
2256
|
right.entry.name.localeCompare(left.entry.name))[0];
|
|
@@ -2190,8 +2261,7 @@ function recoveryProof(unresolved, cfg, hqRoot, srcDir, srcSha, rsyncLauncher, r
|
|
|
2190
2261
|
newest.entry.manifest.sourceSha !== srcSha) {
|
|
2191
2262
|
failures.push("sha");
|
|
2192
2263
|
}
|
|
2193
|
-
const releaseProof =
|
|
2194
|
-
...rsyncLauncher.leadingArgs,
|
|
2264
|
+
const releaseProof = runOverlayCopy(copyEngine, [
|
|
2195
2265
|
"-a",
|
|
2196
2266
|
"--checksum",
|
|
2197
2267
|
"--no-times",
|
|
@@ -2201,7 +2271,7 @@ function recoveryProof(unresolved, cfg, hqRoot, srcDir, srcSha, rsyncLauncher, r
|
|
|
2201
2271
|
...rsyncWindowsReceiverArgs(),
|
|
2202
2272
|
toCygwinRsyncPath(srcDir + "/"),
|
|
2203
2273
|
toCygwinRsyncPath(hqRoot + "/"),
|
|
2204
|
-
],
|
|
2274
|
+
], srcDir, hqRoot, env);
|
|
2205
2275
|
if (releaseProof.status !== 0 ||
|
|
2206
2276
|
!rsyncOutputHasOnlyDirectoryChanges(`${releaseProof.stdout}\n${releaseProof.stderr}`)) {
|
|
2207
2277
|
failures.push("release-bytes");
|
|
@@ -2243,10 +2313,11 @@ function assertClaudeSettingsAdmission(hqRoot, err) {
|
|
|
2243
2313
|
function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTimeoutMs = GIT_REACHABILITY_PROBE_TIMEOUT_MS, stampWriter = writeCoreSourceStamp, restoreOnRsyncFailure = false, setupPathSettingsLocal = false, backupCapacityStatfsSync = fs.statfsSync, backupCapacityCloneProbe, backupCapacityStatSync = fs.statSync, pathSep = path.sep, snapshotClonePlatform = process.platform, snapshotCloneRunner = runDarwinClone) {
|
|
2244
2314
|
const hqRoot = resolveHqRoot(cfg, err);
|
|
2245
2315
|
const RUN_TS = utcStamp(new Date(), "dash");
|
|
2246
|
-
//
|
|
2247
|
-
//
|
|
2248
|
-
// fallback, then fail later at overlay
|
|
2249
|
-
|
|
2316
|
+
// Choose the overlay engine before classification/allocation. A shim which
|
|
2317
|
+
// merely starts but exits non-zero used to trigger an enormous cp -a
|
|
2318
|
+
// fallback, then fail later at overlay, so a broken rsync still stops here.
|
|
2319
|
+
// No rsync at all (stock Windows) uses the built-in copy instead.
|
|
2320
|
+
const copyEngine = selectOverlayCopyEngine(env, out, err);
|
|
2250
2321
|
// The release clone uses `--filter=blob:none`, which needs git 2.19+. Check
|
|
2251
2322
|
// before the prompt so an old git fails with a plain message instead of a
|
|
2252
2323
|
// clone usage dump. A newer git later on PATH is pinned after the scratch
|
|
@@ -2716,9 +2787,9 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
|
|
|
2716
2787
|
];
|
|
2717
2788
|
// Exercise the exact overlay command before any classified delete/move. A
|
|
2718
2789
|
// Cygwin path conversion or filter failure therefore leaves the root intact.
|
|
2719
|
-
const overlayPreflight =
|
|
2790
|
+
const overlayPreflight = runOverlayCopy(copyEngine, ["--dry-run", ...overlayArgs], srcDir, hqRoot, env);
|
|
2720
2791
|
if (overlayPreflight.status !== 0) {
|
|
2721
|
-
reportRsyncFailure(overlayPreflight.status, "dry-run", overlayPreflight.stderr, err);
|
|
2792
|
+
reportRsyncFailure(overlayPreflight.status, "dry-run", overlayPreflight.stderr, err, copyEngine.kind);
|
|
2722
2793
|
throw new ExitError(overlayPreflight.status || 1);
|
|
2723
2794
|
}
|
|
2724
2795
|
ctx.actions = buildRescueActions(ctx);
|
|
@@ -2780,7 +2851,7 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
|
|
|
2780
2851
|
if (postRestore.problem) {
|
|
2781
2852
|
err(`error: post-restore permit is not usable: ${postRestore.problem}\n`);
|
|
2782
2853
|
}
|
|
2783
|
-
const proof = recoveryProof(unresolved, cfg, hqRoot, srcDir, srcSha,
|
|
2854
|
+
const proof = recoveryProof(unresolved, cfg, hqRoot, srcDir, srcSha, copyEngine, rsyncExcludes, env);
|
|
2784
2855
|
if (proof.eligible && proof.failures.length === 0) {
|
|
2785
2856
|
out("==> Recovery proof passed: interrupted update matches the release and preserved paths; continuing.\n");
|
|
2786
2857
|
err("HQ_RESCUE_NOTE=recovery-proof-passed\n");
|
|
@@ -2985,10 +3056,10 @@ function doRescue(cfg, env, out, err, setTmp, retainTmp, gitReachabilityProbeTim
|
|
|
2985
3056
|
toCygwinRsyncPath(hqRoot + "/"),
|
|
2986
3057
|
]
|
|
2987
3058
|
: overlayArgs;
|
|
2988
|
-
const overlay =
|
|
3059
|
+
const overlay = runOverlayCopy(copyEngine, overlayRunArgs, srcDir, hqRoot, env);
|
|
2989
3060
|
if (overlay.status !== 0) {
|
|
2990
3061
|
// bash runs under set -e: a failed rsync aborts with its status.
|
|
2991
|
-
reportRsyncFailure(overlay.status, "overlay", overlay.stderr, err);
|
|
3062
|
+
reportRsyncFailure(overlay.status, "overlay", overlay.stderr, err, copyEngine.kind);
|
|
2992
3063
|
if (restoreOnRsyncFailure) {
|
|
2993
3064
|
const manifest = backupDir ? readSnapshotManifest(backupDir, hqRoot) : null;
|
|
2994
3065
|
if (!manifest || hasSkippedSnapshotEntries(manifest)) {
|
|
@@ -4980,30 +5051,26 @@ function precomputeGitMaps(ctx, wipeToplevel) {
|
|
|
4980
5051
|
ctx.localShas = new Map();
|
|
4981
5052
|
return;
|
|
4982
5053
|
}
|
|
4983
|
-
// Pass 1: floor existence + blob SHA for every rel, in
|
|
5054
|
+
// Pass 1: floor existence + blob SHA for every rel, in chunked batches.
|
|
4984
5055
|
// `cat-file --batch-check` prints "<sha> <type> <size>" for a present object
|
|
4985
|
-
// or "<input> missing" otherwise, one line per input in order. This
|
|
4986
|
-
//
|
|
5056
|
+
// or "<input> missing" otherwise, one line per input in order. This
|
|
5057
|
+
// replaces BOTH the per-file `cat-file -e` (existence) and `rev-parse`
|
|
4987
5058
|
// (sha). It reads only the git object DB — never local file contents — so it
|
|
4988
|
-
// stays cheap even on a 100k-file wipe set.
|
|
5059
|
+
// stays cheap even on a 100k-file wipe set. A batch failure aborts the
|
|
5060
|
+
// rescue before anything is touched: falling back to per-file spawns across
|
|
5061
|
+
// a wipe set this size would mean tens of thousands of git processes and a
|
|
5062
|
+
// machine-wide slowdown for the better part of an hour.
|
|
4989
5063
|
const floorShas = new Map();
|
|
4990
5064
|
if (allRels.length > 0) {
|
|
4991
|
-
const
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
if (line === "" || line.endsWith(" missing")) {
|
|
5001
|
-
floorShas.set(allRels[i], null);
|
|
5002
|
-
}
|
|
5003
|
-
else {
|
|
5004
|
-
const sha = line.split(" ")[0];
|
|
5005
|
-
floorShas.set(allRels[i], sha || null);
|
|
5006
|
-
}
|
|
5065
|
+
const lines = runGitBatchOrAbort(["cat-file", "--batch-check"], allRels.map((rel) => `${ctx.historyFloor}:${rel}`), { cwd: ctx.srcDir, env: ctx.env });
|
|
5066
|
+
for (let i = 0; i < allRels.length; i++) {
|
|
5067
|
+
const line = lines[i];
|
|
5068
|
+
if (line === "" || line.endsWith(" missing")) {
|
|
5069
|
+
floorShas.set(allRels[i], null);
|
|
5070
|
+
}
|
|
5071
|
+
else {
|
|
5072
|
+
const sha = line.split(" ")[0];
|
|
5073
|
+
floorShas.set(allRels[i], sha || null);
|
|
5007
5074
|
}
|
|
5008
5075
|
}
|
|
5009
5076
|
}
|
|
@@ -5023,22 +5090,55 @@ function precomputeGitMaps(ctx, wipeToplevel) {
|
|
|
5023
5090
|
hashAbs.push(fileAbs[i]);
|
|
5024
5091
|
}
|
|
5025
5092
|
}
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
if (res.status === 0) {
|
|
5032
|
-
const lines = res.stdout.split("\n");
|
|
5033
|
-
for (let i = 0; i < hashRels.length; i++) {
|
|
5034
|
-
const sha = (lines[i] ?? "").trim();
|
|
5035
|
-
if (sha)
|
|
5036
|
-
localShas.set(hashRels[i], sha);
|
|
5037
|
-
}
|
|
5038
|
-
}
|
|
5093
|
+
const hashes = hashLocalFilesInChunks(hashAbs, ctx.env, (msg) => process.stderr.write(msg));
|
|
5094
|
+
for (let i = 0; i < hashRels.length; i++) {
|
|
5095
|
+
const sha = hashes[i];
|
|
5096
|
+
if (sha)
|
|
5097
|
+
localShas.set(hashRels[i], sha);
|
|
5039
5098
|
}
|
|
5040
5099
|
ctx.localShas = localShas;
|
|
5041
5100
|
}
|
|
5101
|
+
/**
|
|
5102
|
+
* Blob SHA for each local file, in order; "" where the file could not be
|
|
5103
|
+
* hashed. `git hash-object --stdin-paths` stops at the first file it cannot
|
|
5104
|
+
* open (a cloud placeholder, a permission-denied file, one deleted mid-walk),
|
|
5105
|
+
* so a chunk that fails is retried one file at a time. That bounds the
|
|
5106
|
+
* per-file spawns to one chunk, and an unhashable file simply stays out of
|
|
5107
|
+
* the map, which classifyOne treats as a local edit.
|
|
5108
|
+
*/
|
|
5109
|
+
export function hashLocalFilesInChunks(absPaths, env, warn, chunkSize = GIT_BATCH_CHUNK_SIZE) {
|
|
5110
|
+
const out = [];
|
|
5111
|
+
for (let start = 0; start < absPaths.length; start += chunkSize) {
|
|
5112
|
+
const chunk = absPaths.slice(start, start + chunkSize);
|
|
5113
|
+
let lines;
|
|
5114
|
+
try {
|
|
5115
|
+
lines = runGitBatch(["hash-object", "--stdin-paths"], chunk, {
|
|
5116
|
+
env,
|
|
5117
|
+
chunkSize,
|
|
5118
|
+
});
|
|
5119
|
+
}
|
|
5120
|
+
catch (e) {
|
|
5121
|
+
if (!(e instanceof GitBatchError))
|
|
5122
|
+
throw e;
|
|
5123
|
+
warn(`warning: batched hash of ${chunk.length} files failed (${e.message.split("\n").slice(-1)[0]}); hashing them one at a time\n`);
|
|
5124
|
+
lines = chunk.map((abs) => run("git", ["hash-object", abs], { env }).stdout);
|
|
5125
|
+
}
|
|
5126
|
+
for (const line of lines)
|
|
5127
|
+
out.push(line.trim());
|
|
5128
|
+
}
|
|
5129
|
+
return out;
|
|
5130
|
+
}
|
|
5131
|
+
function runGitBatchOrAbort(args, inputs, opts) {
|
|
5132
|
+
try {
|
|
5133
|
+
return runGitBatch(args, inputs, opts);
|
|
5134
|
+
}
|
|
5135
|
+
catch (e) {
|
|
5136
|
+
if (!(e instanceof GitBatchError))
|
|
5137
|
+
throw e;
|
|
5138
|
+
process.stderr.write(`\nERROR: batched git lookup failed while classifying ${inputs.length} paths; aborting before any file is touched.\n${e.message}\n`);
|
|
5139
|
+
throw new ExitError(1);
|
|
5140
|
+
}
|
|
5141
|
+
}
|
|
5042
5142
|
function walkAndProcess(ctx, rootRel) {
|
|
5043
5143
|
const rootAbs = path.join(ctx.hqRoot, rootRel);
|
|
5044
5144
|
if (!lexists(rootAbs))
|
|
@@ -6369,9 +6469,15 @@ function rescuePathsOverlap(first, second) {
|
|
|
6369
6469
|
function isSkippedSnapshotPath(ctx, rel) {
|
|
6370
6470
|
return ctx.skippedSnapshotRels.some((skippedRel) => rescuePathsOverlap(rel, skippedRel));
|
|
6371
6471
|
}
|
|
6372
|
-
|
|
6472
|
+
/**
|
|
6473
|
+
* Protect one path from the overlay with an exact rsync exclude. rsync reads
|
|
6474
|
+
* backslash escapes only in a pattern that holds a wildcard (`*`, `?`, `[`,
|
|
6475
|
+
* or the `/***` suffix of a recursive entry), so escape only then; a plain
|
|
6476
|
+
* name with a backslash is compared literally and must stay as it is.
|
|
6477
|
+
*/
|
|
6478
|
+
export function appendLiteralRsyncExclude(excludeList, rel, recursive = false) {
|
|
6373
6479
|
let pattern = rel;
|
|
6374
|
-
if (/[
|
|
6480
|
+
if (recursive || /[*?[]/.test(pattern)) {
|
|
6375
6481
|
pattern = pattern
|
|
6376
6482
|
.replace(/\\/g, "\\\\")
|
|
6377
6483
|
.replace(/([*?[])/g, "\\$1");
|