Skip to content

Commit

Permalink
modify IsObjectExist
Browse files Browse the repository at this point in the history
  • Loading branch information
dengwu12 committed Apr 24, 2017
1 parent 404dd50 commit 95f2f5f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions oss/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,15 +440,19 @@ func (bucket Bucket) DeleteObjects(objectKeys []string, options ...Option) (Dele
// error 操作无错误为nil,非nil为错误信息。
//
func (bucket Bucket) IsObjectExist(objectKey string) (bool, error) {
listRes, err := bucket.ListObjects(Prefix(objectKey), MaxKeys(1))
if err != nil {
return false, err
_, err := bucket.GetObjectMeta(objectKey)
if err == nil {
return true, nil
}

if len(listRes.Objects) == 1 && listRes.Objects[0].Key == objectKey {
return true, nil
switch err.(type) {
case ServiceError:
if err.(ServiceError).StatusCode == 404 && err.(ServiceError).Code == "NoSuchKey" {
return false, nil
}
}
return false, nil

return false, err
}

//
Expand Down

0 comments on commit 95f2f5f

Please sign in to comment.