s3: fix usage

Ignore error response for existing bucket, add more debug code.
This commit is contained in:
Alexander Neumann 2015-12-28 18:55:15 +01:00
parent 2b10791df2
commit 1922a4272c
2 changed files with 25 additions and 3 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/minio/minio-go"
"github.com/restic/restic/backend"
"github.com/restic/restic/debug"
)
const maxKeysInList = 1000
@ -28,7 +29,8 @@ type S3Backend struct {
bucketname string
}
// Open opens the S3 backend at bucket and region. The bucket is created if it does not exist yet.
// Open opens the S3 backend at bucket and region. The bucket is created if it
// does not exist yet.
func Open(cfg Config) (backend.Backend, error) {
mcfg := minio.Config{
AccessKeyID: cfg.KeyID,
@ -54,6 +56,15 @@ func Open(cfg Config) (backend.Backend, error) {
be.createConnections()
err = s3api.MakeBucket(cfg.Bucket, "")
if err != nil {
e, ok := err.(minio.ErrorResponse)
if ok && e.Code == "BucketAlreadyExists" {
debug.Log("s3.Open", "ignoring error that bucket %q already exists", cfg.Bucket)
err = nil
}
}
if err != nil {
return nil, err
}