2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-11 07:41:03 +00:00
restic/internal/backend/dryrun/dry_backend.go

89 lines
2.2 KiB
Go
Raw Normal View History

package dryrun
import (
"context"
"hash"
"io"
"github.com/restic/restic/internal/debug"
2021-02-23 15:09:29 +00:00
"github.com/restic/restic/internal/restic"
)
2021-02-23 15:09:29 +00:00
// Backend passes reads through to an underlying layer and accepts writes, but
// doesn't do anything. Also removes are ignored.
// So in fact, this backend silently ignores all operations that would modify
// the repo and does normal operations else.
// This is used for `backup --dry-run`.
type Backend struct {
2021-02-23 15:09:29 +00:00
b restic.Backend
}
2021-02-23 15:09:29 +00:00
// statically ensure that RetryBackend implements restic.Backend.
var _ restic.Backend = &Backend{}
// New returns a new backend that saves all data in a map in memory.
func New(be restic.Backend) *Backend {
2021-02-23 15:09:29 +00:00
b := &Backend{b: be}
debug.Log("created new dry backend")
return b
}
// Save adds new Data to the backend.
func (be *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error {
if err := h.Valid(); err != nil {
return err
}
2021-02-23 15:09:29 +00:00
debug.Log("faked saving %v bytes at %v", rd.Length(), h)
2021-02-23 15:09:29 +00:00
// don't save anything, just return ok
return nil
}
// Remove deletes a file from the backend.
func (be *Backend) Remove(ctx context.Context, h restic.Handle) error {
return nil
}
2021-08-07 20:20:49 +00:00
func (be *Backend) Connections() uint {
return be.b.Connections()
}
2021-02-23 15:09:29 +00:00
// Location returns the location of the backend.
func (be *Backend) Location() string {
return "DRY:" + be.b.Location()
}
2021-02-23 15:09:29 +00:00
// Delete removes all data in the backend.
func (be *Backend) Delete(ctx context.Context) error {
return nil
}
2021-02-23 15:09:29 +00:00
func (be *Backend) Close() error {
return be.b.Close()
}
func (be *Backend) Hasher() hash.Hash {
return be.b.Hasher()
}
func (be *Backend) HasAtomicReplace() bool {
return be.b.HasAtomicReplace()
}
2021-02-23 15:09:29 +00:00
func (be *Backend) IsNotExist(err error) bool {
return be.b.IsNotExist(err)
}
2021-02-23 15:09:29 +00:00
func (be *Backend) List(ctx context.Context, t restic.FileType, fn func(restic.FileInfo) error) error {
return be.b.List(ctx, t, fn)
}
2021-02-23 15:09:29 +00:00
func (be *Backend) Load(ctx context.Context, h restic.Handle, length int, offset int64, fn func(io.Reader) error) error {
return be.b.Load(ctx, h, length, offset, fn)
}
2021-02-23 15:09:29 +00:00
func (be *Backend) Stat(ctx context.Context, h restic.Handle) (restic.FileInfo, error) {
return be.b.Stat(ctx, h)
}