mirror of
https://github.com/restic/restic.git
synced 2026-07-17 12:44:54 +00:00
move Backend interface to backend package
This commit is contained in:
@@ -5,8 +5,8 @@ import (
|
||||
"hash"
|
||||
"io"
|
||||
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/debug"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
)
|
||||
|
||||
// Backend passes reads through to an underlying layer and accepts writes, but
|
||||
@@ -15,20 +15,20 @@ import (
|
||||
// the repo and does normal operations else.
|
||||
// This is used for `backup --dry-run`.
|
||||
type Backend struct {
|
||||
b restic.Backend
|
||||
b backend.Backend
|
||||
}
|
||||
|
||||
// statically ensure that Backend implements restic.Backend.
|
||||
var _ restic.Backend = &Backend{}
|
||||
// statically ensure that Backend implements backend.Backend.
|
||||
var _ backend.Backend = &Backend{}
|
||||
|
||||
func New(be restic.Backend) *Backend {
|
||||
func New(be backend.Backend) *Backend {
|
||||
b := &Backend{b: be}
|
||||
debug.Log("created new dry backend")
|
||||
return b
|
||||
}
|
||||
|
||||
// Save adds new Data to the backend.
|
||||
func (be *Backend) Save(_ context.Context, h restic.Handle, _ restic.RewindReader) error {
|
||||
func (be *Backend) Save(_ context.Context, h backend.Handle, _ backend.RewindReader) error {
|
||||
if err := h.Valid(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -38,7 +38,7 @@ func (be *Backend) Save(_ context.Context, h restic.Handle, _ restic.RewindReade
|
||||
}
|
||||
|
||||
// Remove deletes a file from the backend.
|
||||
func (be *Backend) Remove(_ context.Context, _ restic.Handle) error {
|
||||
func (be *Backend) Remove(_ context.Context, _ backend.Handle) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -72,14 +72,14 @@ func (be *Backend) IsNotExist(err error) bool {
|
||||
return be.b.IsNotExist(err)
|
||||
}
|
||||
|
||||
func (be *Backend) List(ctx context.Context, t restic.FileType, fn func(restic.FileInfo) error) error {
|
||||
func (be *Backend) List(ctx context.Context, t backend.FileType, fn func(backend.FileInfo) error) error {
|
||||
return be.b.List(ctx, t, fn)
|
||||
}
|
||||
|
||||
func (be *Backend) Load(ctx context.Context, h restic.Handle, length int, offset int64, fn func(io.Reader) error) error {
|
||||
func (be *Backend) Load(ctx context.Context, h backend.Handle, length int, offset int64, fn func(io.Reader) error) error {
|
||||
return be.b.Load(ctx, h, length, offset, fn)
|
||||
}
|
||||
|
||||
func (be *Backend) Stat(ctx context.Context, h restic.Handle) (restic.FileInfo, error) {
|
||||
func (be *Backend) Stat(ctx context.Context, h backend.Handle) (backend.FileInfo, error) {
|
||||
return be.b.Stat(ctx, h)
|
||||
}
|
||||
|
||||
@@ -8,16 +8,16 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/restic"
|
||||
"github.com/restic/restic/internal/backend"
|
||||
|
||||
"github.com/restic/restic/internal/backend/dryrun"
|
||||
"github.com/restic/restic/internal/backend/mem"
|
||||
)
|
||||
|
||||
// make sure that Backend implements backend.Backend
|
||||
var _ restic.Backend = &dryrun.Backend{}
|
||||
var _ backend.Backend = &dryrun.Backend{}
|
||||
|
||||
func newBackends() (*dryrun.Backend, restic.Backend) {
|
||||
func newBackends() (*dryrun.Backend, backend.Backend) {
|
||||
m := mem.New()
|
||||
return dryrun.New(m), m
|
||||
}
|
||||
@@ -30,7 +30,7 @@ func TestDry(t *testing.T) {
|
||||
// won't pass. Instead, perform a series of operations over the backend, testing the state
|
||||
// at each step.
|
||||
steps := []struct {
|
||||
be restic.Backend
|
||||
be backend.Backend
|
||||
op string
|
||||
fname string
|
||||
content string
|
||||
@@ -61,13 +61,13 @@ func TestDry(t *testing.T) {
|
||||
for i, step := range steps {
|
||||
var err error
|
||||
|
||||
handle := restic.Handle{Type: restic.PackFile, Name: step.fname}
|
||||
handle := backend.Handle{Type: backend.PackFile, Name: step.fname}
|
||||
switch step.op {
|
||||
case "save":
|
||||
err = step.be.Save(ctx, handle, restic.NewByteReader([]byte(step.content), step.be.Hasher()))
|
||||
err = step.be.Save(ctx, handle, backend.NewByteReader([]byte(step.content), step.be.Hasher()))
|
||||
case "list":
|
||||
fileList := []string{}
|
||||
err = step.be.List(ctx, restic.PackFile, func(fi restic.FileInfo) error {
|
||||
err = step.be.List(ctx, backend.PackFile, func(fi backend.FileInfo) error {
|
||||
fileList = append(fileList, fi.Name)
|
||||
return nil
|
||||
})
|
||||
@@ -86,7 +86,7 @@ func TestDry(t *testing.T) {
|
||||
case "remove":
|
||||
err = step.be.Remove(ctx, handle)
|
||||
case "stat":
|
||||
var fi restic.FileInfo
|
||||
var fi backend.FileInfo
|
||||
fi, err = step.be.Stat(ctx, handle)
|
||||
if err == nil {
|
||||
fis := fmt.Sprintf("%s %d", fi.Name, fi.Size)
|
||||
|
||||
Reference in New Issue
Block a user