2016-08-31 17:10:10 +00:00
|
|
|
package restic
|
|
|
|
|
2017-06-03 15:39:57 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2017-07-23 12:21:03 +00:00
|
|
|
|
|
|
|
"github.com/restic/restic/internal/crypto"
|
2022-05-26 10:49:03 +00:00
|
|
|
"github.com/restic/restic/internal/ui/progress"
|
2017-06-03 15:39:57 +00:00
|
|
|
)
|
2016-08-31 21:07:50 +00:00
|
|
|
|
2016-08-31 17:10:10 +00:00
|
|
|
// Repository stores data in a backend. It provides high-level functions and
|
|
|
|
// transparently encrypts/decrypts data.
|
|
|
|
type Repository interface {
|
|
|
|
|
|
|
|
// Backend returns the backend used by the repository
|
|
|
|
Backend() Backend
|
|
|
|
|
2016-08-31 21:07:50 +00:00
|
|
|
Key() *crypto.Key
|
|
|
|
|
2020-07-25 19:19:46 +00:00
|
|
|
Index() MasterIndex
|
2017-06-04 09:16:55 +00:00
|
|
|
LoadIndex(context.Context) error
|
2022-05-26 10:38:18 +00:00
|
|
|
SetIndex(MasterIndex) error
|
|
|
|
LookupBlobSize(ID, BlobType) (uint, bool)
|
2016-08-31 18:29:54 +00:00
|
|
|
|
|
|
|
Config() Config
|
|
|
|
|
2018-01-23 20:21:54 +00:00
|
|
|
// List calls the function fn for each file of type t in the repository.
|
|
|
|
// When an error is returned by fn, processing stops and List() returns the
|
|
|
|
// error.
|
|
|
|
//
|
|
|
|
// The function fn is called in the same Goroutine List() was called from.
|
|
|
|
List(ctx context.Context, t FileType, fn func(ID, int64) error) error
|
2020-11-16 03:03:45 +00:00
|
|
|
|
|
|
|
// ListPack returns the list of blobs saved in the pack id and the length of
|
|
|
|
// the the pack header.
|
|
|
|
ListPack(context.Context, ID, int64) ([]Blob, uint32, error)
|
2016-09-01 20:42:12 +00:00
|
|
|
|
2017-11-22 11:27:29 +00:00
|
|
|
Flush(context.Context) error
|
2016-09-01 20:42:12 +00:00
|
|
|
|
2017-06-04 09:16:55 +00:00
|
|
|
SaveUnpacked(context.Context, FileType, []byte) (ID, error)
|
|
|
|
SaveJSONUnpacked(context.Context, FileType, interface{}) (ID, error)
|
2016-08-31 18:29:54 +00:00
|
|
|
|
2019-03-24 20:59:14 +00:00
|
|
|
LoadJSONUnpacked(ctx context.Context, t FileType, id ID, dest interface{}) error
|
2022-02-12 23:01:27 +00:00
|
|
|
// LoadUnpacked loads and decrypts the file with the given type and ID,
|
2019-03-24 20:59:14 +00:00
|
|
|
// using the supplied buffer (which must be empty). If the buffer is nil, a
|
|
|
|
// new buffer will be allocated and returned.
|
2022-02-12 23:01:27 +00:00
|
|
|
LoadUnpacked(ctx context.Context, buf []byte, t FileType, id ID) (data []byte, err error)
|
2016-09-03 09:22:01 +00:00
|
|
|
|
2020-03-10 15:41:22 +00:00
|
|
|
LoadBlob(context.Context, BlobType, ID, []byte) ([]byte, error)
|
2020-06-06 20:20:44 +00:00
|
|
|
SaveBlob(context.Context, BlobType, []byte, ID, bool) (ID, bool, error)
|
2016-09-03 18:55:22 +00:00
|
|
|
|
2017-06-04 09:16:55 +00:00
|
|
|
LoadTree(context.Context, ID) (*Tree, error)
|
|
|
|
SaveTree(context.Context, *Tree) (ID, error)
|
2016-08-31 18:29:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-31 20:39:36 +00:00
|
|
|
// Lister allows listing files in a backend.
|
|
|
|
type Lister interface {
|
2018-01-20 12:43:07 +00:00
|
|
|
List(context.Context, FileType, func(FileInfo) error) error
|
2016-08-31 20:39:36 +00:00
|
|
|
}
|
|
|
|
|
2021-11-06 00:14:24 +00:00
|
|
|
// LoadJSONUnpackeder allows loading a JSON file not stored in a pack file
|
|
|
|
type LoadJSONUnpackeder interface {
|
|
|
|
LoadJSONUnpacked(ctx context.Context, t FileType, id ID, dest interface{}) error
|
|
|
|
}
|
|
|
|
|
2022-05-26 10:38:18 +00:00
|
|
|
// SaverUnpacked allows saving a blob not stored in a pack file
|
|
|
|
type SaverUnpacked interface {
|
|
|
|
SaveUnpacked(context.Context, FileType, []byte) (ID, error)
|
|
|
|
}
|
|
|
|
|
2021-08-20 08:09:34 +00:00
|
|
|
type PackBlobs struct {
|
|
|
|
PackID ID
|
|
|
|
Blobs []Blob
|
|
|
|
}
|
|
|
|
|
2020-07-25 19:19:46 +00:00
|
|
|
// MasterIndex keeps track of the blobs are stored within files.
|
|
|
|
type MasterIndex interface {
|
2020-11-05 21:18:00 +00:00
|
|
|
Has(BlobHandle) bool
|
|
|
|
Lookup(BlobHandle) []PackedBlob
|
2017-06-18 12:45:02 +00:00
|
|
|
|
|
|
|
// Each returns a channel that yields all blobs known to the index. When
|
|
|
|
// the context is cancelled, the background goroutine terminates. This
|
|
|
|
// blocks any modification of the index.
|
|
|
|
Each(ctx context.Context) <-chan PackedBlob
|
2021-08-20 08:09:34 +00:00
|
|
|
ListPacks(ctx context.Context, packs IDSet) <-chan PackBlobs
|
2022-05-26 10:49:03 +00:00
|
|
|
|
|
|
|
Save(ctx context.Context, repo SaverUnpacked, packBlacklist IDSet, extraObsolete IDs, p *progress.Counter) (obsolete IDSet, err error)
|
2016-08-31 18:29:54 +00:00
|
|
|
}
|