2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 03:18:55 +00:00

Merge pull request #4331 from MichaelEischer/fix-mount-failures

Hopefully fix `TestMount` failures
This commit is contained in:
Michael Eischer 2023-05-18 20:22:57 +02:00 committed by GitHub
commit bfc9c6c971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 23 additions and 20 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/restic/restic/internal/backend" "github.com/restic/restic/internal/backend"
"github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
@ -236,5 +237,8 @@ func copyTree(ctx context.Context, srcRepo restic.Repository, dstRepo restic.Rep
bar := newProgressMax(!quiet, uint64(len(packList)), "packs copied") bar := newProgressMax(!quiet, uint64(len(packList)), "packs copied")
_, err = repository.Repack(ctx, srcRepo, dstRepo, packList, copyBlobs, bar) _, err = repository.Repack(ctx, srcRepo, dstRepo, packList, copyBlobs, bar)
bar.Done() bar.Done()
return err if err != nil {
return errors.Fatal(err.Error())
}
return nil
} }

View File

@ -93,7 +93,7 @@ func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, args []
PackSize: gopts.PackSize * 1024 * 1024, PackSize: gopts.PackSize * 1024 * 1024,
}) })
if err != nil { if err != nil {
return err return errors.Fatal(err.Error())
} }
err = s.Init(ctx, version, gopts.password, chunkerPolynomial) err = s.Init(ctx, version, gopts.password, chunkerPolynomial)

View File

@ -729,7 +729,7 @@ func doPrune(ctx context.Context, opts PruneOptions, gopts GlobalOptions, repo r
_, err := repository.Repack(ctx, repo, repo, plan.repackPacks, plan.keepBlobs, bar) _, err := repository.Repack(ctx, repo, repo, plan.repackPacks, plan.keepBlobs, bar)
bar.Done() bar.Done()
if err != nil { if err != nil {
return errors.Fatalf("%s", err) return errors.Fatal(err.Error())
} }
// Also remove repacked packs // Also remove repacked packs

View File

@ -456,7 +456,7 @@ func OpenRepository(ctx context.Context, opts GlobalOptions) (*repository.Reposi
PackSize: opts.PackSize * 1024 * 1024, PackSize: opts.PackSize * 1024 * 1024,
}) })
if err != nil { if err != nil {
return nil, err return nil, errors.Fatal(err.Error())
} }
passwordTriesLeft := 1 passwordTriesLeft := 1

View File

@ -62,7 +62,7 @@ func Create(ctx context.Context, cfg Config, rt http.RoundTripper) (*Backend, er
_, err = be.Stat(ctx, restic.Handle{Type: restic.ConfigFile}) _, err = be.Stat(ctx, restic.Handle{Type: restic.ConfigFile})
if err == nil { if err == nil {
return nil, errors.Fatal("config file already exists") return nil, errors.New("config file already exists")
} }
url := *cfg.URL url := *cfg.URL
@ -76,7 +76,7 @@ func Create(ctx context.Context, cfg Config, rt http.RoundTripper) (*Backend, er
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return nil, errors.Fatalf("server response unexpected: %v (%v)", resp.Status, resp.StatusCode) return nil, fmt.Errorf("server response unexpected: %v (%v)", resp.Status, resp.StatusCode)
} }
_, err = io.Copy(io.Discard, resp.Body) _, err = io.Copy(io.Discard, resp.Body)

View File

@ -80,7 +80,7 @@ func ParseConfig(s string) (interface{}, error) {
p := path.Clean(dir) p := path.Clean(dir)
if strings.HasPrefix(p, "~") { if strings.HasPrefix(p, "~") {
return nil, errors.Fatal("sftp path starts with the tilde (~) character, that fails for most sftp servers.\nUse a relative directory, most servers interpret this as relative to the user's home directory.") return nil, errors.New("sftp path starts with the tilde (~) character, that fails for most sftp servers.\nUse a relative directory, most servers interpret this as relative to the user's home directory")
} }
cfg := NewConfig() cfg := NewConfig()

View File

@ -21,7 +21,7 @@ var (
ErrNoKeyFound = errors.New("wrong password or no key found") ErrNoKeyFound = errors.New("wrong password or no key found")
// ErrMaxKeysReached is returned when the maximum number of keys was checked and no key could be found. // ErrMaxKeysReached is returned when the maximum number of keys was checked and no key could be found.
ErrMaxKeysReached = errors.Fatal("maximum number of keys reached") ErrMaxKeysReached = errors.New("maximum number of keys reached")
) )
// Key represents an encrypted master key for a repository. // Key represents an encrypted master key for a repository.

