mirror of
https://github.com/restic/restic.git
synced 2025-12-04 01:11:56 +00:00
Rename 'Repo' -> 'Repository'
This commit is contained in:
@@ -49,12 +49,12 @@ type Key struct {
|
||||
|
||||
// createMasterKey creates a new master key in the given backend and encrypts
|
||||
// it with the password.
|
||||
func createMasterKey(s *Repo, password string) (*Key, error) {
|
||||
func createMasterKey(s *Repository, password string) (*Key, error) {
|
||||
return AddKey(s, password, nil)
|
||||
}
|
||||
|
||||
// OpenKey tries do decrypt the key specified by name with the given password.
|
||||
func OpenKey(s *Repo, name string, password string) (*Key, error) {
|
||||
func OpenKey(s *Repository, name string, password string) (*Key, error) {
|
||||
k, err := LoadKey(s, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -94,7 +94,7 @@ func OpenKey(s *Repo, name string, password string) (*Key, error) {
|
||||
|
||||
// SearchKey tries to decrypt all keys in the backend with the given password.
|
||||
// If none could be found, ErrNoKeyFound is returned.
|
||||
func SearchKey(s *Repo, password string) (*Key, error) {
|
||||
func SearchKey(s *Repository, password string) (*Key, error) {
|
||||
// try all keys in repo
|
||||
done := make(chan struct{})
|
||||
defer close(done)
|
||||
@@ -111,7 +111,7 @@ func SearchKey(s *Repo, password string) (*Key, error) {
|
||||
}
|
||||
|
||||
// LoadKey loads a key from the backend.
|
||||
func LoadKey(s *Repo, name string) (*Key, error) {
|
||||
func LoadKey(s *Repository, name string) (*Key, error) {
|
||||
// extract data from repo
|
||||
rd, err := s.be.Get(backend.Key, name)
|
||||
if err != nil {
|
||||
@@ -131,7 +131,7 @@ func LoadKey(s *Repo, name string) (*Key, error) {
|
||||
}
|
||||
|
||||
// AddKey adds a new key to an already existing repository.
|
||||
func AddKey(s *Repo, password string, template *crypto.Key) (*Key, error) {
|
||||
func AddKey(s *Repository, password string, template *crypto.Key) (*Key, error) {
|
||||
// fill meta data about key
|
||||
newkey := &Key{
|
||||
Created: time.Now(),
|
||||
|
||||
@@ -26,8 +26,8 @@ type Config struct {
|
||||
ChunkerPolynomial chunker.Pol `json:"chunker_polynomial"`
|
||||
}
|
||||
|
||||
// Repo is used to access a repository in a backend.
|
||||
type Repo struct {
|
||||
// Repository is used to access a repository in a backend.
|
||||
type Repository struct {
|
||||
be backend.Backend
|
||||
Config Config
|
||||
key *crypto.Key
|
||||
@@ -38,8 +38,8 @@ type Repo struct {
|
||||
packs []*pack.Packer
|
||||
}
|
||||
|
||||
func New(be backend.Backend) *Repo {
|
||||
return &Repo{
|
||||
func New(be backend.Backend) *Repository {
|
||||
return &Repository{
|
||||
be: be,
|
||||
idx: NewIndex(),
|
||||
}
|
||||
@@ -48,25 +48,25 @@ func New(be backend.Backend) *Repo {
|
||||
// Find loads the list of all blobs of type t and searches for names which start
|
||||
// with prefix. If none is found, nil and ErrNoIDPrefixFound is returned. If
|
||||
// more than one is found, nil and ErrMultipleIDMatches is returned.
|
||||
func (s *Repo) Find(t backend.Type, prefix string) (string, error) {
|
||||
func (s *Repository) Find(t backend.Type, prefix string) (string, error) {
|
||||
return backend.Find(s.be, t, prefix)
|
||||
}
|
||||
|
||||
// FindSnapshot takes a string and tries to find a snapshot whose ID matches
|
||||
// the string as closely as possible.
|
||||
func (s *Repo) FindSnapshot(name string) (string, error) {
|
||||
func (s *Repository) FindSnapshot(name string) (string, error) {
|
||||
return backend.FindSnapshot(s.be, name)
|
||||
}
|
||||
|
||||
// PrefixLength returns the number of bytes required so that all prefixes of
|
||||
// all IDs of type t are unique.
|
||||
func (s *Repo) PrefixLength(t backend.Type) (int, error) {
|
||||
func (s *Repository) PrefixLength(t backend.Type) (int, error) {
|
||||
return backend.PrefixLength(s.be, t)
|
||||
}
|
||||
|
||||
// Load tries to load and decrypt content identified by t and id from the
|
||||
// backend.
|
||||
func (s *Repo) Load(t backend.Type, id backend.ID) ([]byte, error) {
|
||||
func (s *Repository) Load(t backend.Type, id backend.ID) ([]byte, error) {
|
||||
debug.Log("Repo.Load", "load %v with id %v", t, id.Str())
|
||||
|
||||
// load blob from pack
|
||||
@@ -102,7 +102,7 @@ func (s *Repo) Load(t backend.Type, id backend.ID) ([]byte, error) {
|
||||
|
||||
// LoadBlob tries to load and decrypt content identified by t and id from a
|
||||
// pack from the backend.
|
||||
func (s *Repo) LoadBlob(t pack.BlobType, id backend.ID) ([]byte, error) {
|
||||
func (s *Repository) LoadBlob(t pack.BlobType, id backend.ID) ([]byte, error) {
|
||||
debug.Log("Repo.LoadBlob", "load %v with id %v", t, id.Str())
|
||||
// lookup pack
|
||||
packID, tpe, offset, length, err := s.idx.Lookup(id)
|
||||
@@ -151,7 +151,7 @@ func (s *Repo) LoadBlob(t pack.BlobType, id backend.ID) ([]byte, error) {
|
||||
|
||||
// LoadJSONUnpacked decrypts the data and afterwards calls json.Unmarshal on
|
||||
// the item.
|
||||
func (s *Repo) LoadJSONUnpacked(t backend.Type, id backend.ID, item interface{}) error {
|
||||
func (s *Repository) LoadJSONUnpacked(t backend.Type, id backend.ID, item interface{}) error {
|
||||
// load blob from backend
|
||||
rd, err := s.be.Get(t, id.String())
|
||||
if err != nil {
|
||||
@@ -178,7 +178,7 @@ func (s *Repo) LoadJSONUnpacked(t backend.Type, id backend.ID, item interface{})
|
||||
|
||||
// LoadJSONPack calls LoadBlob() to load a blob from the backend, decrypt the
|
||||
// data and afterwards call json.Unmarshal on the item.
|
||||
func (s *Repo) LoadJSONPack(t pack.BlobType, id backend.ID, item interface{}) error {
|
||||
func (s *Repository) LoadJSONPack(t pack.BlobType, id backend.ID, item interface{}) error {
|
||||
// lookup pack
|
||||
packID, _, offset, length, err := s.idx.Lookup(id)
|
||||
if err != nil {
|
||||
@@ -215,7 +215,7 @@ const maxPackers = 200
|
||||
|
||||
// findPacker returns a packer for a new blob of size bytes. Either a new one is
|
||||
// created or one is returned that already has some blobs.
|
||||
func (s *Repo) findPacker(size uint) (*pack.Packer, error) {
|
||||
func (s *Repository) findPacker(size uint) (*pack.Packer, error) {
|
||||
s.pm.Lock()
|
||||
defer s.pm.Unlock()
|
||||
|
||||
@@ -242,7 +242,7 @@ func (s *Repo) findPacker(size uint) (*pack.Packer, error) {
|
||||
}
|
||||
|
||||
// insertPacker appends p to s.packs.
|
||||
func (s *Repo) insertPacker(p *pack.Packer) {
|
||||
func (s *Repository) insertPacker(p *pack.Packer) {
|
||||
s.pm.Lock()
|
||||
defer s.pm.Unlock()
|
||||
|
||||
@@ -251,7 +251,7 @@ func (s *Repo) insertPacker(p *pack.Packer) {
|
||||
}
|
||||
|
||||
// savePacker stores p in the backend.
|
||||
func (s *Repo) savePacker(p *pack.Packer) error {
|
||||
func (s *Repository) savePacker(p *pack.Packer) error {
|
||||
debug.Log("Repo.savePacker", "save packer with %d blobs\n", p.Count())
|
||||
_, err := p.Finalize()
|
||||
if err != nil {
|
||||
@@ -278,7 +278,7 @@ func (s *Repo) savePacker(p *pack.Packer) error {
|
||||
}
|
||||
|
||||
// countPacker returns the number of open (unfinished) packers.
|
||||
func (s *Repo) countPacker() int {
|
||||
func (s *Repository) countPacker() int {
|
||||
s.pm.Lock()
|
||||
defer s.pm.Unlock()
|
||||
|
||||
@@ -287,7 +287,7 @@ func (s *Repo) countPacker() int {
|
||||
|
||||
// Save encrypts data and stores it to the backend as type t. If data is small
|
||||
// enough, it will be packed together with other small blobs.
|
||||
func (s *Repo) Save(t pack.BlobType, data []byte, id backend.ID) (backend.ID, error) {
|
||||
func (s *Repository) Save(t pack.BlobType, data []byte, id backend.ID) (backend.ID, error) {
|
||||
if id == nil {
|
||||
// compute plaintext hash
|
||||
id = backend.Hash(data)
|
||||
@@ -332,7 +332,7 @@ func (s *Repo) Save(t pack.BlobType, data []byte, id backend.ID) (backend.ID, er
|
||||
}
|
||||
|
||||
// SaveFrom encrypts data read from rd and stores it in a pack in the backend as type t.
|
||||
func (s *Repo) SaveFrom(t pack.BlobType, id backend.ID, length uint, rd io.Reader) error {
|
||||
func (s *Repository) SaveFrom(t pack.BlobType, id backend.ID, length uint, rd io.Reader) error {
|
||||
debug.Log("Repo.SaveFrom", "save id %v (%v, %d bytes)", id.Str(), t, length)
|
||||
if id == nil {
|
||||
return errors.New("id is nil")
|
||||
@@ -353,7 +353,7 @@ func (s *Repo) SaveFrom(t pack.BlobType, id backend.ID, length uint, rd io.Reade
|
||||
|
||||
// SaveJSON serialises item as JSON and encrypts and saves it in a pack in the
|
||||
// backend as type t.
|
||||
func (s *Repo) SaveJSON(t pack.BlobType, item interface{}) (backend.ID, error) {
|
||||
func (s *Repository) SaveJSON(t pack.BlobType, item interface{}) (backend.ID, error) {
|
||||
debug.Log("Repo.SaveJSON", "save %v blob", t)
|
||||
buf := getBuf()[:0]
|
||||
defer freeBuf(buf)
|
||||
@@ -372,7 +372,7 @@ func (s *Repo) SaveJSON(t pack.BlobType, item interface{}) (backend.ID, error) {
|
||||
|
||||
// SaveJSONUnpacked serialises item as JSON and encrypts and saves it in the
|
||||
// backend as type t, without a pack. It returns the storage hash.
|
||||
func (s *Repo) SaveJSONUnpacked(t backend.Type, item interface{}) (backend.ID, error) {
|
||||
func (s *Repository) SaveJSONUnpacked(t backend.Type, item interface{}) (backend.ID, error) {
|
||||
// create file
|
||||
blob, err := s.be.Create()
|
||||
if err != nil {
|
||||
@@ -409,7 +409,7 @@ func (s *Repo) SaveJSONUnpacked(t backend.Type, item interface{}) (backend.ID, e
|
||||
}
|
||||
|
||||
// Flush saves all remaining packs.
|
||||
func (s *Repo) Flush() error {
|
||||
func (s *Repository) Flush() error {
|
||||
s.pm.Lock()
|
||||
defer s.pm.Unlock()
|
||||
|
||||
@@ -426,22 +426,22 @@ func (s *Repo) Flush() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Repo) Backend() backend.Backend {
|
||||
func (s *Repository) Backend() backend.Backend {
|
||||
return s.be
|
||||
}
|
||||
|
||||
func (s *Repo) Index() *Index {
|
||||
func (s *Repository) Index() *Index {
|
||||
return s.idx
|
||||
}
|
||||
|
||||
// SetIndex instructs the repository to use the given index.
|
||||
func (s *Repo) SetIndex(i *Index) {
|
||||
func (s *Repository) SetIndex(i *Index) {
|
||||
s.idx = i
|
||||
}
|
||||
|
||||
// SaveIndex saves all new packs in the index in the backend, returned is the
|
||||
// storage ID.
|
||||
func (s *Repo) SaveIndex() (backend.ID, error) {
|
||||
func (s *Repository) SaveIndex() (backend.ID, error) {
|
||||
debug.Log("Repo.SaveIndex", "Saving index")
|
||||
|
||||
// create blob
|
||||
@@ -483,7 +483,7 @@ func (s *Repo) SaveIndex() (backend.ID, error) {
|
||||
|
||||
// LoadIndex loads all index files from the backend and merges them with the
|
||||
// current index.
|
||||
func (s *Repo) LoadIndex() error {
|
||||
func (s *Repository) LoadIndex() error {
|
||||
debug.Log("Repo.LoadIndex", "Loading index")
|
||||
done := make(chan struct{})
|
||||
defer close(done)
|
||||
@@ -498,7 +498,7 @@ func (s *Repo) LoadIndex() error {
|
||||
}
|
||||
|
||||
// loadIndex loads the index id and merges it with the currently used index.
|
||||
func (s *Repo) loadIndex(id string) error {
|
||||
func (s *Repository) loadIndex(id string) error {
|
||||
debug.Log("Repo.loadIndex", "Loading index %v", id[:8])
|
||||
before := len(s.idx.pack)
|
||||
|
||||
@@ -532,7 +532,7 @@ func (s *Repo) loadIndex(id string) error {
|
||||
const repositoryIDSize = sha256.Size
|
||||
const RepoVersion = 1
|
||||
|
||||
func createConfig(s *Repo) (err error) {
|
||||
func createConfig(s *Repository) (err error) {
|
||||
s.Config.ChunkerPolynomial, err = chunker.RandomPolynomial()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -553,7 +553,7 @@ func createConfig(s *Repo) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Repo) loadConfig(cfg *Config) error {
|
||||
func (s *Repository) loadConfig(cfg *Config) error {
|
||||
err := s.LoadJSONUnpacked(backend.Config, nil, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -572,7 +572,7 @@ func (s *Repo) loadConfig(cfg *Config) error {
|
||||
|
||||
// SearchKey finds a key with the supplied password, afterwards the config is
|
||||
// read and parsed.
|
||||
func (s *Repo) SearchKey(password string) error {
|
||||
func (s *Repository) SearchKey(password string) error {
|
||||
key, err := SearchKey(s, password)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -585,7 +585,7 @@ func (s *Repo) SearchKey(password string) error {
|
||||
|
||||
// Init creates a new master key with the supplied password and initializes the
|
||||
// repository config.
|
||||
func (s *Repo) Init(password string) error {
|
||||
func (s *Repository) Init(password string) error {
|
||||
has, err := s.Test(backend.Config, "")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -604,7 +604,7 @@ func (s *Repo) Init(password string) error {
|
||||
return createConfig(s)
|
||||
}
|
||||
|
||||
func (s *Repo) Decrypt(ciphertext []byte) ([]byte, error) {
|
||||
func (s *Repository) Decrypt(ciphertext []byte) ([]byte, error) {
|
||||
if s.key == nil {
|
||||
return nil, errors.New("key for repository not set")
|
||||
}
|
||||
@@ -612,7 +612,7 @@ func (s *Repo) Decrypt(ciphertext []byte) ([]byte, error) {
|
||||
return crypto.Decrypt(s.key, nil, ciphertext)
|
||||
}
|
||||
|
||||
func (s *Repo) Encrypt(ciphertext, plaintext []byte) ([]byte, error) {
|
||||
func (s *Repository) Encrypt(ciphertext, plaintext []byte) ([]byte, error) {
|
||||
if s.key == nil {
|
||||
return nil, errors.New("key for repository not set")
|
||||
}
|
||||
@@ -620,16 +620,16 @@ func (s *Repo) Encrypt(ciphertext, plaintext []byte) ([]byte, error) {
|
||||
return crypto.Encrypt(s.key, ciphertext, plaintext)
|
||||
}
|
||||
|
||||
func (s *Repo) Key() *crypto.Key {
|
||||
func (s *Repository) Key() *crypto.Key {
|
||||
return s.key
|
||||
}
|
||||
|
||||
func (s *Repo) KeyName() string {
|
||||
func (s *Repository) KeyName() string {
|
||||
return s.keyName
|
||||
}
|
||||
|
||||
// Count returns the number of blobs of a given type in the backend.
|
||||
func (s *Repo) Count(t backend.Type) (n uint) {
|
||||
func (s *Repository) Count(t backend.Type) (n uint) {
|
||||
for _ = range s.be.List(t, nil) {
|
||||
n++
|
||||
}
|
||||
@@ -639,27 +639,27 @@ func (s *Repo) Count(t backend.Type) (n uint) {
|
||||
|
||||
// Proxy methods to backend
|
||||
|
||||
func (s *Repo) Get(t backend.Type, name string) (io.ReadCloser, error) {
|
||||
func (s *Repository) Get(t backend.Type, name string) (io.ReadCloser, error) {
|
||||
return s.be.Get(t, name)
|
||||
}
|
||||
|
||||
func (s *Repo) List(t backend.Type, done <-chan struct{}) <-chan string {
|
||||
func (s *Repository) List(t backend.Type, done <-chan struct{}) <-chan string {
|
||||
return s.be.List(t, done)
|
||||
}
|
||||
|
||||
func (s *Repo) Test(t backend.Type, name string) (bool, error) {
|
||||
func (s *Repository) Test(t backend.Type, name string) (bool, error) {
|
||||
return s.be.Test(t, name)
|
||||
}
|
||||
|
||||
func (s *Repo) Remove(t backend.Type, name string) error {
|
||||
func (s *Repository) Remove(t backend.Type, name string) error {
|
||||
return s.be.Remove(t, name)
|
||||
}
|
||||
|
||||
func (s *Repo) Close() error {
|
||||
func (s *Repository) Close() error {
|
||||
return s.be.Close()
|
||||
}
|
||||
|
||||
func (s *Repo) Delete() error {
|
||||
func (s *Repository) Delete() error {
|
||||
if b, ok := s.be.(backend.Deleter); ok {
|
||||
return b.Delete()
|
||||
}
|
||||
@@ -667,6 +667,6 @@ func (s *Repo) Delete() error {
|
||||
return errors.New("Delete() called for backend that does not implement this method")
|
||||
}
|
||||
|
||||
func (s *Repo) Location() string {
|
||||
func (s *Repository) Location() string {
|
||||
return s.be.Location()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user