[#125] Fixed bucket creation

Bucket should has unique name.

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2021-07-07 17:56:29 +03:00
parent e7bebcc1aa
commit 0aae8c595a
2 changed files with 14 additions and 1 deletions

View file

@ -124,6 +124,7 @@ func (h *handler) CreateBucketHandler(w http.ResponseWriter, r *http.Request) {
Description: err.Error(), Description: err.Error(),
HTTPStatusCode: http.StatusInternalServerError, HTTPStatusCode: http.StatusInternalServerError,
}, r.URL) }, r.URL)
return
} }
h.log.Info("bucket is created", h.log.Info("bucket is created",

View file

@ -127,6 +127,8 @@ var (
ErrObjectExists = errors.New("object exists") ErrObjectExists = errors.New("object exists")
// ErrObjectNotExists is returned on attempts to work with non-existing object. // ErrObjectNotExists is returned on attempts to work with non-existing object.
ErrObjectNotExists = errors.New("object not exists") ErrObjectNotExists = errors.New("object not exists")
// ErrBucketAlreadyExists is returned on attempts to create already existing bucket.
ErrBucketAlreadyExists = errors.New("bucket exists")
) )
const ( const (
@ -491,7 +493,17 @@ func (n *layer) DeleteObjects(ctx context.Context, bucket string, objects []stri
} }
func (n *layer) CreateBucket(ctx context.Context, p *CreateBucketParams) (*cid.ID, error) { func (n *layer) CreateBucket(ctx context.Context, p *CreateBucketParams) (*cid.ID, error) {
return n.createContainer(ctx, p) _, err := n.GetBucketInfo(ctx, p.Name)
if err != nil {
errMsg := err.Error()
if strings.Contains(errMsg, "bucket not found") ||
strings.Contains(errMsg, "container not found") {
return n.createContainer(ctx, p)
}
return nil, err
}
return nil, ErrBucketAlreadyExists
} }
func (n *layer) DeleteBucket(ctx context.Context, p *DeleteBucketParams) error { func (n *layer) DeleteBucket(ctx context.Context, p *DeleteBucketParams) error {