fix: test repo configuration button
Build Snapshot Release / build (push) Waiting to run
Release Please / release-please (push) Waiting to run
Test / test-nix (push) Waiting to run
Test / test-win (push) Waiting to run

This commit is contained in:
Gareth George
2025-01-22 22:46:10 -08:00
parent 99264b2469
commit b3cfef1405
3 changed files with 14 additions and 2 deletions
+8 -1
View File
@@ -20,6 +20,7 @@ import (
"github.com/garethgeorge/backrest/gen/go/v1/v1connect"
syncapi "github.com/garethgeorge/backrest/internal/api/syncapi"
"github.com/garethgeorge/backrest/internal/config"
"github.com/garethgeorge/backrest/internal/cryptoutil"
"github.com/garethgeorge/backrest/internal/env"
"github.com/garethgeorge/backrest/internal/logstore"
"github.com/garethgeorge/backrest/internal/oplog"
@@ -108,6 +109,10 @@ func (s *BackrestHandler) CheckRepoExists(ctx context.Context, req *connect.Requ
c.Repos = append(c.Repos, req.Msg)
}
if req.Msg.Guid == "" {
req.Msg.Guid = cryptoutil.MustRandomID(cryptoutil.DefaultIDBits)
}
if err := config.ValidateConfig(c); err != nil {
return nil, fmt.Errorf("validation error: %w", err)
}
@@ -126,7 +131,9 @@ func (s *BackrestHandler) CheckRepoExists(ctx context.Context, req *connect.Requ
defer cancel()
if err := r.Exists(ctx); err != nil {
if strings.Contains(err.Error(), "repository does not exist") {
zap.S().Debugf("repo %q exists or not: %v", req.Msg.Id, err)
if errors.Is(err, restic.ErrRepoNotFound) {
zap.S().Debugf("repo %q does not exist", req.Msg.Id)
return connect.NewResponse(&types.BoolValue{Value: false}), nil
}
return nil, err
+5
View File
@@ -22,6 +22,7 @@ var errAlreadyInitialized = errors.New("repo already initialized")
var ErrPartialBackup = errors.New("incomplete backup")
var ErrBackupFailed = errors.New("backup failed")
var ErrRestoreFailed = errors.New("restore failed")
var ErrRepoNotFound = errors.New("repo does not exist")
type Repo struct {
cmd string
@@ -99,6 +100,10 @@ func (r *Repo) Exists(ctx context.Context, opts ...GenericOption) error {
cmd := r.commandWithContext(ctx, []string{"cat", "config"}, opts...)
r.pipeCmdOutputToWriter(cmd, output)
if err := cmd.Run(); err != nil {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) && exitErr.ExitCode() == 10 {
err = ErrRepoNotFound
}
r.exists = newCmdError(ctx, cmd, newErrorWithOutput(err, output.String()))
} else if err := json.Unmarshal(output.Bytes(), &r.repoConfig); err != nil {
r.exists = newCmdError(ctx, cmd, newErrorWithOutput(fmt.Errorf("command output is not valid JSON: %w", err), output.String()))
+1 -1
View File
@@ -209,7 +209,7 @@ export const AddRepoModal = ({ template }: { template: Repo | null }) => {
});
try {
const exists = await backrestService.checkRepoExists(repo);
if (exists) {
if (exists.value) {
alertsApi.success(
"Connected successfully to " +
repo.uri +