mirror of https://github.com/restic/restic.git
backend: Rename Get() -> Load()
This commit is contained in:
parent
cfc9e8b2fa
commit
03292d10cc
|
@ -43,7 +43,7 @@ func forgetfulBackend() restic.Backend {
|
|||
return false, nil
|
||||
}
|
||||
|
||||
be.GetFn = func(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
be.LoadFn = func(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
return nil, errors.New("not found")
|
||||
}
|
||||
|
||||
|
|
|
@ -20,11 +20,11 @@ type Backend interface {
|
|||
// Save stores the data in the backend under the given handle.
|
||||
Save(h Handle, rd io.Reader) error
|
||||
|
||||
// Get returns a reader that yields the contents of the file at h at the
|
||||
// Load returns a reader that yields the contents of the file at h at the
|
||||
// given offset. If length is larger than zero, only a portion of the file
|
||||
// is returned. rd must be closed after use. If an error is returned, the
|
||||
// ReadCloser must be nil.
|
||||
Get(h Handle, length int, offset int64) (io.ReadCloser, error)
|
||||
Load(h Handle, length int, offset int64) (io.ReadCloser, error)
|
||||
|
||||
// Stat returns information about the File identified by h.
|
||||
Stat(h Handle) (FileInfo, error)
|
||||
|
|
|
@ -44,11 +44,11 @@ func TestLocalBackendConfig(t *testing.T) {
|
|||
test.TestConfig(t)
|
||||
}
|
||||
|
||||
func TestLocalBackendGet(t *testing.T) {
|
||||
func TestLocalBackendLoad(t *testing.T) {
|
||||
if SkipMessage != "" {
|
||||
t.Skip(SkipMessage)
|
||||
}
|
||||
test.TestGet(t)
|
||||
test.TestLoad(t)
|
||||
}
|
||||
|
||||
func TestLocalBackendSave(t *testing.T) {
|
||||
|
|
|
@ -170,11 +170,11 @@ func (b *Local) Save(h restic.Handle, rd io.Reader) (err error) {
|
|||
return setNewFileMode(filename, fi)
|
||||
}
|
||||
|
||||
// Get returns a reader that yields the contents of the file at h at the
|
||||
// Load returns a reader that yields the contents of the file at h at the
|
||||
// given offset. If length is nonzero, only a portion of the file is
|
||||
// returned. rd must be closed after use.
|
||||
func (b *Local) Get(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
debug.Log("Get %v, length %v, offset %v", h, length, offset)
|
||||
func (b *Local) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
debug.Log("Load %v, length %v, offset %v", h, length, offset)
|
||||
if err := h.Valid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -44,11 +44,11 @@ func TestMemBackendConfig(t *testing.T) {
|
|||
test.TestConfig(t)
|
||||
}
|
||||
|
||||
func TestMemBackendGet(t *testing.T) {
|
||||
func TestMemBackendLoad(t *testing.T) {
|
||||
if SkipMessage != "" {
|
||||
t.Skip(SkipMessage)
|
||||
}
|
||||
test.TestGet(t)
|
||||
test.TestLoad(t)
|
||||
}
|
||||
|
||||
func TestMemBackendSave(t *testing.T) {
|
||||
|
|
|
@ -83,10 +83,10 @@ func (be *MemoryBackend) Save(h restic.Handle, rd io.Reader) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Get returns a reader that yields the contents of the file at h at the
|
||||
// Load returns a reader that yields the contents of the file at h at the
|
||||
// given offset. If length is nonzero, only a portion of the file is
|
||||
// returned. rd must be closed after use.
|
||||
func (be *MemoryBackend) Get(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
func (be *MemoryBackend) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
if err := h.Valid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ func (be *MemoryBackend) Get(h restic.Handle, length int, offset int64) (io.Read
|
|||
h.Name = ""
|
||||
}
|
||||
|
||||
debug.Log("Get %v offset %v len %v", h, offset, length)
|
||||
debug.Log("Load %v offset %v len %v", h, offset, length)
|
||||
|
||||
if offset < 0 {
|
||||
return nil, errors.New("offset is negative")
|
||||
|
|
|
@ -44,11 +44,11 @@ func TestRestBackendConfig(t *testing.T) {
|
|||
test.TestConfig(t)
|
||||
}
|
||||
|
||||
func TestRestBackendGet(t *testing.T) {
|
||||
func TestRestBackendLoad(t *testing.T) {
|
||||
if SkipMessage != "" {
|
||||
t.Skip(SkipMessage)
|
||||
}
|
||||
test.TestGet(t)
|
||||
test.TestLoad(t)
|
||||
}
|
||||
|
||||
func TestRestBackendSave(t *testing.T) {
|
||||
|
|
|
@ -106,11 +106,11 @@ func (b *restBackend) Save(h restic.Handle, rd io.Reader) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Get returns a reader that yields the contents of the file at h at the
|
||||
// Load returns a reader that yields the contents of the file at h at the
|
||||
// given offset. If length is nonzero, only a portion of the file is
|
||||
// returned. rd must be closed after use.
|
||||
func (b *restBackend) Get(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
debug.Log("Get %v, length %v, offset %v", h, length, offset)
|
||||
func (b *restBackend) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
debug.Log("Load %v, length %v, offset %v", h, length, offset)
|
||||
if err := h.Valid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ func (b *restBackend) Get(h restic.Handle, length int, offset int64) (io.ReadClo
|
|||
byteRange = fmt.Sprintf("bytes=%d-%d", offset, offset+int64(length)-1)
|
||||
}
|
||||
req.Header.Add("Range", byteRange)
|
||||
debug.Log("Get(%v) send range %v", h, byteRange)
|
||||
debug.Log("Load(%v) send range %v", h, byteRange)
|
||||
|
||||
<-b.connChan
|
||||
resp, err := b.client.Do(req)
|
||||
|
|
|
@ -44,11 +44,11 @@ func TestS3BackendConfig(t *testing.T) {
|
|||
test.TestConfig(t)
|
||||
}
|
||||
|
||||
func TestS3BackendGet(t *testing.T) {
|
||||
func TestS3BackendLoad(t *testing.T) {
|
||||
if SkipMessage != "" {
|
||||
t.Skip(SkipMessage)
|
||||
}
|
||||
test.TestGet(t)
|
||||
test.TestLoad(t)
|
||||
}
|
||||
|
||||
func TestS3BackendSave(t *testing.T) {
|
||||
|
|
|
@ -104,11 +104,11 @@ func (be *s3) Save(h restic.Handle, rd io.Reader) (err error) {
|
|||
return errors.Wrap(err, "client.PutObject")
|
||||
}
|
||||
|
||||
// Get returns a reader that yields the contents of the file at h at the
|
||||
// Load returns a reader that yields the contents of the file at h at the
|
||||
// given offset. If length is nonzero, only a portion of the file is
|
||||
// returned. rd must be closed after use.
|
||||
func (be *s3) Get(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
debug.Log("Get %v, length %v, offset %v", h, length, offset)
|
||||
func (be *s3) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
debug.Log("Load %v, length %v, offset %v", h, length, offset)
|
||||
if err := h.Valid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ func (be *s3) Get(h restic.Handle, length int, offset int64) (io.ReadCloser, err
|
|||
|
||||
// if we're going to read the whole object, just pass it on.
|
||||
if length == 0 {
|
||||
debug.Log("Get %v: pass on object", h)
|
||||
debug.Log("Load %v: pass on object", h)
|
||||
_, err = obj.Seek(offset, 0)
|
||||
if err != nil {
|
||||
_ = obj.Close()
|
||||
|
@ -167,9 +167,9 @@ func (be *s3) Get(h restic.Handle, length int, offset int64) (io.ReadCloser, err
|
|||
|
||||
buf := make([]byte, l)
|
||||
n, err := obj.ReadAt(buf, offset)
|
||||
debug.Log("Get %v: use buffer with ReadAt: %v, %v", h, n, err)
|
||||
debug.Log("Load %v: use buffer with ReadAt: %v, %v", h, n, err)
|
||||
if err == io.EOF {
|
||||
debug.Log("Get %v: shorten buffer %v -> %v", h, len(buf), n)
|
||||
debug.Log("Load %v: shorten buffer %v -> %v", h, len(buf), n)
|
||||
buf = buf[:n]
|
||||
err = nil
|
||||
}
|
||||
|
|
|
@ -44,11 +44,11 @@ func TestSftpBackendConfig(t *testing.T) {
|
|||
test.TestConfig(t)
|
||||
}
|
||||
|
||||
func TestSftpBackendGet(t *testing.T) {
|
||||
func TestSftpBackendLoad(t *testing.T) {
|
||||
if SkipMessage != "" {
|
||||
t.Skip(SkipMessage)
|
||||
}
|
||||
test.TestGet(t)
|
||||
test.TestLoad(t)
|
||||
}
|
||||
|
||||
func TestSftpBackendSave(t *testing.T) {
|
||||
|
|
|
@ -360,11 +360,11 @@ func (r *SFTP) Save(h restic.Handle, rd io.Reader) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
// Get returns a reader that yields the contents of the file at h at the
|
||||
// Load returns a reader that yields the contents of the file at h at the
|
||||
// given offset. If length is nonzero, only a portion of the file is
|
||||
// returned. rd must be closed after use.
|
||||
func (r *SFTP) Get(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
debug.Log("Get %v, length %v, offset %v", h, length, offset)
|
||||
func (r *SFTP) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
debug.Log("Load %v, length %v, offset %v", h, length, offset)
|
||||
if err := h.Valid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -44,11 +44,11 @@ func TestTestBackendConfig(t *testing.T) {
|
|||
test.TestConfig(t)
|
||||
}
|
||||
|
||||
func TestTestBackendGet(t *testing.T) {
|
||||
func TestTestBackendLoad(t *testing.T) {
|
||||
if SkipMessage != "" {
|
||||
t.Skip(SkipMessage)
|
||||
}
|
||||
test.TestGet(t)
|
||||
test.TestLoad(t)
|
||||
}
|
||||
|
||||
func TestTestBackendSave(t *testing.T) {
|
||||
|
|
|
@ -178,19 +178,19 @@ func TestConfig(t testing.TB) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestGet tests the backend's Get function.
|
||||
func TestGet(t testing.TB) {
|
||||
// TestLoad tests the backend's Load function.
|
||||
func TestLoad(t testing.TB) {
|
||||
b := open(t)
|
||||
defer close(t)
|
||||
|
||||
_, err := b.Get(restic.Handle{}, 0, 0)
|
||||
_, err := b.Load(restic.Handle{}, 0, 0)
|
||||
if err == nil {
|
||||
t.Fatalf("Get() did not return an error for invalid handle")
|
||||
t.Fatalf("Load() did not return an error for invalid handle")
|
||||
}
|
||||
|
||||
_, err = b.Get(restic.Handle{Type: restic.DataFile, Name: "foobar"}, 0, 0)
|
||||
_, err = b.Load(restic.Handle{Type: restic.DataFile, Name: "foobar"}, 0, 0)
|
||||
if err == nil {
|
||||
t.Fatalf("Get() did not return an error for non-existing blob")
|
||||
t.Fatalf("Load() did not return an error for non-existing blob")
|
||||
}
|
||||
|
||||
length := rand.Intn(1<<24) + 2000
|
||||
|
@ -204,13 +204,13 @@ func TestGet(t testing.TB) {
|
|||
t.Fatalf("Save() error: %v", err)
|
||||
}
|
||||
|
||||
rd, err := b.Get(handle, 100, -1)
|
||||
rd, err := b.Load(handle, 100, -1)
|
||||
if err == nil {
|
||||
t.Fatalf("Get() returned no error for negative offset!")
|
||||
t.Fatalf("Load() returned no error for negative offset!")
|
||||
}
|
||||
|
||||
if rd != nil {
|
||||
t.Fatalf("Get() returned a non-nil reader for negative offset!")
|
||||
t.Fatalf("Load() returned a non-nil reader for negative offset!")
|
||||
}
|
||||
|
||||
for i := 0; i < 50; i++ {
|
||||
|
@ -234,36 +234,36 @@ func TestGet(t testing.TB) {
|
|||
d = d[:l]
|
||||
}
|
||||
|
||||
rd, err := b.Get(handle, getlen, int64(o))
|
||||
rd, err := b.Load(handle, getlen, int64(o))
|
||||
if err != nil {
|
||||
t.Errorf("Get(%d, %d) returned unexpected error: %v", l, o, err)
|
||||
t.Errorf("Load(%d, %d) returned unexpected error: %v", l, o, err)
|
||||
continue
|
||||
}
|
||||
|
||||
buf, err := ioutil.ReadAll(rd)
|
||||
if err != nil {
|
||||
t.Errorf("Get(%d, %d) ReadAll() returned unexpected error: %v", l, o, err)
|
||||
t.Errorf("Load(%d, %d) ReadAll() returned unexpected error: %v", l, o, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if l <= len(d) && len(buf) != l {
|
||||
t.Errorf("Get(%d, %d) wrong number of bytes read: want %d, got %d", l, o, l, len(buf))
|
||||
t.Errorf("Load(%d, %d) wrong number of bytes read: want %d, got %d", l, o, l, len(buf))
|
||||
continue
|
||||
}
|
||||
|
||||
if l > len(d) && len(buf) != len(d) {
|
||||
t.Errorf("Get(%d, %d) wrong number of bytes read for overlong read: want %d, got %d", l, o, l, len(buf))
|
||||
t.Errorf("Load(%d, %d) wrong number of bytes read for overlong read: want %d, got %d", l, o, l, len(buf))
|
||||
continue
|
||||
}
|
||||
|
||||
if !bytes.Equal(buf, d) {
|
||||
t.Errorf("Get(%d, %d) returned wrong bytes", l, o)
|
||||
t.Errorf("Load(%d, %d) returned wrong bytes", l, o)
|
||||
continue
|
||||
}
|
||||
|
||||
err = rd.Close()
|
||||
if err != nil {
|
||||
t.Errorf("Get(%d, %d) rd.Close() returned unexpected error: %v", l, o, err)
|
||||
t.Errorf("Load(%d, %d) rd.Close() returned unexpected error: %v", l, o, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
@ -398,7 +398,7 @@ func TestBackend(t testing.TB) {
|
|||
test.Assert(t, err != nil, "blob data could be extracted before creation")
|
||||
|
||||
// try to read not existing blob
|
||||
_, err = b.Get(h, 0, 0)
|
||||
_, err = b.Load(h, 0, 0)
|
||||
test.Assert(t, err != nil, "blob reader could be obtained before creation")
|
||||
|
||||
// try to get string out, should fail
|
||||
|
@ -423,7 +423,7 @@ func TestBackend(t testing.TB) {
|
|||
length := end - start
|
||||
|
||||
buf2 := make([]byte, length)
|
||||
rd, err := b.Get(h, len(buf2), int64(start))
|
||||
rd, err := b.Load(h, len(buf2), int64(start))
|
||||
test.OK(t, err)
|
||||
n, err := io.ReadFull(rd, buf2)
|
||||
test.OK(t, err)
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
// LoadAll reads all data stored in the backend for the handle.
|
||||
func LoadAll(be restic.Backend, h restic.Handle) (buf []byte, err error) {
|
||||
rd, err := be.Get(h, 0, 0)
|
||||
rd, err := be.Load(h, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -209,8 +209,8 @@ type errorBackend struct {
|
|||
ProduceErrors bool
|
||||
}
|
||||
|
||||
func (b errorBackend) Get(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
rd, err := b.Backend.Get(h, length, offset)
|
||||
func (b errorBackend) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
rd, err := b.Backend.Load(h, length, offset)
|
||||
if err != nil {
|
||||
return rd, err
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
type Backend struct {
|
||||
CloseFn func() error
|
||||
SaveFn func(h restic.Handle, rd io.Reader) error
|
||||
GetFn func(h restic.Handle, length int, offset int64) (io.ReadCloser, error)
|
||||
LoadFn func(h restic.Handle, length int, offset int64) (io.ReadCloser, error)
|
||||
StatFn func(h restic.Handle) (restic.FileInfo, error)
|
||||
ListFn func(restic.FileType, <-chan struct{}) <-chan string
|
||||
RemoveFn func(restic.FileType, string) error
|
||||
|
@ -47,13 +47,13 @@ func (m *Backend) Save(h restic.Handle, rd io.Reader) error {
|
|||
return m.SaveFn(h, rd)
|
||||
}
|
||||
|
||||
// Get loads data from the backend.
|
||||
func (m *Backend) Get(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
if m.GetFn == nil {
|
||||
// Load loads data from the backend.
|
||||
func (m *Backend) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
if m.LoadFn == nil {
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
|
||||
return m.GetFn(h, length, offset)
|
||||
return m.LoadFn(h, length, offset)
|
||||
}
|
||||
|
||||
// Stat an object in the backend.
|
||||
|
|
|
@ -20,7 +20,7 @@ func ReaderAt(be Backend, h Handle) io.ReaderAt {
|
|||
|
||||
// ReadAt reads from the backend handle h at the given position.
|
||||
func ReadAt(be Backend, h Handle, offset int64, p []byte) (n int, err error) {
|
||||
rd, err := be.Get(h, len(p), offset)
|
||||
rd, err := be.Load(h, len(p), offset)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ func Repack(repo restic.Repository, packs restic.IDSet, keepBlobs restic.BlobSet
|
|||
return errors.Wrap(err, "TempFile")
|
||||
}
|
||||
|
||||
beRd, err := repo.Backend().Get(h, 0, 0)
|
||||
beRd, err := repo.Backend().Load(h, 0, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue