2016-08-31 17:10:10 +00:00
|
|
|
package restic
|
|
|
|
|
2017-06-03 15:39:57 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2020-12-19 11:39:48 +00:00
|
|
|
"hash"
|
2017-06-03 15:39:57 +00:00
|
|
|
"io"
|
|
|
|
)
|
2017-01-22 11:32:20 +00:00
|
|
|
|
2016-08-31 17:10:10 +00:00
|
|
|
// Backend is used to store and access data.
|
2020-12-16 12:58:02 +00:00
|
|
|
//
|
|
|
|
// Backend operations that return an error will be retried when a Backend is
|
|
|
|
// wrapped in a RetryBackend. To prevent that from happening, the operations
|
|
|
|
// should return a github.com/cenkalti/backoff/v4.PermanentError. Errors from
|
|
|
|
// the context package need not be wrapped, as context cancellation is checked
|
|
|
|
// separately by the retrying logic.
|
2016-08-31 17:10:10 +00:00
|
|
|
type Backend interface {
|
|
|
|
// Location returns a string that describes the type and location of the
|
|
|
|
// repository.
|
|
|
|
Location() string
|
|
|
|
|
2021-08-07 20:20:49 +00:00
|
|
|
// Connections returns the maxmimum number of concurrent backend operations.
|
|
|
|
Connections() uint
|
|
|
|
|
2020-12-19 11:39:48 +00:00
|
|
|
// Hasher may return a hash function for calculating a content hash for the backend
|
|
|
|
Hasher() hash.Hash
|
|
|
|
|
2022-05-01 18:07:29 +00:00
|
|
|
// HasAtomicReplace returns whether Save() can atomically replace files
|
|
|
|
HasAtomicReplace() bool
|
|
|
|
|
2017-12-22 17:34:17 +00:00
|
|
|
// Remove removes a File described by h.
|
2017-06-03 15:39:57 +00:00
|
|
|
Remove(ctx context.Context, h Handle) error
|
2016-08-31 17:10:10 +00:00
|
|
|
|
|
|
|
// Close the backend
|
|
|
|
Close() error
|
|
|
|
|
2018-03-03 13:20:54 +00:00
|
|
|
// Save stores the data from rd under the given handle.
|
|
|
|
Save(ctx context.Context, h Handle, rd RewindReader) error
|
2016-08-31 17:10:10 +00:00
|
|
|
|
2018-01-17 04:59:16 +00:00
|
|
|
// Load runs fn with a reader that yields the contents of the file at h at the
|
2017-01-23 16:20:08 +00:00
|
|
|
// given offset. If length is larger than zero, only a portion of the file
|
2018-01-17 04:59:16 +00:00
|
|
|
// is read.
|
|
|
|
//
|
|
|
|
// The function fn may be called multiple times during the same Load invocation
|
|
|
|
// and therefore must be idempotent.
|
|
|
|
//
|
|
|
|
// Implementations are encouraged to use backend.DefaultLoad
|
|
|
|
Load(ctx context.Context, h Handle, length int, offset int64, fn func(rd io.Reader) error) error
|
2017-01-22 21:01:12 +00:00
|
|
|
|
2016-08-31 18:29:54 +00:00
|
|
|
// Stat returns information about the File identified by h.
|
2017-06-03 15:39:57 +00:00
|
|
|
Stat(ctx context.Context, h Handle) (FileInfo, error)
|
2016-08-31 17:10:10 +00:00
|
|
|
|
2018-01-20 12:43:07 +00:00
|
|
|
// List runs fn for each file in the backend which has the type t. When an
|
|
|
|
// error occurs (or fn returns an error), List stops and returns it.
|
2018-01-23 20:21:54 +00:00
|
|
|
//
|
2018-01-24 15:25:40 +00:00
|
|
|
// The function fn is called exactly once for each file during successful
|
|
|
|
// execution and at most once in case of an error.
|
|
|
|
//
|
2018-01-23 20:21:54 +00:00
|
|
|
// The function fn is called in the same Goroutine that List() is called
|
|
|
|
// from.
|
2018-01-20 12:43:07 +00:00
|
|
|
List(ctx context.Context, t FileType, fn func(FileInfo) error) error
|
2017-06-15 11:40:27 +00:00
|
|
|
|
|
|
|
// IsNotExist returns true if the error was caused by a non-existing file
|
|
|
|
// in the backend.
|
2022-10-08 10:37:18 +00:00
|
|
|
//
|
|
|
|
// The argument may be a wrapped error. The implementation is responsible
|
|
|
|
// for unwrapping it.
|
2017-06-15 11:40:27 +00:00
|
|
|
IsNotExist(err error) bool
|
2017-10-14 11:38:17 +00:00
|
|
|
|
|
|
|
// Delete removes all data in the backend.
|
|
|
|
Delete(ctx context.Context) error
|
2016-08-31 17:10:10 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 12:43:07 +00:00
|
|
|
// FileInfo is contains information about a file in the backend.
|
|
|
|
type FileInfo struct {
|
|
|
|
Size int64
|
|
|
|
Name string
|
|
|
|
}
|