Add rsync exit code awareness + plan operation abstraction
- spawn.js: rsync() wrapper handles exit codes 0/24 as OK, 23 as fatal - spawn.js: capture() accepts allowedExitCodes option - run.js: all rsync calls go through rsync() wrapper - PLAN.md: document planned operation abstraction refactor
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
import { mkdir, writeFile } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { run as spawn, capture } from '../spawn.js';
|
||||
import { run as spawn, rsync } from '../spawn.js';
|
||||
import { parseItemize } from '../itemize.js';
|
||||
import { getBackend } from '../backends/index.js';
|
||||
import { readState, writeState, PHASES } from '../state.js';
|
||||
@@ -33,28 +33,22 @@ export async function runCommand(config) {
|
||||
// ── Phase 2: rsync PREV → PEND (local seed, with delete) ────
|
||||
await setPhase(deltas, state, PHASES.RSYNC_LOCAL, dry);
|
||||
console.log('\n── rsync PREV → PEND (local seed) ──');
|
||||
await spawn('rsync', ['-aP', '--delete', trailingSlash(prev), trailingSlash(pend)], { dryRun: dry });
|
||||
await rsync(['-aP', '--delete', trailingSlash(prev), trailingSlash(pend)], { dryRun: dry });
|
||||
|
||||
// ── Phase 3: rsync SOURCE → PEND, capture change list ───────
|
||||
await setPhase(deltas, state, PHASES.RSYNC_REMOTE, dry);
|
||||
console.log('\n── rsync SOURCE → PEND ──');
|
||||
|
||||
let changes = [];
|
||||
const output = await rsync(
|
||||
['-aP', '--itemize-changes', '--delete', trailingSlash(source), trailingSlash(pend)],
|
||||
{ dryRun: dry, capture: true },
|
||||
);
|
||||
const changes = dry ? [] : parseItemize(output);
|
||||
if (!dry) {
|
||||
const rsyncArgs = [
|
||||
'-aP',
|
||||
'--itemize-changes',
|
||||
'--delete',
|
||||
trailingSlash(source),
|
||||
trailingSlash(pend),
|
||||
];
|
||||
const output = await capture('rsync', rsyncArgs);
|
||||
changes = parseItemize(output);
|
||||
console.log(` ${changes.length} file(s) changed`);
|
||||
for (const c of changes) console.log(` [${c.status}] ${c.path}`);
|
||||
} else {
|
||||
console.log(`$ rsync -aP --itemize-changes --delete ${trailingSlash(source)} ${trailingSlash(pend)}`);
|
||||
console.log('[dry-run] (change list will be determined at runtime)');
|
||||
console.log(' [dry-run] change list determined at runtime');
|
||||
}
|
||||
|
||||
// ── Phase 4: Generate per-file deltas into DELTAS/tmp/N/ ────
|
||||
@@ -132,7 +126,7 @@ export async function runCommand(config) {
|
||||
// ── Phase 6: Promote PEND → PREV ────────────────────────────
|
||||
await setPhase(deltas, state, PHASES.PROMOTING, dry);
|
||||
console.log('\n── Promote PEND → PREV ──');
|
||||
await spawn('rsync', ['-aP', '--delete', trailingSlash(pend), trailingSlash(prev)], { dryRun: dry });
|
||||
await rsync(['-aP', '--delete', trailingSlash(pend), trailingSlash(prev)], { dryRun: dry });
|
||||
|
||||
// ── Done ─────────────────────────────────────────────────────
|
||||
state.last_complete = seq;
|
||||
|
||||
Reference in New Issue
Block a user