From cbca7a7a50bac756eeebb5f1a75c465c38390f93 Mon Sep 17 00:00:00 2001 From: garethgeorge Date: Sat, 11 Jul 2026 21:20:37 -0700 Subject: [PATCH] fix: downloading files from a snapshot can fail if repoID has changed --- internal/api/downloadhandler.go | 13 +++++++++++-- internal/orchestrator/orchestrator.go | 11 +++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/internal/api/downloadhandler.go b/internal/api/downloadhandler.go index ca5a614c..81d9de72 100644 --- a/internal/api/downloadhandler.go +++ b/internal/api/downloadhandler.go @@ -54,7 +54,16 @@ func NewDownloadHandler(oplog *oplog.OpLog, orchestrator *orchestrator.Orchestra } func handleIndexSnapshotDownload(w http.ResponseWriter, r *http.Request, orchestrator *orchestrator.Orchestrator, op *v1.Operation, indexOp *v1.Operation_OperationIndexSnapshot, filePath string) { - repoCfg, err := orchestrator.GetRepo(op.RepoId) + // Resolve the repo by GUID; the op may have been recorded under a repo id + // the repo is no longer configured with. + repoID := op.RepoId + if op.RepoGuid != "" { + if byGuid, err := orchestrator.GetRepoByGUID(op.RepoGuid); err == nil { + repoID = byGuid.Id + } + } + + repoCfg, err := orchestrator.GetRepo(repoID) if err != nil { http.Error(w, "error getting repo", http.StatusInternalServerError) return @@ -65,7 +74,7 @@ func handleIndexSnapshotDownload(w http.ResponseWriter, r *http.Request, orchest return } - repo, err := orchestrator.GetRepoOrchestrator(op.RepoId) + repo, err := orchestrator.GetRepoOrchestrator(repoID) if err != nil { http.Error(w, "error getting repo", http.StatusInternalServerError) return diff --git a/internal/orchestrator/orchestrator.go b/internal/orchestrator/orchestrator.go index 367070e4..86e48ff7 100644 --- a/internal/orchestrator/orchestrator.go +++ b/internal/orchestrator/orchestrator.go @@ -355,6 +355,17 @@ func (o *Orchestrator) GetRepo(repoID string) (*v1.Repo, error) { return repo, nil } +func (o *Orchestrator) GetRepoByGUID(guid string) (*v1.Repo, error) { + o.mu.Lock() + defer o.mu.Unlock() + + repo := config.FindRepoByGUID(o.config, guid) + if repo == nil { + return nil, fmt.Errorf("get repo by guid %q: %w", guid, ErrRepoNotFound) + } + return repo, nil +} + func (o *Orchestrator) GetPlan(planID string) (*v1.Plan, error) { o.mu.Lock() defer o.mu.Unlock()