summaryrefslogtreecommitdiff
path: root/internal/backend/dryrun/dry_backend.go
blob: f7acb10dd7ae7736b62ee7fa4d5990651d0bfb37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package dryrun

import (
	"context"
	"hash"
	"io"

	"github.com/restic/restic/internal/debug"
	"github.com/restic/restic/internal/restic"
)

// 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 {
	b restic.Backend
}

// statically ensure that Backend implements restic.Backend.
var _ restic.Backend = &Backend{}

func New(be restic.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 {
	if err := h.Valid(); err != nil {
		return err
	}

	// don't save anything, just return ok
	return nil
}

// Remove deletes a file from the backend.
func (be *Backend) Remove(_ context.Context, _ restic.Handle) error {
	return nil
}

func (be *Backend) Connections() uint {
	return be.b.Connections()
}

// Location returns the location of the backend.
func (be *Backend) Location() string {
	return "DRY:" + be.b.Location()
}

// Delete removes all data in the backend.
func (be *Backend) Delete(_ context.Context) error {
	return nil
}

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()
}

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 {
	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 {
	return be.b.Load(ctx, h, length, offset, fn)
}

func (be *Backend) Stat(ctx context.Context, h restic.Handle) (restic.FileInfo, error) {
	return be.b.Stat(ctx, h)
}