Restore prepared inputs and flat session products
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
)
|
||||
@@ -60,6 +63,13 @@ func restoreSessionState(ctx context.Context, cfg *config.Config, opts RestorePl
|
||||
if err != nil {
|
||||
return diagnostic, fmt.Errorf("restore: %w", err)
|
||||
}
|
||||
if current == nil || len(current.ManifestData) == 0 {
|
||||
return diagnostic, fmt.Errorf("restore: verified remote session manifest is required")
|
||||
}
|
||||
destinationRoot := artifacts.SessionWorkDirForCampaign(cfg.Pipeline.Workspace.Root, cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if _, err := prepareRestoredManifest(ctx, cfg, current, bytes.NewReader(current.ManifestData), destinationRoot, true); err != nil {
|
||||
return diagnostic, fmt.Errorf("restore: validate remote session manifest: %w", err)
|
||||
}
|
||||
manifestPath := artifacts.SessionManifestPathForCampaign(cfg.Pipeline.Workspace.Root, cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if _, _, err := loadManifestAtPathIfPresent(ctx, &manifest.LocalStore{}, manifestPath); err != nil {
|
||||
return diagnostic, fmt.Errorf("restore: %w", err)
|
||||
@@ -126,11 +136,26 @@ func restoreSessionState(ctx context.Context, cfg *config.Config, opts RestorePl
|
||||
|
||||
diagnostic = report
|
||||
|
||||
restoreRunID, err := artifacts.NewRunID()
|
||||
if err != nil {
|
||||
return diagnostic, fmt.Errorf("restore: generate diagnostic run id: %w", err)
|
||||
}
|
||||
sessionPaths := artifactStore.SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if _, err := fileops.BeginAttemptViews(sessionPaths.Root, restoreRunID, "restore"); err != nil {
|
||||
return diagnostic, fmt.Errorf("restore: prepare diagnostic views: %w", err)
|
||||
}
|
||||
report.reportPathRel = filepath.ToSlash(filepath.Join("runs", restoreRunID, "restore", "logs", "restore.json"))
|
||||
defer func() {
|
||||
if resultErr != nil {
|
||||
report.setFailed(resultErr)
|
||||
_, reportErr := persistRestoreReport(artifactStore, cfg, report)
|
||||
resultErr = errors.Join(resultErr, reportErr)
|
||||
}
|
||||
}()
|
||||
|
||||
if plan.ConflictCount > 0 {
|
||||
conflictErr := fmt.Errorf("restore conflict: %d conflicting path(s); --force can replace eligible regular files but not unresolved conflicts (download=%d skip_same=%d conflicts=%d)", plan.ConflictCount, plan.DownloadCount, plan.SkipSameCount, plan.ConflictCount)
|
||||
report.setFailed(conflictErr)
|
||||
_, reportErr := persistRestoreReport(artifactStore, cfg, report)
|
||||
return diagnostic, errors.Join(conflictErr, reportErr)
|
||||
return diagnostic, conflictErr
|
||||
}
|
||||
if err := writeRestoreMarker(artifactStore.SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)); err != nil {
|
||||
return diagnostic, fmt.Errorf("restore: mark incomplete restore: %w", err)
|
||||
@@ -139,10 +164,6 @@ func restoreSessionState(ctx context.Context, cfg *config.Config, opts RestorePl
|
||||
result, err := deps.executeRestorePlan(ctx, cfg, current, plan, report, objectStore)
|
||||
err = errors.Join(err, ctx.Err())
|
||||
if err != nil {
|
||||
report.setFailed(err)
|
||||
if _, reportErr := persistRestoreReport(artifactStore, cfg, report); reportErr != nil {
|
||||
return diagnostic, fmt.Errorf("restore: execute plan and persist report: %w", errors.Join(err, reportErr))
|
||||
}
|
||||
return diagnostic, fmt.Errorf("restore: execute plan: %w", err)
|
||||
}
|
||||
if result == nil {
|
||||
|
||||
Reference in New Issue
Block a user