diff --git a/internal/api/backresthandler.go b/internal/api/backresthandler.go index ae53a721..749ca6b1 100644 --- a/internal/api/backresthandler.go +++ b/internal/api/backresthandler.go @@ -9,6 +9,7 @@ import ( "os" "path" "reflect" + "slices" "time" "connectrpc.com/connect" @@ -99,8 +100,15 @@ func (s *BackrestHandler) AddRepo(ctx context.Context, req *connect.Request[v1.R return nil, fmt.Errorf("failed to get config: %w", err) } + // Deep copy the configuration c = proto.Clone(c).(*v1.Config) - c.Repos = append(c.Repos, req.Msg) + + // Add or implicit update the repo + if idx := slices.IndexFunc(c.Repos, func(r *v1.Repo) bool { return r.Id == req.Msg.Id }); idx != -1 { + c.Repos[idx] = req.Msg + } else { + c.Repos = append(c.Repos, req.Msg) + } if err := config.ValidateConfig(c); err != nil { return nil, fmt.Errorf("validation error: %w", err) diff --git a/webui/src/views/AddRepoModal.tsx b/webui/src/views/AddRepoModal.tsx index 1dcf1f2b..f62b2ded 100644 --- a/webui/src/views/AddRepoModal.tsx +++ b/webui/src/views/AddRepoModal.tsx @@ -106,15 +106,8 @@ export const AddRepoModal = ({ template }: { template: Repo | null }) => { }); if (template !== null) { - const configCopy = config.clone(); - // We are in the edit repo flow, update the repo in the config - const idx = configCopy.repos!.findIndex((r) => r.id === template!.id); - if (idx === -1) { - alertsApi.error("Can't update repo, not found"); - return; - } - configCopy.repos![idx] = repo; - setConfig(await backrestService.setConfig(configCopy)); + // We are in the update repo flow, update the repo via the service + setConfig(await backrestService.addRepo(repo)); showModal(null); alertsApi.success("Updated repo configuration " + repo.uri); } else {