mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 14:56:29 +00:00
Merge pull request #3970 from MichaelEischer/split-retry-backend
Split backend package into smaller parts
This commit is contained in:
commit
2e9ee8577a
@ -22,6 +22,7 @@ import (
|
||||
"github.com/restic/restic/internal/backend/location"
|
||||
"github.com/restic/restic/internal/backend/rclone"
|
||||
"github.com/restic/restic/internal/backend/rest"
|
||||
"github.com/restic/restic/internal/backend/retry"
|
||||
"github.com/restic/restic/internal/backend/s3"
|
||||
"github.com/restic/restic/internal/backend/sftp"
|
||||
"github.com/restic/restic/internal/backend/swift"
|
||||
@ -445,7 +446,7 @@ func OpenRepository(ctx context.Context, opts GlobalOptions) (*repository.Reposi
|
||||
success := func(msg string, retries int) {
|
||||
Warnf("%v operation successful after %d retries\n", msg, retries)
|
||||
}
|
||||
be = backend.NewRetryBackend(be, 10, report, success)
|
||||
be = retry.New(be, 10, report, success)
|
||||
|
||||
// wrap backend if a test specified a hook
|
||||
if opts.backendTestHook != nil {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/backend/retry"
|
||||
"github.com/restic/restic/internal/options"
|
||||
"github.com/restic/restic/internal/repository"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
@ -172,7 +172,7 @@ func withTestEnvironment(t testing.TB) (env *testEnvironment, cleanup func()) {
|
||||
|
||||
repository.TestUseLowSecurityKDFParameters(t)
|
||||
restic.TestDisableCheckPolynomial(t)
|
||||
backend.TestFastRetries(t)
|
||||
retry.TestFastRetries(t)
|
||||
|
||||
tempdir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-")
|
||||
rtest.OK(t, err)
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/backend/layout"
|
||||
"github.com/restic/restic/internal/backend/sema"
|
||||
"github.com/restic/restic/internal/debug"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
@ -30,7 +31,7 @@ type Backend struct {
|
||||
sem sema.Semaphore
|
||||
prefix string
|
||||
listMaxItems int
|
||||
backend.Layout
|
||||
layout.Layout
|
||||
}
|
||||
|
||||
const defaultListMaxItems = 5000
|
||||
@ -85,7 +86,7 @@ func open(cfg Config, rt http.RoundTripper) (*Backend, error) {
|
||||
connections: cfg.Connections,
|
||||
sem: sem,
|
||||
prefix: cfg.Prefix,
|
||||
Layout: &backend.DefaultLayout{
|
||||
Layout: &layout.DefaultLayout{
|
||||
Path: cfg.Prefix,
|
||||
Join: path.Join,
|
||||
},
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/backend/layout"
|
||||
"github.com/restic/restic/internal/backend/sema"
|
||||
"github.com/restic/restic/internal/debug"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
@ -25,7 +26,7 @@ type b2Backend struct {
|
||||
bucket *b2.Bucket
|
||||
cfg Config
|
||||
listMaxItems int
|
||||
backend.Layout
|
||||
layout.Layout
|
||||
sem sema.Semaphore
|
||||
}
|
||||
|
||||
@ -97,7 +98,7 @@ func Open(ctx context.Context, cfg Config, rt http.RoundTripper) (restic.Backend
|
||||
client: client,
|
||||
bucket: bucket,
|
||||
cfg: cfg,
|
||||
Layout: &backend.DefaultLayout{
|
||||
Layout: &layout.DefaultLayout{
|
||||
Join: path.Join,
|
||||
Path: cfg.Prefix,
|
||||
},
|
||||
@ -138,7 +139,7 @@ func Create(ctx context.Context, cfg Config, rt http.RoundTripper) (restic.Backe
|
||||
client: client,
|
||||
bucket: bucket,
|
||||
cfg: cfg,
|
||||
Layout: &backend.DefaultLayout{
|
||||
Layout: &layout.DefaultLayout{
|
||||
Join: path.Join,
|
||||
Path: cfg.Prefix,
|
||||
},
|
||||
|
@ -1,84 +0,0 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"sync"
|
||||
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
)
|
||||
|
||||
// ErrorBackend is used to induce errors into various function calls and test
|
||||
// the retry functions.
|
||||
type ErrorBackend struct {
|
||||
FailSave float32
|
||||
FailSaveRead float32
|
||||
FailLoad float32
|
||||
FailStat float32
|
||||
restic.Backend
|
||||
|
||||
r *rand.Rand
|
||||
m sync.Mutex
|
||||
}
|
||||
|
||||
// statically ensure that ErrorBackend implements restic.Backend.
|
||||
var _ restic.Backend = &ErrorBackend{}
|
||||
|
||||
// NewErrorBackend wraps be with a backend that returns errors according to
|
||||
// given probabilities.
|
||||
func NewErrorBackend(be restic.Backend, seed int64) *ErrorBackend {
|
||||
return &ErrorBackend{
|
||||
Backend: be,
|
||||
r: rand.New(rand.NewSource(seed)),
|
||||
}
|
||||
}
|
||||
|
||||
func (be *ErrorBackend) fail(p float32) bool {
|
||||
be.m.Lock()
|
||||
v := be.r.Float32()
|
||||
be.m.Unlock()
|
||||
|
||||
return v < p
|
||||
}
|
||||
|
||||
// Save stores the data in the backend under the given handle.
|
||||
func (be *ErrorBackend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error {
|
||||
if be.fail(be.FailSave) {
|
||||
return errors.Errorf("Save(%v) random error induced", h)
|
||||
}
|
||||
|
||||
if be.fail(be.FailSaveRead) {
|
||||
_, err := io.CopyN(ioutil.Discard, rd, be.r.Int63n(1000))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return errors.Errorf("Save(%v) random error with partial read induced", h)
|
||||
}
|
||||
|
||||
return be.Backend.Save(ctx, h, rd)
|
||||
}
|
||||
|
||||
// Load returns a reader that yields the contents of the file at h at the
|
||||
// given offset. If length is larger than zero, only a portion of the file
|
||||
// is returned. rd must be closed after use. If an error is returned, the
|
||||
// ReadCloser must be nil.
|
||||
func (be *ErrorBackend) Load(ctx context.Context, h restic.Handle, length int, offset int64, consumer func(rd io.Reader) error) error {
|
||||
if be.fail(be.FailLoad) {
|
||||
return errors.Errorf("Load(%v, %v, %v) random error induced", h, length, offset)
|
||||
}
|
||||
|
||||
return be.Backend.Load(ctx, h, length, offset, consumer)
|
||||
}
|
||||
|
||||
// Stat returns information about the File identified by h.
|
||||
func (be *ErrorBackend) Stat(ctx context.Context, h restic.Handle) (restic.FileInfo, error) {
|
||||
if be.fail(be.FailLoad) {
|
||||
return restic.FileInfo{}, errors.Errorf("Stat(%v) random error induced", h)
|
||||
}
|
||||
|
||||
return be.Stat(ctx, h)
|
||||
}
|
@ -14,6 +14,7 @@ import (
|
||||
"cloud.google.com/go/storage"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/backend/layout"
|
||||
"github.com/restic/restic/internal/backend/sema"
|
||||
"github.com/restic/restic/internal/debug"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
@ -41,7 +42,7 @@ type Backend struct {
|
||||
bucket *storage.BucketHandle
|
||||
prefix string
|
||||
listMaxItems int
|
||||
backend.Layout
|
||||
layout.Layout
|
||||
}
|
||||
|
||||
// Ensure that *Backend implements restic.Backend.
|
||||
@ -111,7 +112,7 @@ func open(cfg Config, rt http.RoundTripper) (*Backend, error) {
|
||||
bucketName: cfg.Bucket,
|
||||
bucket: gcsClient.Bucket(cfg.Bucket),
|
||||
prefix: cfg.Prefix,
|
||||
Layout: &backend.DefaultLayout{
|
||||
Layout: &layout.DefaultLayout{
|
||||
Path: cfg.Prefix,
|
||||
Join: path.Join,
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
package backend
|
||||
package layout
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package backend
|
||||
package layout
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
@ -1,4 +1,4 @@
|
||||
package backend
|
||||
package layout
|
||||
|
||||
import "github.com/restic/restic/internal/restic"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package backend
|
||||
package layout
|
||||
|
||||
import "github.com/restic/restic/internal/restic"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package backend
|
||||
package layout
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -362,15 +362,15 @@ func TestDetectLayout(t *testing.T) {
|
||||
filename string
|
||||
want string
|
||||
}{
|
||||
{"repo-layout-default.tar.gz", "*backend.DefaultLayout"},
|
||||
{"repo-layout-s3legacy.tar.gz", "*backend.S3LegacyLayout"},
|
||||
{"repo-layout-default.tar.gz", "*layout.DefaultLayout"},
|
||||
{"repo-layout-s3legacy.tar.gz", "*layout.S3LegacyLayout"},
|
||||
}
|
||||
|
||||
var fs = &LocalFilesystem{}
|
||||
for _, test := range tests {
|
||||
for _, fs := range []Filesystem{fs, nil} {
|
||||
t.Run(fmt.Sprintf("%v/fs-%T", test.filename, fs), func(t *testing.T) {
|
||||
rtest.SetupTarTestFixture(t, path, filepath.Join("testdata", test.filename))
|
||||
rtest.SetupTarTestFixture(t, path, filepath.Join("../testdata", test.filename))
|
||||
|
||||
layout, err := DetectLayout(context.TODO(), fs, filepath.Join(path, "repo"))
|
||||
if err != nil {
|
||||
@ -401,12 +401,12 @@ func TestParseLayout(t *testing.T) {
|
||||
defaultLayoutName string
|
||||
want string
|
||||
}{
|
||||
{"default", "", "*backend.DefaultLayout"},
|
||||
{"s3legacy", "", "*backend.S3LegacyLayout"},
|
||||
{"", "", "*backend.DefaultLayout"},
|
||||
{"default", "", "*layout.DefaultLayout"},
|
||||
{"s3legacy", "", "*layout.S3LegacyLayout"},
|
||||
{"", "", "*layout.DefaultLayout"},
|
||||
}
|
||||
|
||||
rtest.SetupTarTestFixture(t, path, filepath.Join("testdata", "repo-layout-default.tar.gz"))
|
||||
rtest.SetupTarTestFixture(t, path, filepath.Join("..", "testdata", "repo-layout-default.tar.gz"))
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.layoutName, func(t *testing.T) {
|
@ -10,6 +10,7 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/backend/layout"
|
||||
"github.com/restic/restic/internal/backend/sema"
|
||||
"github.com/restic/restic/internal/debug"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
@ -23,7 +24,7 @@ import (
|
||||
type Local struct {
|
||||
Config
|
||||
sem sema.Semaphore
|
||||
backend.Layout
|
||||
layout.Layout
|
||||
backend.Modes
|
||||
}
|
||||
|
||||
@ -33,7 +34,7 @@ var _ restic.Backend = &Local{}
|
||||
const defaultLayout = "default"
|
||||
|
||||
func open(ctx context.Context, cfg Config) (*Local, error) {
|
||||
l, err := backend.ParseLayout(ctx, &backend.LocalFilesystem{}, cfg.Layout, defaultLayout, cfg.Path)
|
||||
l, err := layout.ParseLayout(ctx, &layout.LocalFilesystem{}, cfg.Layout, defaultLayout, cfg.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2,25 +2,6 @@ package backend
|
||||
|
||||
import "os"
|
||||
|
||||
// Paths contains the default paths for file-based backends (e.g. local).
|
||||
var Paths = struct {
|
||||
Data string
|
||||
Snapshots string
|
||||
Index string
|
||||
Locks string
|
||||
Keys string
|
||||
Temp string
|
||||
Config string
|
||||
}{
|
||||
"data",
|
||||
"snapshots",
|
||||
"index",
|
||||
"locks",
|
||||
"keys",
|
||||
"tmp",
|
||||
"config",
|
||||
}
|
||||
|
||||
type Modes struct {
|
||||
Dir os.FileMode
|
||||
File os.FileMode
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/backend/layout"
|
||||
"github.com/restic/restic/internal/backend/sema"
|
||||
"github.com/restic/restic/internal/debug"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
@ -32,7 +32,7 @@ type Backend struct {
|
||||
connections uint
|
||||
sem sema.Semaphore
|
||||
client http.Client
|
||||
backend.Layout
|
||||
layout.Layout
|
||||
}
|
||||
|
||||
// the REST API protocol version is decided by HTTP request headers, these are the constants.
|
||||
@ -57,7 +57,7 @@ func Open(cfg Config, rt http.RoundTripper) (*Backend, error) {
|
||||
be := &Backend{
|
||||
url: cfg.URL,
|
||||
client: http.Client{Transport: rt},
|
||||
Layout: &backend.RESTLayout{URL: url, Join: path.Join},
|
||||
Layout: &layout.RESTLayout{URL: url, Join: path.Join},
|
||||
connections: cfg.Connections,
|
||||
sem: sem,
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package backend
|
||||
package retry
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -11,9 +11,9 @@ import (
|
||||
"github.com/restic/restic/internal/restic"
|
||||
)
|
||||
|
||||
// RetryBackend retries operations on the backend in case of an error with a
|
||||
// Backend retries operations on the backend in case of an error with a
|
||||
// backoff.
|
||||
type RetryBackend struct {
|
||||
type Backend struct {
|
||||
restic.Backend
|
||||
MaxTries int
|
||||
Report func(string, error, time.Duration)
|
||||
@ -21,14 +21,14 @@ type RetryBackend struct {
|
||||
}
|
||||
|
||||
// statically ensure that RetryBackend implements restic.Backend.
|
||||
var _ restic.Backend = &RetryBackend{}
|
||||
var _ restic.Backend = &Backend{}
|
||||
|
||||
// NewRetryBackend wraps be with a backend that retries operations after a
|
||||
// New wraps be with a backend that retries operations after a
|
||||
// backoff. report is called with a description and the error, if one occurred.
|
||||
// success is called with the number of retries before a successful operation
|
||||
// (it is not called if it succeeded on the first try)
|
||||
func NewRetryBackend(be restic.Backend, maxTries int, report func(string, error, time.Duration), success func(string, int)) *RetryBackend {
|
||||
return &RetryBackend{
|
||||
func New(be restic.Backend, maxTries int, report func(string, error, time.Duration), success func(string, int)) *Backend {
|
||||
return &Backend{
|
||||
Backend: be,
|
||||
MaxTries: maxTries,
|
||||
Report: report,
|
||||
@ -57,7 +57,7 @@ func retryNotifyErrorWithSuccess(operation backoff.Operation, b backoff.BackOff,
|
||||
|
||||
var fastRetries = false
|
||||
|
||||
func (be *RetryBackend) retry(ctx context.Context, msg string, f func() error) error {
|
||||
func (be *Backend) retry(ctx context.Context, msg string, f func() error) error {
|
||||
// Don't do anything when called with an already cancelled context. There would be
|
||||
// no retries in that case either, so be consistent and abort always.
|
||||
// This enforces a strict contract for backend methods: Using a cancelled context
|
||||
@ -92,7 +92,7 @@ func (be *RetryBackend) retry(ctx context.Context, msg string, f func() error) e
|
||||
}
|
||||
|
||||
// Save stores the data in the backend under the given handle.
|
||||
func (be *RetryBackend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error {
|
||||
func (be *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error {
|
||||
return be.retry(ctx, fmt.Sprintf("Save(%v)", h), func() error {
|
||||
err := rd.Rewind()
|
||||
if err != nil {
|
||||
@ -125,7 +125,7 @@ func (be *RetryBackend) Save(ctx context.Context, h restic.Handle, rd restic.Rew
|
||||
// given offset. If length is larger than zero, only a portion of the file
|
||||
// is returned. rd must be closed after use. If an error is returned, the
|
||||
// ReadCloser must be nil.
|
||||
func (be *RetryBackend) Load(ctx context.Context, h restic.Handle, length int, offset int64, consumer func(rd io.Reader) error) (err error) {
|
||||
func (be *Backend) Load(ctx context.Context, h restic.Handle, length int, offset int64, consumer func(rd io.Reader) error) (err error) {
|
||||
return be.retry(ctx, fmt.Sprintf("Load(%v, %v, %v)", h, length, offset),
|
||||
func() error {
|
||||
return be.Backend.Load(ctx, h, length, offset, consumer)
|
||||
@ -133,7 +133,7 @@ func (be *RetryBackend) Load(ctx context.Context, h restic.Handle, length int, o
|
||||
}
|
||||
|
||||
// Stat returns information about the File identified by h.
|
||||
func (be *RetryBackend) Stat(ctx context.Context, h restic.Handle) (fi restic.FileInfo, err error) {
|
||||
func (be *Backend) Stat(ctx context.Context, h restic.Handle) (fi restic.FileInfo, err error) {
|
||||
err = be.retry(ctx, fmt.Sprintf("Stat(%v)", h),
|
||||
func() error {
|
||||
var innerError error
|
||||
@ -145,14 +145,14 @@ func (be *RetryBackend) Stat(ctx context.Context, h restic.Handle) (fi restic.Fi
|
||||
}
|
||||
|
||||
// Remove removes a File with type t and name.
|
||||
func (be *RetryBackend) Remove(ctx context.Context, h restic.Handle) (err error) {
|
||||
func (be *Backend) Remove(ctx context.Context, h restic.Handle) (err error) {
|
||||
return be.retry(ctx, fmt.Sprintf("Remove(%v)", h), func() error {
|
||||
return be.Backend.Remove(ctx, h)
|
||||
})
|
||||
}
|
||||
|
||||
// Test a boolean value whether a File with the name and type exists.
|
||||
func (be *RetryBackend) Test(ctx context.Context, h restic.Handle) (exists bool, err error) {
|
||||
func (be *Backend) Test(ctx context.Context, h restic.Handle) (exists bool, err error) {
|
||||
err = be.retry(ctx, fmt.Sprintf("Test(%v)", h), func() error {
|
||||
var innerError error
|
||||
exists, innerError = be.Backend.Test(ctx, h)
|
||||
@ -166,7 +166,7 @@ func (be *RetryBackend) Test(ctx context.Context, h restic.Handle) (exists bool,
|
||||
// error is returned by the underlying backend, the request is retried. When fn
|
||||
// returns an error, the operation is aborted and the error is returned to the
|
||||
// caller.
|
||||
func (be *RetryBackend) List(ctx context.Context, t restic.FileType, fn func(restic.FileInfo) error) error {
|
||||
func (be *Backend) List(ctx context.Context, t restic.FileType, fn func(restic.FileInfo) error) error {
|
||||
// create a new context that we can cancel when fn returns an error, so
|
||||
// that listing is aborted
|
||||
listCtx, cancel := context.WithCancel(ctx)
|
@ -1,4 +1,4 @@
|
||||
package backend
|
||||
package retry
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -36,7 +36,7 @@ func TestBackendSaveRetry(t *testing.T) {
|
||||
}
|
||||
|
||||
TestFastRetries(t)
|
||||
retryBackend := NewRetryBackend(be, 10, nil, nil)
|
||||
retryBackend := New(be, 10, nil, nil)
|
||||
|
||||
data := test.Random(23, 5*1024*1024+11241)
|
||||
err := retryBackend.Save(context.TODO(), restic.Handle{}, restic.NewByteReader(data, be.Hasher()))
|
||||
@ -72,7 +72,7 @@ func TestBackendSaveRetryAtomic(t *testing.T) {
|
||||
}
|
||||
|
||||
TestFastRetries(t)
|
||||
retryBackend := NewRetryBackend(be, 10, nil, nil)
|
||||
retryBackend := New(be, 10, nil, nil)
|
||||
|
||||
data := test.Random(23, 5*1024*1024+11241)
|
||||
err := retryBackend.Save(context.TODO(), restic.Handle{}, restic.NewByteReader(data, be.Hasher()))
|
||||
@ -106,7 +106,7 @@ func TestBackendListRetry(t *testing.T) {
|
||||
}
|
||||
|
||||
TestFastRetries(t)
|
||||
retryBackend := NewRetryBackend(be, 10, nil, nil)
|
||||
retryBackend := New(be, 10, nil, nil)
|
||||
|
||||
var listed []string
|
||||
err := retryBackend.List(context.TODO(), restic.PackFile, func(fi restic.FileInfo) error {
|
||||
@ -136,7 +136,7 @@ func TestBackendListRetryErrorFn(t *testing.T) {
|
||||
}
|
||||
|
||||
TestFastRetries(t)
|
||||
retryBackend := NewRetryBackend(be, 10, nil, nil)
|
||||
retryBackend := New(be, 10, nil, nil)
|
||||
|
||||
var ErrTest = errors.New("test error")
|
||||
|
||||
@ -193,7 +193,7 @@ func TestBackendListRetryErrorBackend(t *testing.T) {
|
||||
|
||||
TestFastRetries(t)
|
||||
const maxRetries = 2
|
||||
retryBackend := NewRetryBackend(be, maxRetries, nil, nil)
|
||||
retryBackend := New(be, maxRetries, nil, nil)
|
||||
|
||||
var listed []string
|
||||
err := retryBackend.List(context.TODO(), restic.PackFile, func(fi restic.FileInfo) error {
|
||||
@ -263,7 +263,7 @@ func TestBackendLoadRetry(t *testing.T) {
|
||||
}
|
||||
|
||||
TestFastRetries(t)
|
||||
retryBackend := NewRetryBackend(be, 10, nil, nil)
|
||||
retryBackend := New(be, 10, nil, nil)
|
||||
|
||||
var buf []byte
|
||||
err := retryBackend.Load(context.TODO(), restic.Handle{}, 0, 0, func(rd io.Reader) (err error) {
|
||||
@ -283,7 +283,7 @@ func TestBackendCanceledContext(t *testing.T) {
|
||||
// unimplemented mock backend functions return an error by default
|
||||
// check that we received the expected context canceled error instead
|
||||
TestFastRetries(t)
|
||||
retryBackend := NewRetryBackend(mock.NewBackend(), 2, nil, nil)
|
||||
retryBackend := New(mock.NewBackend(), 2, nil, nil)
|
||||
h := restic.Handle{Type: restic.PackFile, Name: restic.NewRandomID().String()}
|
||||
|
||||
// create an already canceled context
|
@ -1,4 +1,4 @@
|
||||
package backend
|
||||
package retry
|
||||
|
||||
import "testing"
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/backend/layout"
|
||||
"github.com/restic/restic/internal/backend/sema"
|
||||
"github.com/restic/restic/internal/debug"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
@ -28,7 +29,7 @@ type Backend struct {
|
||||
client *minio.Client
|
||||
sem sema.Semaphore
|
||||
cfg Config
|
||||
backend.Layout
|
||||
layout.Layout
|
||||
}
|
||||
|
||||
// make sure that *Backend implements backend.Backend
|
||||
@ -113,7 +114,7 @@ func open(ctx context.Context, cfg Config, rt http.RoundTripper) (*Backend, erro
|
||||
cfg: cfg,
|
||||
}
|
||||
|
||||
l, err := backend.ParseLayout(ctx, be, cfg.Layout, defaultLayout, cfg.Prefix)
|
||||
l, err := layout.ParseLayout(ctx, be, cfg.Layout, defaultLayout, cfg.Prefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -514,7 +515,7 @@ func (be *Backend) Delete(ctx context.Context) error {
|
||||
func (be *Backend) Close() error { return nil }
|
||||
|
||||
// Rename moves a file based on the new layout l.
|
||||
func (be *Backend) Rename(ctx context.Context, h restic.Handle, l backend.Layout) error {
|
||||
func (be *Backend) Rename(ctx context.Context, h restic.Handle, l layout.Layout) error {
|
||||
debug.Log("Rename %v to %v", h, l)
|
||||
oldname := be.Filename(h)
|
||||
newname := l.Filename(h)
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/backend/layout"
|
||||
"github.com/restic/restic/internal/backend/sema"
|
||||
"github.com/restic/restic/internal/debug"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
@ -35,7 +36,7 @@ type SFTP struct {
|
||||
posixRename bool
|
||||
|
||||
sem sema.Semaphore
|
||||
backend.Layout
|
||||
layout.Layout
|
||||
Config
|
||||
backend.Modes
|
||||
}
|
||||
@ -144,14 +145,14 @@ func open(ctx context.Context, sftp *SFTP, cfg Config) (*SFTP, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sftp.Layout, err = backend.ParseLayout(ctx, sftp, cfg.Layout, defaultLayout, cfg.Path)
|
||||
sftp.Layout, err = layout.ParseLayout(ctx, sftp, cfg.Layout, defaultLayout, cfg.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
debug.Log("layout: %v\n", sftp.Layout)
|
||||
|
||||
fi, err := sftp.c.Stat(Join(cfg.Path, backend.Paths.Config))
|
||||
fi, err := sftp.c.Stat(sftp.Layout.Filename(restic.Handle{Type: restic.ConfigFile}))
|
||||
m := backend.DeriveModesFromFileInfo(fi, err)
|
||||
debug.Log("using (%03O file, %03O dir) permissions", m.File, m.Dir)
|
||||
|
||||
@ -243,7 +244,7 @@ func Create(ctx context.Context, cfg Config) (*SFTP, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sftp.Layout, err = backend.ParseLayout(ctx, sftp, cfg.Layout, defaultLayout, cfg.Path)
|
||||
sftp.Layout, err = layout.ParseLayout(ctx, sftp, cfg.Layout, defaultLayout, cfg.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -251,7 +252,7 @@ func Create(ctx context.Context, cfg Config) (*SFTP, error) {
|
||||
sftp.Modes = backend.DefaultModes
|
||||
|
||||
// test if config file already exists
|
||||
_, err = sftp.c.Lstat(Join(cfg.Path, backend.Paths.Config))
|
||||
_, err = sftp.c.Lstat(sftp.Layout.Filename(restic.Handle{Type: restic.ConfigFile}))
|
||||
if err == nil {
|
||||
return nil, errors.New("config file already exists")
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/backend/layout"
|
||||
"github.com/restic/restic/internal/backend/sema"
|
||||
"github.com/restic/restic/internal/debug"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
@ -30,7 +31,7 @@ type beSwift struct {
|
||||
sem sema.Semaphore
|
||||
container string // Container name
|
||||
prefix string // Prefix of object names in the container
|
||||
backend.Layout
|
||||
layout.Layout
|
||||
}
|
||||
|
||||
// ensure statically that *beSwift implements restic.Backend.
|
||||
@ -74,7 +75,7 @@ func Open(ctx context.Context, cfg Config, rt http.RoundTripper) (restic.Backend
|
||||
sem: sem,
|
||||
container: cfg.Container,
|
||||
prefix: cfg.Prefix,
|
||||
Layout: &backend.DefaultLayout{
|
||||
Layout: &layout.DefaultLayout{
|
||||
Path: cfg.Prefix,
|
||||
Join: path.Join,
|
||||
},
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/backend/layout"
|
||||
"github.com/restic/restic/internal/backend/s3"
|
||||
"github.com/restic/restic/internal/cache"
|
||||
"github.com/restic/restic/internal/debug"
|
||||
@ -74,7 +74,7 @@ func retry(max int, fail func(err error), f func() error) error {
|
||||
// maxErrors for retrying renames on s3.
|
||||
const maxErrors = 20
|
||||
|
||||
func (m *S3Layout) moveFiles(ctx context.Context, be *s3.Backend, l backend.Layout, t restic.FileType) error {
|
||||
func (m *S3Layout) moveFiles(ctx context.Context, be *s3.Backend, l layout.Layout, t restic.FileType) error {
|
||||
printErr := func(err error) {
|
||||
fmt.Fprintf(os.Stderr, "renaming file returned error: %v\n", err)
|
||||
}
|
||||
@ -97,12 +97,12 @@ func (m *S3Layout) Apply(ctx context.Context, repo restic.Repository) error {
|
||||
return errors.New("backend is not s3")
|
||||
}
|
||||
|
||||
oldLayout := &backend.S3LegacyLayout{
|
||||
oldLayout := &layout.S3LegacyLayout{
|
||||
Path: be.Path(),
|
||||
Join: path.Join,
|
||||
}
|
||||
|
||||
newLayout := &backend.DefaultLayout{
|
||||
newLayout := &layout.DefaultLayout{
|
||||
Path: be.Path(),
|
||||
Join: path.Join,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user