Implement restore execution for the restore subcommand

This commit is contained in:
2026-05-19 22:06:48 -05:00
parent 23d6470b0f
commit f3b63bd5e5
4 changed files with 534 additions and 7 deletions

View File

@@ -8,12 +8,14 @@ import (
"io"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
"gitea.maximumdirect.net/eric/narratio/internal/config"
)
var newObjectStoreFromConfigFn = storage.NewObjectStoreFromConfig
var discoverRemoteCurrentStateFn = discoverRemoteCurrentState
var buildRestorePlanFn = buildRestorePlan
var executeRestorePlanFn = executeRestorePlan
// Restore validates restore CLI/config inputs and storage preflight for future restore phases.
func Restore(ctx context.Context, args []string, out io.Writer) error {
@@ -93,16 +95,43 @@ func Restore(ctx context.Context, args []string, out io.Writer) error {
if dryRun {
return nil
}
artifactStore := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root)
if _, err := artifactStore.EnsureLayoutFor(cfg.Session.Campaign, cfg.Session.SessionID); err != nil {
return fmt.Errorf("restore: prepare workdir: %w", err)
}
lock, err := artifactStore.AcquireSessionLockFor(cfg.Session.Campaign, cfg.Session.SessionID)
if err != nil {
return fmt.Errorf("restore: acquire session lock: %w", err)
}
defer func() {
_ = artifactStore.ReleaseSessionLock(lock)
}()
if plan.ConflictCount > 0 && !force {
return fmt.Errorf(
"restore: plan has %d conflicting path(s); rerun with --force or resolve local conflicts",
plan.ConflictCount,
)
}
return fmt.Errorf(
"restore: planned remote restore for %s/%s (run %s); not yet implemented (phase 4: restore execution)",
result, err := executeRestorePlanFn(ctx, cfg, current, plan, objectStore)
if err != nil {
return fmt.Errorf("restore: execute plan: %w", err)
}
_, err = fmt.Fprintf(
out,
"restore complete: session %s/%s run=%s downloaded=%d skipped_same=%d conflicts=%d\n",
current.Campaign,
current.SessionID,
current.RunID,
result.DownloadedCount,
plan.SkipSameCount,
plan.ConflictCount,
)
if err != nil {
return fmt.Errorf("restore: write summary: %w", err)
}
return nil
}