forked from TrueCloudLab/frostfs-s3-gw
[#125] Fixed bucket creation
Bucket should has unique name. Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
e7bebcc1aa
commit
0aae8c595a
2 changed files with 14 additions and 1 deletions
|
@ -124,6 +124,7 @@ func (h *handler) CreateBucketHandler(w http.ResponseWriter, r *http.Request) {
|
|||
Description: err.Error(),
|
||||
HTTPStatusCode: http.StatusInternalServerError,
|
||||
}, r.URL)
|
||||
return
|
||||
}
|
||||
|
||||
h.log.Info("bucket is created",
|
||||
|
|
|
@ -127,6 +127,8 @@ var (
|
|||
ErrObjectExists = errors.New("object exists")
|
||||
// ErrObjectNotExists is returned on attempts to work with non-existing object.
|
||||
ErrObjectNotExists = errors.New("object not exists")
|
||||
// ErrBucketAlreadyExists is returned on attempts to create already existing bucket.
|
||||
ErrBucketAlreadyExists = errors.New("bucket exists")
|
||||
)
|
||||
|
||||
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) {
|
||||
_, 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 {
|
||||
|
|
Loading…
Reference in a new issue