2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-02 11:46:36 +00:00

s3: Rename struct to Backend

This commit is contained in:
Alexander Neumann 2017-06-07 21:59:01 +02:00
parent 550e1feaec
commit b8b5c8e8c9

View File

@ -21,8 +21,8 @@ import (
const connLimit = 10 const connLimit = 10
// s3 is a backend which stores the data on an S3 endpoint. // Backend stores data on an S3 endpoint.
type s3 struct { type Backend struct {
client *minio.Client client *minio.Client
sem *backend.Semaphore sem *backend.Semaphore
bucketname string bucketname string
@ -32,8 +32,8 @@ type s3 struct {
backend.Layout backend.Layout
} }
// make sure that *s3 implements backend.Backend // make sure that *Backend implements backend.Backend
var _ restic.Backend = &s3{} var _ restic.Backend = &Backend{}
const defaultLayout = "s3legacy" const defaultLayout = "s3legacy"
@ -52,7 +52,7 @@ func Open(cfg Config) (restic.Backend, error) {
return nil, err return nil, err
} }
be := &s3{ be := &Backend{
client: client, client: client,
sem: sem, sem: sem,
bucketname: cfg.Bucket, bucketname: cfg.Bucket,
@ -87,13 +87,13 @@ func Open(cfg Config) (restic.Backend, error) {
} }
// IsNotExist returns true if the error is caused by a not existing file. // IsNotExist returns true if the error is caused by a not existing file.
func (be *s3) IsNotExist(err error) bool { func (be *Backend) IsNotExist(err error) bool {
debug.Log("IsNotExist(%T, %#v)", err, err) debug.Log("IsNotExist(%T, %#v)", err, err)
return os.IsNotExist(err) return os.IsNotExist(err)
} }
// Join combines path components with slashes. // Join combines path components with slashes.
func (be *s3) Join(p ...string) string { func (be *Backend) Join(p ...string) string {
return path.Join(p...) return path.Join(p...)
} }
@ -113,7 +113,7 @@ func (fi fileInfo) IsDir() bool { return fi.isDir } // abbreviation for
func (fi fileInfo) Sys() interface{} { return nil } // underlying data source (can return nil) func (fi fileInfo) Sys() interface{} { return nil } // underlying data source (can return nil)
// ReadDir returns the entries for a directory. // ReadDir returns the entries for a directory.
func (be *s3) ReadDir(dir string) (list []os.FileInfo, err error) { func (be *Backend) ReadDir(dir string) (list []os.FileInfo, err error) {
debug.Log("ReadDir(%v)", dir) debug.Log("ReadDir(%v)", dir)
// make sure dir ends with a slash // make sure dir ends with a slash
@ -154,7 +154,7 @@ func (be *s3) ReadDir(dir string) (list []os.FileInfo, err error) {
} }
// Location returns this backend's location (the bucket name). // Location returns this backend's location (the bucket name).
func (be *s3) Location() string { func (be *Backend) Location() string {
return be.bucketname return be.bucketname
} }
@ -203,7 +203,7 @@ func (wr preventCloser) Close() error {
} }
// Save stores data in the backend at the handle. // Save stores data in the backend at the handle.
func (be *s3) Save(ctx context.Context, h restic.Handle, rd io.Reader) (err error) { func (be *Backend) Save(ctx context.Context, h restic.Handle, rd io.Reader) (err error) {
if err := h.Valid(); err != nil { if err := h.Valid(); err != nil {
return err return err
} }
@ -259,7 +259,7 @@ func (wr wrapReader) Close() error {
// Load 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 // given offset. If length is nonzero, only a portion of the file is
// returned. rd must be closed after use. // returned. rd must be closed after use.
func (be *s3) Load(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error) { func (be *Backend) Load(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
debug.Log("Load %v, length %v, offset %v from %v", h, length, offset, be.Filename(h)) debug.Log("Load %v, length %v, offset %v from %v", h, length, offset, be.Filename(h))
if err := h.Valid(); err != nil { if err := h.Valid(); err != nil {
return nil, err return nil, err
@ -304,7 +304,7 @@ func (be *s3) Load(ctx context.Context, h restic.Handle, length int, offset int6
} }
// Stat returns information about a blob. // Stat returns information about a blob.
func (be *s3) Stat(ctx context.Context, h restic.Handle) (bi restic.FileInfo, err error) { func (be *Backend) Stat(ctx context.Context, h restic.Handle) (bi restic.FileInfo, err error) {
debug.Log("%v", h) debug.Log("%v", h)
objName := be.Filename(h) objName := be.Filename(h)
@ -334,7 +334,7 @@ func (be *s3) Stat(ctx context.Context, h restic.Handle) (bi restic.FileInfo, er
} }
// Test returns true if a blob of the given type and name exists in the backend. // Test returns true if a blob of the given type and name exists in the backend.
func (be *s3) Test(ctx context.Context, h restic.Handle) (bool, error) { func (be *Backend) Test(ctx context.Context, h restic.Handle) (bool, error) {
found := false found := false
objName := be.Filename(h) objName := be.Filename(h)
_, err := be.client.StatObject(be.bucketname, objName) _, err := be.client.StatObject(be.bucketname, objName)
@ -347,7 +347,7 @@ func (be *s3) Test(ctx context.Context, h restic.Handle) (bool, error) {
} }
// Remove removes the blob with the given name and type. // Remove removes the blob with the given name and type.
func (be *s3) Remove(ctx context.Context, h restic.Handle) error { func (be *Backend) Remove(ctx context.Context, h restic.Handle) error {
objName := be.Filename(h) objName := be.Filename(h)
err := be.client.RemoveObject(be.bucketname, objName) err := be.client.RemoveObject(be.bucketname, objName)
debug.Log("Remove(%v) at %v -> err %v", h, objName, err) debug.Log("Remove(%v) at %v -> err %v", h, objName, err)
@ -357,7 +357,7 @@ func (be *s3) Remove(ctx context.Context, h restic.Handle) error {
// List returns a channel that yields all names of blobs of type t. A // List returns a channel that yields all names of blobs of type t. A
// goroutine is started for this. If the channel done is closed, sending // goroutine is started for this. If the channel done is closed, sending
// stops. // stops.
func (be *s3) List(ctx context.Context, t restic.FileType) <-chan string { func (be *Backend) List(ctx context.Context, t restic.FileType) <-chan string {
debug.Log("listing %v", t) debug.Log("listing %v", t)
ch := make(chan string) ch := make(chan string)
@ -390,7 +390,7 @@ func (be *s3) List(ctx context.Context, t restic.FileType) <-chan string {
} }
// Remove keys for a specified backend type. // Remove keys for a specified backend type.
func (be *s3) removeKeys(ctx context.Context, t restic.FileType) error { func (be *Backend) removeKeys(ctx context.Context, t restic.FileType) error {
for key := range be.List(ctx, restic.DataFile) { for key := range be.List(ctx, restic.DataFile) {
err := be.Remove(ctx, restic.Handle{Type: restic.DataFile, Name: key}) err := be.Remove(ctx, restic.Handle{Type: restic.DataFile, Name: key})
if err != nil { if err != nil {
@ -402,7 +402,7 @@ func (be *s3) removeKeys(ctx context.Context, t restic.FileType) error {
} }
// Delete removes all restic keys in the bucket. It will not remove the bucket itself. // Delete removes all restic keys in the bucket. It will not remove the bucket itself.
func (be *s3) Delete(ctx context.Context) error { func (be *Backend) Delete(ctx context.Context) error {
alltypes := []restic.FileType{ alltypes := []restic.FileType{
restic.DataFile, restic.DataFile,
restic.KeyFile, restic.KeyFile,
@ -421,4 +421,4 @@ func (be *s3) Delete(ctx context.Context) error {
} }
// Close does nothing // Close does nothing
func (be *s3) Close() error { return nil } func (be *Backend) Close() error { return nil }