mirror of
https://github.com/garethgeorge/backrest.git
synced 2026-05-04 12:00:36 +00:00
fix: test repo configuration button
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()))
|
||||
|
||||
@@ -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 +
|
||||
|
||||
Reference in New Issue
Block a user