mirror of
https://github.com/restic/restic.git
synced 2026-09-29 07:20:30 +00:00
Correctly pair backend/restic.FileType with APIs
Use backend.FileType to interact with the backend. And restic.FileType to interact with the repository.
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/global"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
@@ -72,7 +71,7 @@ func (b *indexErrorBackend) Load(ctx context.Context, h backend.Handle, length i
|
||||
// protect hasErred
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
if !b.hasErred && h.Type == restic.IndexFile {
|
||||
if !b.hasErred && h.Type == backend.IndexFile {
|
||||
b.hasErred = true
|
||||
return consumer(errorReadCloser{rd})
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ func removePacks(gopts global.Options, t testing.TB, remove restic.IDSet) {
|
||||
defer unlock()
|
||||
|
||||
for id := range remove {
|
||||
rtest.OK(t, be().Remove(ctx, backend.Handle{Type: restic.PackFile, Name: id.String()}))
|
||||
rtest.OK(t, be().Remove(ctx, backend.Handle{Type: backend.PackFile, Name: id.String()}))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -329,7 +329,7 @@ func removePacksExcept(gopts global.Options, t testing.TB, keep restic.IDSet, re
|
||||
if treePacks.Has(id) != removeTreePacks || keep.Has(id) {
|
||||
return nil
|
||||
}
|
||||
return be().Remove(ctx, backend.Handle{Type: restic.PackFile, Name: id.String()})
|
||||
return be().Remove(ctx, backend.Handle{Type: backend.PackFile, Name: id.String()})
|
||||
})
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
|
||||
@@ -46,14 +46,14 @@ func TestCheckRestoreNoLock(t *testing.T) {
|
||||
// is expected by the first listing + some operations.
|
||||
type listOnceBackend struct {
|
||||
backend.Backend
|
||||
listedFileType map[restic.FileType]bool
|
||||
listedFileType map[backend.FileType]bool
|
||||
strictOrder bool
|
||||
}
|
||||
|
||||
func newListOnceBackend(be backend.Backend) *listOnceBackend {
|
||||
return &listOnceBackend{
|
||||
Backend: be,
|
||||
listedFileType: make(map[restic.FileType]bool),
|
||||
listedFileType: make(map[backend.FileType]bool),
|
||||
strictOrder: false,
|
||||
}
|
||||
}
|
||||
@@ -61,16 +61,16 @@ func newListOnceBackend(be backend.Backend) *listOnceBackend {
|
||||
func newOrderedListOnceBackend(be backend.Backend) *listOnceBackend {
|
||||
return &listOnceBackend{
|
||||
Backend: be,
|
||||
listedFileType: make(map[restic.FileType]bool),
|
||||
listedFileType: make(map[backend.FileType]bool),
|
||||
strictOrder: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (be *listOnceBackend) List(ctx context.Context, t restic.FileType, fn func(backend.FileInfo) error) error {
|
||||
if t != restic.LockFile && be.listedFileType[t] {
|
||||
func (be *listOnceBackend) List(ctx context.Context, t backend.FileType, fn func(backend.FileInfo) error) error {
|
||||
if t != backend.LockFile && be.listedFileType[t] {
|
||||
return errors.Errorf("tried listing type %v the second time", t)
|
||||
}
|
||||
if be.strictOrder && t == restic.SnapshotFile && be.listedFileType[restic.IndexFile] {
|
||||
if be.strictOrder && t == backend.SnapshotFile && be.listedFileType[backend.IndexFile] {
|
||||
return errors.Errorf("tried listing type snapshots after index")
|
||||
}
|
||||
be.listedFileType[t] = true
|
||||
@@ -194,7 +194,7 @@ type failConfigOnceBackend struct {
|
||||
func (be *failConfigOnceBackend) Load(ctx context.Context, h backend.Handle,
|
||||
length int, offset int64, fn func(rd io.Reader) error) error {
|
||||
|
||||
if !be.failedOnce && h.Type == restic.ConfigFile {
|
||||
if !be.failedOnce && h.Type == backend.ConfigFile {
|
||||
be.failedOnce = true
|
||||
return fmt.Errorf("oops")
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func (be *failConfigOnceBackend) Load(ctx context.Context, h backend.Handle,
|
||||
}
|
||||
|
||||
func (be *failConfigOnceBackend) Stat(ctx context.Context, h backend.Handle) (backend.FileInfo, error) {
|
||||
if !be.failedOnce && h.Type == restic.ConfigFile {
|
||||
if !be.failedOnce && h.Type == backend.ConfigFile {
|
||||
be.failedOnce = true
|
||||
return backend.FileInfo{}, fmt.Errorf("oops")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user