mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #2626 from swordqiu/hotfix/qj-compatible-with-minio-s3
fix: compatible with minio s3
This commit is contained in:
@@ -242,12 +242,19 @@ func GetIObjects(bucket ICloudBucket, objectPrefix string, isRecursive bool) ([]
|
||||
}
|
||||
|
||||
func GetIObject(bucket ICloudBucket, objectPrefix string) (ICloudObject, error) {
|
||||
objects, err := GetIObjects(bucket, objectPrefix, true)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIObjects")
|
||||
tryPrefix := []string{objectPrefix}
|
||||
if strings.HasSuffix(objectPrefix, "/") {
|
||||
tryPrefix = append(tryPrefix, objectPrefix[:len(objectPrefix)-1])
|
||||
}
|
||||
if len(objects) > 0 && objects[0].GetKey() == objectPrefix {
|
||||
return objects[0], nil
|
||||
for _, pref := range tryPrefix {
|
||||
result, err := bucket.ListObjects(pref, "", "", 1)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "bucket.ListObjects")
|
||||
}
|
||||
objects := result.Objects
|
||||
if len(objects) > 0 && objects[0].GetKey() == objectPrefix {
|
||||
return objects[0], nil
|
||||
}
|
||||
}
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ type SBucket struct {
|
||||
|
||||
SManagedResourceBase
|
||||
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"admin_required"`
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"required"`
|
||||
|
||||
StorageClass string `width:"36" charset:"ascii" nullable:"false" list:"user"`
|
||||
Location string `width:"36" charset:"ascii" nullable:"false" list:"user"`
|
||||
|
||||
@@ -168,10 +168,10 @@ func (bucket *SBucket) PutObject(ctx context.Context, key string, input io.Reade
|
||||
}
|
||||
obj, err := cloudprovider.GetIObject(bucket, key)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "GetIObject")
|
||||
return errors.Wrap(err, "cloudprovider.GetIObject")
|
||||
}
|
||||
err = obj.SetAcl(cannedAcl)
|
||||
if err != nil {
|
||||
if err != nil && errors.Cause(err) != cloudprovider.ErrNotImplemented {
|
||||
return errors.Wrap(err, "obj.SetAcl")
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -15,9 +15,11 @@
|
||||
package objectstore
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/pkg/errors"
|
||||
)
|
||||
|
||||
type SObject struct {
|
||||
@@ -42,7 +44,11 @@ func (o *SObject) GetAcl() cloudprovider.TBucketACLType {
|
||||
func (o *SObject) SetAcl(aclStr cloudprovider.TBucketACLType) error {
|
||||
err := o.bucket.client.SetObjectAcl(o.bucket.Name, o.Key, aclStr)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "o.bucket.client.SetObjectAcl")
|
||||
if strings.Contains(err.Error(), "not implemented") {
|
||||
return cloudprovider.ErrNotImplemented
|
||||
} else {
|
||||
return errors.Wrap(err, "o.bucket.client.SetObjectAcl")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user