Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services/*: Check metadata value before set #235

Merged
merged 1 commit into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions services/azblob/storager.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,23 @@ func (s *Storage) Stat(path string, pairs ...*types.Pair) (o *types.Object, err
ObjectMeta: metadata.NewObjectMeta(),
}

o.SetETag(string(output.ETag()))

if output.ContentType() != "" {
o.SetContentType(output.ContentType())
if v := string(output.ETag()); v != "" {
o.SetETag(v)
}
if len(output.ContentMD5()) > 0 {
o.SetContentMD5(base64.StdEncoding.EncodeToString(output.ContentMD5()))
if v := output.ContentType(); v != "" {
o.SetContentType(v)
}

storageClass, err := formatStorageClass(azblob.AccessTierType(output.AccessTier()))
if err != nil {
return nil, err
if v := output.ContentMD5(); len(v) > 0 {
o.SetContentMD5(base64.StdEncoding.EncodeToString(v))
}
if v := output.AccessTier(); v != "" {
storageClass, err := formatStorageClass(azblob.AccessTierType(v))
if err != nil {
return nil, err
}
o.SetStorageClass(storageClass)
}
o.SetStorageClass(storageClass)

return o, nil
}

Expand Down Expand Up @@ -278,12 +281,13 @@ func (s *Storage) formatFileObject(v azblob.BlobItem) (o *types.Object, err erro
if len(v.Properties.ContentMD5) > 0 {
o.SetContentMD5(base64.StdEncoding.EncodeToString(v.Properties.ContentMD5))
}

storageClass, err := formatStorageClass(v.Properties.AccessTier)
if err != nil {
return nil, err
if value := v.Properties.AccessTier; len(value) > 0 {
storageClass, err := formatStorageClass(v.Properties.AccessTier)
if err != nil {
return nil, err
}
o.SetStorageClass(storageClass)
}
o.SetStorageClass(storageClass)

return o, nil
}
Expand Down
44 changes: 27 additions & 17 deletions services/cos/storager.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,28 @@ func (s *Storage) List(path string, pairs ...*types.Pair) (err error) {
// encryption method, so we can't treat this value as content-md5
//
// ref: https://cloud.tencent.com/document/product/436/7729
o.SetETag(v.ETag)
if v.ETag != "" {
o.SetETag(v.ETag)
}

// COS uses ISO8601 format: "2019-05-27T11:26:14.000Z" in List
//
// ref: https://cloud.tencent.com/document/product/436/7729
t, err := time.Parse("2006-01-02T15:04:05.999Z", v.LastModified)
if err != nil {
return err
if v.LastModified != "" {
t, err := time.Parse("2006-01-02T15:04:05.999Z", v.LastModified)
if err != nil {
return err
}
o.UpdatedAt = t
}
o.UpdatedAt = t

storageClass, err := formatStorageClass(v.StorageClass)
if err != nil {
return err
if v.StorageClass != "" {
storageClass, err := formatStorageClass(v.StorageClass)
if err != nil {
return err
}
o.SetStorageClass(storageClass)
}
o.SetStorageClass(storageClass)

if opt.HasObjectFunc {
opt.ObjectFunc(o)
Expand Down Expand Up @@ -235,11 +241,13 @@ func (s *Storage) Stat(path string, pairs ...*types.Pair) (o *types.Object, err
// > Last-Modified: Fri, 09 Aug 2019 10:20:56 GMT
//
// ref: https://cloud.tencent.com/document/product/436/7745
lastModified, err := time.Parse(time.RFC1123, output.Header.Get("Last-Modified"))
if err != nil {
return nil, err
if v := output.Header.Get("Last-Modified"); v != "" {
lastModified, err := time.Parse(time.RFC1123, v)
if err != nil {
return nil, err
}
o.UpdatedAt = lastModified
}
o.UpdatedAt = lastModified

if v := output.Header.Get("Content-Type"); v != "" {
o.SetContentType(v)
Expand All @@ -249,11 +257,13 @@ func (s *Storage) Stat(path string, pairs ...*types.Pair) (o *types.Object, err
o.SetETag(output.Header.Get(v))
}

storageClass, err := formatStorageClass(output.Header.Get(storageClassHeader))
if err != nil {
return nil, err
if v := output.Header.Get(storageClassHeader); v != "" {
storageClass, err := formatStorageClass(v)
if err != nil {
return nil, err
}
o.SetStorageClass(storageClass)
}
o.SetStorageClass(storageClass)

return o, nil
}
Expand Down
8 changes: 6 additions & 2 deletions services/dropbox/storager.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ func (s *Storage) List(path string, pairs ...*types.Pair) (err error) {
ObjectMeta: metadata.NewObjectMeta(),
}

o.SetETag(meta.ContentHash)
if meta.ContentHash != "" {
o.SetETag(meta.ContentHash)
}

if opt.HasFileFunc {
opt.FileFunc(o)
Expand Down Expand Up @@ -206,7 +208,9 @@ func (s *Storage) Stat(path string, pairs ...*types.Pair) (o *types.Object, err
ObjectMeta: metadata.NewObjectMeta(),
}

o.SetETag(meta.ContentHash)
if meta.ContentHash != "" {
o.SetETag(meta.ContentHash)
}

return o, nil
case *files.FolderMetadata:
Expand Down
11 changes: 6 additions & 5 deletions services/gcs/storager.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,13 @@ func (s *Storage) formatFileObject(v *gs.ObjectAttrs) (o *types.Object, err erro
if len(v.MD5) > 0 {
o.SetContentMD5(base64.StdEncoding.EncodeToString(v.MD5))
}

storageClass, err := formatStorageClass(v.StorageClass)
if err != nil {
return nil, err
if v.StorageClass != "" {
storageClass, err := formatStorageClass(v.StorageClass)
if err != nil {
return nil, err
}
o.SetStorageClass(storageClass)
}
o.SetStorageClass(storageClass)

return
}
16 changes: 12 additions & 4 deletions services/kodo/storager.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ func (s *Storage) List(path string, pairs ...*types.Pair) (err error) {
ObjectMeta: metadata.NewObjectMeta(),
}

o.SetContentType(v.MimeType)
o.SetETag(v.Hash)
if v.MimeType != "" {
o.SetContentType(v.MimeType)
}
if v.Hash != "" {
o.SetETag(v.Hash)
}

storageClass, err := formatStorageClass(v.Type)
if err != nil {
Expand Down Expand Up @@ -193,8 +197,12 @@ func (s *Storage) Stat(path string, pairs ...*types.Pair) (o *types.Object, err
ObjectMeta: metadata.NewObjectMeta(),
}

o.SetETag(fi.Hash)
o.SetContentType(fi.MimeType)
if fi.Hash != "" {
o.SetETag(fi.Hash)
}
if fi.MimeType != "" {
o.SetContentType(fi.MimeType)
}

storageClass, err := formatStorageClass(fi.Type)
if err != nil {
Expand Down
58 changes: 38 additions & 20 deletions services/oss/storager.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,24 @@ func (s *Storage) List(path string, pairs ...*types.Pair) (err error) {
ObjectMeta: metadata.NewObjectMeta(),
}

o.SetContentType(v.Type)
if v.Type != "" {
o.SetContentType(v.Type)
}

// OSS advise us don't use Etag as Content-MD5.
//
// ref: https://help.aliyun.com/document_detail/31965.html
o.SetETag(v.ETag)
if v.ETag != "" {
o.SetETag(v.ETag)
}

storageClass, err := formatStorageClass(v.Type)
if err != nil {
return err
if v.Type != "" {
storageClass, err := formatStorageClass(v.Type)
if err != nil {
return err
}
o.SetStorageClass(storageClass)
}
o.SetStorageClass(storageClass)

if opt.HasObjectFunc {
opt.ObjectFunc(o)
Expand Down Expand Up @@ -207,29 +214,40 @@ func (s *Storage) Stat(path string, pairs ...*types.Pair) (o *types.Object, err
ObjectMeta: metadata.NewObjectMeta(),
}

size, err := strconv.ParseInt(output.Get("Content-Length"), 10, 64)
if err != nil {
return nil, err
if v := output.Get("Content-Length"); v != "" {
size, err := strconv.ParseInt(v, 10, 64)
if err != nil {
return nil, err
}
o.Size = size
}
o.Size = size

lastModified, err := time.Parse(time.RFC822, output.Get("Last-Modified"))
if err != nil {
return nil, err
if v := output.Get("Last-Modified"); v != "" {
lastModified, err := time.Parse(time.RFC822, v)
if err != nil {
return nil, err
}
o.UpdatedAt = lastModified
}
o.UpdatedAt = lastModified

// OSS advise us don't use Etag as Content-MD5.
//
// ref: https://help.aliyun.com/document_detail/31965.html
o.SetETag(output.Get("ETag"))
o.SetContentType(output.Get("Content-Type"))
if v := output.Get("ETag"); v != "" {
o.SetETag(v)
}

storageClass, err := formatStorageClass(output.Get(storageClassHeader))
if err != nil {
return nil, err
if v := output.Get("Content-Type"); v != "" {
o.SetContentType(v)
}

if v := output.Get(storageClassHeader); v != "" {
storageClass, err := formatStorageClass(v)
if err != nil {
return nil, err
}
o.SetStorageClass(storageClass)
}
o.SetStorageClass(storageClass)

return o, nil
}
Expand Down
10 changes: 6 additions & 4 deletions services/qingstor/storager.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,13 @@ func (s *Storage) Stat(path string, pairs ...*types.Pair) (o *types.Object, err
o.SetETag(service.StringValue(output.ETag))
}

storageClass, err := formatStorageClass(service.StringValue(output.XQSStorageClass))
if err != nil {
return
if v := service.StringValue(output.XQSStorageClass); v != "" {
storageClass, err := formatStorageClass(v)
if err != nil {
return nil, err
}
o.SetStorageClass(storageClass)
}
o.SetStorageClass(storageClass)

return o, nil
}
Expand Down
17 changes: 13 additions & 4 deletions services/uss/storager.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ func (s *Storage) List(path string, pairs ...*types.Pair) (err error) {
UpdatedAt: v.Time,
ObjectMeta: metadata.NewObjectMeta(),
}
o.SetETag(v.ETag)
o.SetContentType(v.ContentType)

if v.ETag != "" {
o.SetETag(v.ETag)
}
if v.ContentType != "" {
o.SetContentType(v.ContentType)
}

if opt.HasObjectFunc {
opt.ObjectFunc(o)
Expand Down Expand Up @@ -187,8 +192,12 @@ func (s *Storage) Stat(path string, pairs ...*types.Pair) (o *types.Object, err
UpdatedAt: output.Time,
ObjectMeta: metadata.NewObjectMeta(),
}
o.SetETag(output.ETag)
o.SetContentType(output.ContentType)
if output.ETag != "" {
o.SetETag(output.ETag)
}
if output.ContentType != "" {
o.SetContentType(output.ContentType)
}

return o, nil
}
Expand Down