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:
Michael Eischer
2026-06-20 19:15:40 +02:00
parent ea699bb0ba
commit 6c509f7ac1
15 changed files with 53 additions and 55 deletions
@@ -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})
}
+2 -2
View File
@@ -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)
+8 -8
View File
@@ -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")
}