- package.json (ESM, bin entry) - bin/delta-backup.js — entrypoint - lib/args.js — CLI arg parsing via Node parseArgs - lib/config.js — config file merging + required path guards - lib/spawn.js — safe process spawning (no shell strings) - lib/state.js — sequence number + phase state management - lib/backends/zstd.js — zstd delta backend - lib/backends/index.js — backend registry - lib/commands/run.js — full run skeleton (phases 1-3 wired, 4-6 stubbed) - lib/commands/status.js — status command
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
/**
|
|
* State management — tracks sequence numbers and run phases in DELTAS/state.json.
|
|
* The state file is a recoverable cache; source of truth is the DELTAS directory.
|
|
*/
|
|
import { readFile, writeFile } from 'fs/promises';
|
|
import { join } from 'path';
|
|
|
|
const STATE_FILE = 'state.json';
|
|
|
|
export async function readState(deltasDir) {
|
|
const path = join(deltasDir, STATE_FILE);
|
|
try {
|
|
const raw = await readFile(path, 'utf8');
|
|
return JSON.parse(raw);
|
|
} catch {
|
|
// Missing or unreadable — reconstruct from directory scan
|
|
return reconstructState(deltasDir);
|
|
}
|
|
}
|
|
|
|
export async function writeState(deltasDir, state) {
|
|
const path = join(deltasDir, STATE_FILE);
|
|
await writeFile(path, JSON.stringify(state, null, 2) + '\n', 'utf8');
|
|
}
|
|
|
|
async function reconstructState(deltasDir) {
|
|
// TODO: scan DELTAS for highest committed sequence number
|
|
// For now, start fresh
|
|
return { next_seq: 1, last_complete: 0, phase: 'idle' };
|
|
}
|
|
|
|
export const PHASES = {
|
|
IDLE: 'idle',
|
|
CLEARING_PEND: 'clearing_pend',
|
|
RSYNC_LOCAL: 'rsync_local',
|
|
RSYNC_REMOTE: 'rsync_remote',
|
|
GENERATING: 'generating_delta',
|
|
COMMITTING: 'committing',
|
|
PROMOTING: 'promoting_prev',
|
|
};
|