repository: Rename receiver: s -> r

No functional changes.
This commit is contained in:
Alexander Neumann 2015-07-02 21:52:57 +02:00
parent e3ffe33216
commit 867f6c8e24
1 changed files with 116 additions and 116 deletions

View File

@ -48,23 +48,23 @@ func New(be backend.Backend) *Repository {
// Find loads the list of all blobs of type t and searches for names which start // 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 // with prefix. If none is found, nil and ErrNoIDPrefixFound is returned. If
// more than one is found, nil and ErrMultipleIDMatches is returned. // more than one is found, nil and ErrMultipleIDMatches is returned.
func (s *Repository) Find(t backend.Type, prefix string) (string, error) { func (r *Repository) Find(t backend.Type, prefix string) (string, error) {
return backend.Find(s.be, t, prefix) return backend.Find(r.be, t, prefix)
} }
// PrefixLength returns the number of bytes required so that all prefixes of // PrefixLength returns the number of bytes required so that all prefixes of
// all IDs of type t are unique. // all IDs of type t are unique.
func (s *Repository) PrefixLength(t backend.Type) (int, error) { func (r *Repository) PrefixLength(t backend.Type) (int, error) {
return backend.PrefixLength(s.be, t) return backend.PrefixLength(r.be, t)
} }
// Load tries to load and decrypt content identified by t and id from the // Load tries to load and decrypt content identified by t and id from the
// backend. // backend.
func (s *Repository) Load(t backend.Type, id backend.ID) ([]byte, error) { func (r *Repository) Load(t backend.Type, id backend.ID) ([]byte, error) {
debug.Log("Repo.Load", "load %v with id %v", t, id.Str()) debug.Log("Repo.Load", "load %v with id %v", t, id.Str())
// load blob from pack // load blob from pack
rd, err := s.be.Get(t, id.String()) rd, err := r.be.Get(t, id.String())
if err != nil { if err != nil {
debug.Log("Repo.Load", "error loading %v: %v", id.Str(), err) debug.Log("Repo.Load", "error loading %v: %v", id.Str(), err)
return nil, err return nil, err
@ -86,7 +86,7 @@ func (s *Repository) Load(t backend.Type, id backend.ID) ([]byte, error) {
} }
// decrypt // decrypt
plain, err := s.Decrypt(buf) plain, err := r.Decrypt(buf)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -96,10 +96,10 @@ func (s *Repository) Load(t backend.Type, id backend.ID) ([]byte, error) {
// LoadBlob tries to load and decrypt content identified by t and id from a // LoadBlob tries to load and decrypt content identified by t and id from a
// pack from the backend. // pack from the backend.
func (s *Repository) LoadBlob(t pack.BlobType, id backend.ID) ([]byte, error) { func (r *Repository) LoadBlob(t pack.BlobType, id backend.ID) ([]byte, error) {
debug.Log("Repo.LoadBlob", "load %v with id %v", t, id.Str()) debug.Log("Repo.LoadBlob", "load %v with id %v", t, id.Str())
// lookup pack // lookup pack
packID, tpe, offset, length, err := s.idx.Lookup(id) packID, tpe, offset, length, err := r.idx.Lookup(id)
if err != nil { if err != nil {
debug.Log("Repo.LoadBlob", "id %v not found in index: %v", id.Str(), err) debug.Log("Repo.LoadBlob", "id %v not found in index: %v", id.Str(), err)
return nil, err return nil, err
@ -113,7 +113,7 @@ func (s *Repository) LoadBlob(t pack.BlobType, id backend.ID) ([]byte, error) {
debug.Log("Repo.LoadBlob", "id %v found in pack %v at offset %v (length %d)", id.Str(), packID.Str(), offset, length) debug.Log("Repo.LoadBlob", "id %v found in pack %v at offset %v (length %d)", id.Str(), packID.Str(), offset, length)
// load blob from pack // load blob from pack
rd, err := s.be.GetReader(backend.Data, packID.String(), offset, length) rd, err := r.be.GetReader(backend.Data, packID.String(), offset, length)
if err != nil { if err != nil {
debug.Log("Repo.LoadBlob", "error loading pack %v for %v: %v", packID.Str(), id.Str(), err) debug.Log("Repo.LoadBlob", "error loading pack %v for %v: %v", packID.Str(), id.Str(), err)
return nil, err return nil, err
@ -130,7 +130,7 @@ func (s *Repository) LoadBlob(t pack.BlobType, id backend.ID) ([]byte, error) {
} }
// decrypt // decrypt
plain, err := s.Decrypt(buf) plain, err := r.Decrypt(buf)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -145,16 +145,16 @@ func (s *Repository) LoadBlob(t pack.BlobType, id backend.ID) ([]byte, error) {
// LoadJSONUnpacked decrypts the data and afterwards calls json.Unmarshal on // LoadJSONUnpacked decrypts the data and afterwards calls json.Unmarshal on
// the item. // the item.
func (s *Repository) LoadJSONUnpacked(t backend.Type, id backend.ID, item interface{}) error { func (r *Repository) LoadJSONUnpacked(t backend.Type, id backend.ID, item interface{}) error {
// load blob from backend // load blob from backend
rd, err := s.be.Get(t, id.String()) rd, err := r.be.Get(t, id.String())
if err != nil { if err != nil {
return err return err
} }
defer rd.Close() defer rd.Close()
// decrypt // decrypt
decryptRd, err := crypto.DecryptFrom(s.key, rd) decryptRd, err := crypto.DecryptFrom(r.key, rd)
defer decryptRd.Close() defer decryptRd.Close()
if err != nil { if err != nil {
return err return err
@ -172,22 +172,22 @@ func (s *Repository) LoadJSONUnpacked(t backend.Type, id backend.ID, item interf
// LoadJSONPack calls LoadBlob() to load a blob from the backend, decrypt the // LoadJSONPack calls LoadBlob() to load a blob from the backend, decrypt the
// data and afterwards call json.Unmarshal on the item. // data and afterwards call json.Unmarshal on the item.
func (s *Repository) LoadJSONPack(t pack.BlobType, id backend.ID, item interface{}) error { func (r *Repository) LoadJSONPack(t pack.BlobType, id backend.ID, item interface{}) error {
// lookup pack // lookup pack
packID, _, offset, length, err := s.idx.Lookup(id) packID, _, offset, length, err := r.idx.Lookup(id)
if err != nil { if err != nil {
return err return err
} }
// load blob from pack // load blob from pack
rd, err := s.be.GetReader(backend.Data, packID.String(), offset, length) rd, err := r.be.GetReader(backend.Data, packID.String(), offset, length)
if err != nil { if err != nil {
return err return err
} }
defer rd.Close() defer rd.Close()
// decrypt // decrypt
decryptRd, err := crypto.DecryptFrom(s.key, rd) decryptRd, err := crypto.DecryptFrom(r.key, rd)
defer decryptRd.Close() defer decryptRd.Close()
if err != nil { if err != nil {
return err return err
@ -209,43 +209,43 @@ const maxPackers = 200
// findPacker returns a packer for a new blob of size bytes. Either a new one is // 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. // created or one is returned that already has some blobs.
func (s *Repository) findPacker(size uint) (*pack.Packer, error) { func (r *Repository) findPacker(size uint) (*pack.Packer, error) {
s.pm.Lock() r.pm.Lock()
defer s.pm.Unlock() defer r.pm.Unlock()
// search for a suitable packer // search for a suitable packer
if len(s.packs) > 0 { if len(r.packs) > 0 {
debug.Log("Repo.findPacker", "searching packer for %d bytes\n", size) debug.Log("Repo.findPacker", "searching packer for %d bytes\n", size)
for i, p := range s.packs { for i, p := range r.packs {
if p.Size()+size < maxPackSize { if p.Size()+size < maxPackSize {
debug.Log("Repo.findPacker", "found packer %v", p) debug.Log("Repo.findPacker", "found packer %v", p)
// remove from list // remove from list
s.packs = append(s.packs[:i], s.packs[i+1:]...) r.packs = append(r.packs[:i], r.packs[i+1:]...)
return p, nil return p, nil
} }
} }
} }
// no suitable packer found, return new // no suitable packer found, return new
blob, err := s.be.Create() blob, err := r.be.Create()
if err != nil { if err != nil {
return nil, err return nil, err
} }
debug.Log("Repo.findPacker", "create new pack %p", blob) debug.Log("Repo.findPacker", "create new pack %p", blob)
return pack.NewPacker(s.key, blob), nil return pack.NewPacker(r.key, blob), nil
} }
// insertPacker appends p to s.packs. // insertPacker appends p to s.packs.
func (s *Repository) insertPacker(p *pack.Packer) { func (r *Repository) insertPacker(p *pack.Packer) {
s.pm.Lock() r.pm.Lock()
defer s.pm.Unlock() defer r.pm.Unlock()
s.packs = append(s.packs, p) r.packs = append(r.packs, p)
debug.Log("Repo.insertPacker", "%d packers\n", len(s.packs)) debug.Log("Repo.insertPacker", "%d packers\n", len(r.packs))
} }
// savePacker stores p in the backend. // savePacker stores p in the backend.
func (s *Repository) savePacker(p *pack.Packer) error { func (r *Repository) savePacker(p *pack.Packer) error {
debug.Log("Repo.savePacker", "save packer with %d blobs\n", p.Count()) debug.Log("Repo.savePacker", "save packer with %d blobs\n", p.Count())
_, err := p.Finalize() _, err := p.Finalize()
if err != nil { if err != nil {
@ -265,23 +265,23 @@ func (s *Repository) savePacker(p *pack.Packer) error {
// update blobs in the index // update blobs in the index
for _, b := range p.Blobs() { for _, b := range p.Blobs() {
debug.Log("Repo.savePacker", " updating blob %v to pack %v", b.ID.Str(), sid.Str()) debug.Log("Repo.savePacker", " updating blob %v to pack %v", b.ID.Str(), sid.Str())
s.idx.Store(b.Type, b.ID, sid, b.Offset, uint(b.Length)) r.idx.Store(b.Type, b.ID, sid, b.Offset, uint(b.Length))
} }
return nil return nil
} }
// countPacker returns the number of open (unfinished) packers. // countPacker returns the number of open (unfinished) packers.
func (s *Repository) countPacker() int { func (r *Repository) countPacker() int {
s.pm.Lock() r.pm.Lock()
defer s.pm.Unlock() defer r.pm.Unlock()
return len(s.packs) return len(r.packs)
} }
// Save encrypts data and stores it to the backend as type t. If data is small // 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. // enough, it will be packed together with other small blobs.
func (s *Repository) Save(t pack.BlobType, data []byte, id backend.ID) (backend.ID, error) { func (r *Repository) Save(t pack.BlobType, data []byte, id backend.ID) (backend.ID, error) {
if id == nil { if id == nil {
// compute plaintext hash // compute plaintext hash
id = backend.Hash(data) id = backend.Hash(data)
@ -294,13 +294,13 @@ func (s *Repository) Save(t pack.BlobType, data []byte, id backend.ID) (backend.
defer freeBuf(ciphertext) defer freeBuf(ciphertext)
// encrypt blob // encrypt blob
ciphertext, err := s.Encrypt(ciphertext, data) ciphertext, err := r.Encrypt(ciphertext, data)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// find suitable packer and add blob // find suitable packer and add blob
packer, err := s.findPacker(uint(len(ciphertext))) packer, err := r.findPacker(uint(len(ciphertext)))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -310,23 +310,23 @@ func (s *Repository) Save(t pack.BlobType, data []byte, id backend.ID) (backend.
// add this id to the index, although we don't know yet in which pack it // add this id to the index, although we don't know yet in which pack it
// will be saved, the entry will be updated when the pack is written. // will be saved, the entry will be updated when the pack is written.
s.idx.Store(t, id, nil, 0, 0) r.idx.Store(t, id, nil, 0, 0)
debug.Log("Repo.Save", "saving stub for %v (%v) in index", id.Str, t) debug.Log("Repo.Save", "saving stub for %v (%v) in index", id.Str, t)
// if the pack is not full enough and there are less than maxPackers // if the pack is not full enough and there are less than maxPackers
// packers, put back to the list // packers, put back to the list
if packer.Size() < minPackSize && s.countPacker() < maxPackers { if packer.Size() < minPackSize && r.countPacker() < maxPackers {
debug.Log("Repo.Save", "pack is not full enough (%d bytes)", packer.Size()) debug.Log("Repo.Save", "pack is not full enough (%d bytes)", packer.Size())
s.insertPacker(packer) r.insertPacker(packer)
return id, nil return id, nil
} }
// else write the pack to the backend // else write the pack to the backend
return id, s.savePacker(packer) return id, r.savePacker(packer)
} }
// SaveFrom encrypts data read from rd and stores it in a pack in the backend as type t. // SaveFrom encrypts data read from rd and stores it in a pack in the backend as type t.
func (s *Repository) SaveFrom(t pack.BlobType, id backend.ID, length uint, rd io.Reader) error { func (r *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) debug.Log("Repo.SaveFrom", "save id %v (%v, %d bytes)", id.Str(), t, length)
if id == nil { if id == nil {
return errors.New("id is nil") return errors.New("id is nil")
@ -337,7 +337,7 @@ func (s *Repository) SaveFrom(t pack.BlobType, id backend.ID, length uint, rd io
return err return err
} }
_, err = s.Save(t, buf, id) _, err = r.Save(t, buf, id)
if err != nil { if err != nil {
return err return err
} }
@ -347,7 +347,7 @@ func (s *Repository) SaveFrom(t pack.BlobType, id backend.ID, length uint, rd io
// SaveJSON serialises item as JSON and encrypts and saves it in a pack in the // SaveJSON serialises item as JSON and encrypts and saves it in a pack in the
// backend as type t. // backend as type t.
func (s *Repository) SaveJSON(t pack.BlobType, item interface{}) (backend.ID, error) { func (r *Repository) SaveJSON(t pack.BlobType, item interface{}) (backend.ID, error) {
debug.Log("Repo.SaveJSON", "save %v blob", t) debug.Log("Repo.SaveJSON", "save %v blob", t)
buf := getBuf()[:0] buf := getBuf()[:0]
defer freeBuf(buf) defer freeBuf(buf)
@ -361,14 +361,14 @@ func (s *Repository) SaveJSON(t pack.BlobType, item interface{}) (backend.ID, er
} }
buf = wr.Bytes() buf = wr.Bytes()
return s.Save(t, buf, nil) return r.Save(t, buf, nil)
} }
// SaveJSONUnpacked serialises item as JSON and encrypts and saves it in the // SaveJSONUnpacked serialises item as JSON and encrypts and saves it in the
// backend as type t, without a pack. It returns the storage hash. // backend as type t, without a pack. It returns the storage hash.
func (s *Repository) SaveJSONUnpacked(t backend.Type, item interface{}) (backend.ID, error) { func (r *Repository) SaveJSONUnpacked(t backend.Type, item interface{}) (backend.ID, error) {
// create file // create file
blob, err := s.be.Create() blob, err := r.be.Create()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -378,7 +378,7 @@ func (s *Repository) SaveJSONUnpacked(t backend.Type, item interface{}) (backend
hw := backend.NewHashingWriter(blob, sha256.New()) hw := backend.NewHashingWriter(blob, sha256.New())
// encrypt blob // encrypt blob
ewr := crypto.EncryptTo(s.key, hw) ewr := crypto.EncryptTo(r.key, hw)
enc := json.NewEncoder(ewr) enc := json.NewEncoder(ewr)
err = enc.Encode(item) err = enc.Encode(item)
@ -406,43 +406,43 @@ func (s *Repository) SaveJSONUnpacked(t backend.Type, item interface{}) (backend
} }
// Flush saves all remaining packs. // Flush saves all remaining packs.
func (s *Repository) Flush() error { func (r *Repository) Flush() error {
s.pm.Lock() r.pm.Lock()
defer s.pm.Unlock() defer r.pm.Unlock()
debug.Log("Repo.Flush", "manually flushing %d packs", len(s.packs)) debug.Log("Repo.Flush", "manually flushing %d packs", len(r.packs))
for _, p := range s.packs { for _, p := range r.packs {
err := s.savePacker(p) err := r.savePacker(p)
if err != nil { if err != nil {
return err return err
} }
} }
s.packs = s.packs[:0] r.packs = r.packs[:0]
return nil return nil
} }
func (s *Repository) Backend() backend.Backend { func (r *Repository) Backend() backend.Backend {
return s.be return r.be
} }
func (s *Repository) Index() *Index { func (r *Repository) Index() *Index {
return s.idx return r.idx
} }
// SetIndex instructs the repository to use the given index. // SetIndex instructs the repository to use the given index.
func (s *Repository) SetIndex(i *Index) { func (r *Repository) SetIndex(i *Index) {
s.idx = i r.idx = i
} }
// SaveIndex saves all new packs in the index in the backend, returned is the // SaveIndex saves all new packs in the index in the backend, returned is the
// storage ID. // storage ID.
func (s *Repository) SaveIndex() (backend.ID, error) { func (r *Repository) SaveIndex() (backend.ID, error) {
debug.Log("Repo.SaveIndex", "Saving index") debug.Log("Repo.SaveIndex", "Saving index")
// create blob // create blob
blob, err := s.be.Create() blob, err := r.be.Create()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -453,9 +453,9 @@ func (s *Repository) SaveIndex() (backend.ID, error) {
hw := backend.NewHashingWriter(blob, sha256.New()) hw := backend.NewHashingWriter(blob, sha256.New())
// encrypt blob // encrypt blob
ewr := crypto.EncryptTo(s.key, hw) ewr := crypto.EncryptTo(r.key, hw)
err = s.idx.Encode(ewr) err = r.idx.Encode(ewr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -480,13 +480,13 @@ func (s *Repository) SaveIndex() (backend.ID, error) {
// LoadIndex loads all index files from the backend and merges them with the // LoadIndex loads all index files from the backend and merges them with the
// current index. // current index.
func (s *Repository) LoadIndex() error { func (r *Repository) LoadIndex() error {
debug.Log("Repo.LoadIndex", "Loading index") debug.Log("Repo.LoadIndex", "Loading index")
done := make(chan struct{}) done := make(chan struct{})
defer close(done) defer close(done)
for id := range s.be.List(backend.Index, done) { for id := range r.be.List(backend.Index, done) {
err := s.loadIndex(id) err := r.loadIndex(id)
if err != nil { if err != nil {
return err return err
} }
@ -495,18 +495,18 @@ func (s *Repository) LoadIndex() error {
} }
// loadIndex loads the index id and merges it with the currently used index. // loadIndex loads the index id and merges it with the currently used index.
func (s *Repository) loadIndex(id string) error { func (r *Repository) loadIndex(id string) error {
debug.Log("Repo.loadIndex", "Loading index %v", id[:8]) debug.Log("Repo.loadIndex", "Loading index %v", id[:8])
before := len(s.idx.pack) before := len(r.idx.pack)
rd, err := s.be.Get(backend.Index, id) rd, err := r.be.Get(backend.Index, id)
defer rd.Close() defer rd.Close()
if err != nil { if err != nil {
return err return err
} }
// decrypt // decrypt
decryptRd, err := crypto.DecryptFrom(s.key, rd) decryptRd, err := crypto.DecryptFrom(r.key, rd)
defer decryptRd.Close() defer decryptRd.Close()
if err != nil { if err != nil {
return err return err
@ -518,9 +518,9 @@ func (s *Repository) loadIndex(id string) error {
return err return err
} }
s.idx.Merge(idx) r.idx.Merge(idx)
after := len(s.idx.pack) after := len(r.idx.pack)
debug.Log("Repo.loadIndex", "Loaded index %v, added %v blobs", id[:8], after-before) debug.Log("Repo.loadIndex", "Loaded index %v, added %v blobs", id[:8], after-before)
return nil return nil
@ -529,8 +529,8 @@ func (s *Repository) loadIndex(id string) error {
const repositoryIDSize = sha256.Size const repositoryIDSize = sha256.Size
const RepoVersion = 1 const RepoVersion = 1
func createConfig(s *Repository) (err error) { func createConfig(r *Repository) (err error) {
s.Config.ChunkerPolynomial, err = chunker.RandomPolynomial() r.Config.ChunkerPolynomial, err = chunker.RandomPolynomial()
if err != nil { if err != nil {
return err return err
} }
@ -541,17 +541,17 @@ func createConfig(s *Repository) (err error) {
return err return err
} }
s.Config.ID = hex.EncodeToString(newID) r.Config.ID = hex.EncodeToString(newID)
s.Config.Version = RepoVersion r.Config.Version = RepoVersion
debug.Log("Repo.createConfig", "New config: %#v", s.Config) debug.Log("Repo.createConfig", "New config: %#v", r.Config)
_, err = s.SaveJSONUnpacked(backend.Config, s.Config) _, err = r.SaveJSONUnpacked(backend.Config, r.Config)
return err return err
} }
func (s *Repository) loadConfig(cfg *Config) error { func (r *Repository) loadConfig(cfg *Config) error {
err := s.LoadJSONUnpacked(backend.Config, nil, cfg) err := r.LoadJSONUnpacked(backend.Config, nil, cfg)
if err != nil { if err != nil {
return err return err
} }
@ -569,21 +569,21 @@ func (s *Repository) loadConfig(cfg *Config) error {
// SearchKey finds a key with the supplied password, afterwards the config is // SearchKey finds a key with the supplied password, afterwards the config is
// read and parsed. // read and parsed.
func (s *Repository) SearchKey(password string) error { func (r *Repository) SearchKey(password string) error {
key, err := SearchKey(s, password) key, err := SearchKey(r, password)
if err != nil { if err != nil {
return err return err
} }
s.key = key.master r.key = key.master
s.keyName = key.Name() r.keyName = key.Name()
return s.loadConfig(&s.Config) return r.loadConfig(&r.Config)
} }
// Init creates a new master key with the supplied password and initializes the // Init creates a new master key with the supplied password and initializes the
// repository config. // repository config.
func (s *Repository) Init(password string) error { func (r *Repository) Init(password string) error {
has, err := s.be.Test(backend.Config, "") has, err := r.be.Test(backend.Config, "")
if err != nil { if err != nil {
return err return err
} }
@ -591,52 +591,52 @@ func (s *Repository) Init(password string) error {
return errors.New("repository master key and config already initialized") return errors.New("repository master key and config already initialized")
} }
key, err := createMasterKey(s, password) key, err := createMasterKey(r, password)
if err != nil { if err != nil {
return err return err
} }
s.key = key.master r.key = key.master
s.keyName = key.Name() r.keyName = key.Name()
return createConfig(s) return createConfig(r)
} }
func (s *Repository) Decrypt(ciphertext []byte) ([]byte, error) { func (r *Repository) Decrypt(ciphertext []byte) ([]byte, error) {
if s.key == nil { if r.key == nil {
return nil, errors.New("key for repository not set") return nil, errors.New("key for repository not set")
} }
return crypto.Decrypt(s.key, nil, ciphertext) return crypto.Decrypt(r.key, nil, ciphertext)
} }
func (s *Repository) Encrypt(ciphertext, plaintext []byte) ([]byte, error) { func (r *Repository) Encrypt(ciphertext, plaintext []byte) ([]byte, error) {
if s.key == nil { if r.key == nil {
return nil, errors.New("key for repository not set") return nil, errors.New("key for repository not set")
} }
return crypto.Encrypt(s.key, ciphertext, plaintext) return crypto.Encrypt(r.key, ciphertext, plaintext)
} }
func (s *Repository) Key() *crypto.Key { func (r *Repository) Key() *crypto.Key {
return s.key return r.key
} }
func (s *Repository) KeyName() string { func (r *Repository) KeyName() string {
return s.keyName return r.keyName
} }
// Count returns the number of blobs of a given type in the backend. // Count returns the number of blobs of a given type in the backend.
func (s *Repository) Count(t backend.Type) (n uint) { func (r *Repository) Count(t backend.Type) (n uint) {
for _ = range s.be.List(t, nil) { for _ = range r.be.List(t, nil) {
n++ n++
} }
return return
} }
func (s *Repository) list(t backend.Type, done <-chan struct{}, out chan<- backend.ID) { func (r *Repository) list(t backend.Type, done <-chan struct{}, out chan<- backend.ID) {
defer close(out) defer close(out)
in := s.be.List(t, done) in := r.be.List(t, done)
var ( var (
// disable sending on the outCh until we received a job // disable sending on the outCh until we received a job
@ -671,22 +671,22 @@ func (s *Repository) list(t backend.Type, done <-chan struct{}, out chan<- backe
} }
} }
func (s *Repository) List(t backend.Type, done <-chan struct{}) <-chan backend.ID { func (r *Repository) List(t backend.Type, done <-chan struct{}) <-chan backend.ID {
outCh := make(chan backend.ID) outCh := make(chan backend.ID)
go s.list(t, done, outCh) go r.list(t, done, outCh)
return outCh return outCh
} }
func (s *Repository) Delete() error { func (r *Repository) Delete() error {
if b, ok := s.be.(backend.Deleter); ok { if b, ok := r.be.(backend.Deleter); ok {
return b.Delete() return b.Delete()
} }
return errors.New("Delete() called for backend that does not implement this method") return errors.New("Delete() called for backend that does not implement this method")
} }
func (s *Repository) Close() error { func (r *Repository) Close() error {
return s.be.Close() return r.be.Close()
} }