View File

@ -29,7 +29,7 @@ func Repack(ctx context.Context, repo restic.Repository, dstRepo restic.Reposito
debug.Log("repacking %d packs while keeping %d blobs", len(packs), keepBlobs.Len()) debug.Log("repacking %d packs while keeping %d blobs", len(packs), keepBlobs.Len())
if repo == dstRepo && dstRepo.Connections() < 2 { if repo == dstRepo && dstRepo.Connections() < 2 {
return nil, errors.Fatal("repack step requires a backend connection limit of at least two") return nil, errors.New("repack step requires a backend connection limit of at least two")
} }
wg, wgCtx := errgroup.WithContext(ctx) wg, wgCtx := errgroup.WithContext(ctx)

View File

@ -110,16 +110,16 @@ func (c *CompressionMode) Type() string {
// New returns a new repository with backend be. // New returns a new repository with backend be.
func New(be restic.Backend, opts Options) (*Repository, error) { func New(be restic.Backend, opts Options) (*Repository, error) {
if opts.Compression == CompressionInvalid { if opts.Compression == CompressionInvalid {
return nil, errors.Fatalf("invalid compression mode") return nil, errors.New("invalid compression mode")
} }
if opts.PackSize == 0 { if opts.PackSize == 0 {
opts.PackSize = DefaultPackSize opts.PackSize = DefaultPackSize
} }
if opts.PackSize > MaxPackSize { if opts.PackSize > MaxPackSize {
return nil, errors.Fatalf("pack size larger than limit of %v MiB", MaxPackSize/1024/1024) return nil, fmt.Errorf("pack size larger than limit of %v MiB", MaxPackSize/1024/1024)
} else if opts.PackSize < MinPackSize { } else if opts.PackSize < MinPackSize {
return nil, errors.Fatalf("pack size smaller than minimum of %v MiB", MinPackSize/1024/1024) return nil, fmt.Errorf("pack size smaller than minimum of %v MiB", MinPackSize/1024/1024)
} }
repo := &Repository{ repo := &Repository{
@ -593,7 +593,7 @@ func (r *Repository) LoadIndex(ctx context.Context) error {
}) })
if err != nil { if err != nil {
return errors.Fatal(err.Error()) return err
} }
err = r.idx.MergeFinalIndexes() err = r.idx.MergeFinalIndexes()
@ -613,7 +613,7 @@ func (r *Repository) LoadIndex(ctx context.Context) error {
} }
}) })
if invalidIndex { if invalidIndex {
return errors.Fatal("index uses feature not supported by repository version 1") return errors.New("index uses feature not supported by repository version 1")
} }
} }
@ -678,7 +678,7 @@ func (r *Repository) CreateIndexFromPacks(ctx context.Context, packsize map[rest
err = wg.Wait() err = wg.Wait()
if err != nil { if err != nil {
return invalid, errors.Fatal(err.Error()) return invalid, err
} }
return invalid, nil return invalid, nil
@ -723,9 +723,9 @@ func (r *Repository) SearchKey(ctx context.Context, password string, maxKeys int
r.keyID = key.ID() r.keyID = key.ID()
cfg, err := restic.LoadConfig(ctx, r) cfg, err := restic.LoadConfig(ctx, r)
if err == crypto.ErrUnauthenticated { if err == crypto.ErrUnauthenticated {
return errors.Fatalf("config or key %v is damaged: %v", key.ID(), err) return fmt.Errorf("config or key %v is damaged: %w", key.ID(), err)
} else if err != nil { } else if err != nil {
return errors.Fatalf("config cannot be loaded: %v", err) return fmt.Errorf("config cannot be loaded: %w", err)
} }
r.setConfig(cfg) r.setConfig(cfg)

View File

@ -2,10 +2,9 @@ package restic
import ( import (
"encoding/json" "encoding/json"
"fmt"
"sort" "sort"
"strings" "strings"
"github.com/restic/restic/internal/errors"
) )
type SnapshotGroupByOptions struct { type SnapshotGroupByOptions struct {
@ -26,7 +25,7 @@ func splitSnapshotGroupBy(s string) (SnapshotGroupByOptions, error) {
l.Tag = true l.Tag = true
case "": case "":
default: default:
return SnapshotGroupByOptions{}, errors.Fatal("unknown grouping option: '" + option + "'") return SnapshotGroupByOptions{}, fmt.Errorf("unknown grouping option: %q", option)
} }
} }
return l, nil return l, nil