Address code review

Signed-off-by: Carlisia <carlisiac@vmware.com>
This commit is contained in:
Carlisia
2019-04-24 10:54:43 -07:00
parent 38ccb40ca1
commit 7d28f82540
10 changed files with 46 additions and 75 deletions
+19 -20
View File
@@ -220,30 +220,29 @@ func (o *ObjectStore) ObjectExists(bucket, key string) (bool, error) {
log.Debug("Checking if object exists")
_, err := o.s3.HeadObject(req)
if err == nil {
log.Debug("Object exists")
return true, nil
}
if err != nil {
log.Debug("Checking for AWS specific error information")
if aerr, ok := err.(awserr.Error); ok {
log.WithFields(
logrus.Fields{
"code": aerr.Code(),
"message": aerr.Message(),
},
).Debugf("awserr.Error contents (origErr=%v)", aerr.OrigErr())
log.Debug("Checking for AWS specific error information")
if aerr, ok := err.(awserr.Error); ok {
log.WithFields(
logrus.Fields{
"code": aerr.Code(),
"message": aerr.Message(),
},
).Debugf("awserr.Error contents (origErr=%v)", aerr.OrigErr())
// The code will be NotFound if the key doesn't exist.
// See https://github.com/aws/aws-sdk-go/issues/1208 and https://github.com/aws/aws-sdk-go/pull/1213.
log.Debugf("Checking for code=%s", notFoundCode)
if aerr.Code() == notFoundCode {
log.Debug("Object doesn't exist - got not found")
return false, nil
// The code will be NotFound if the key doesn't exist.
// See https://github.com/aws/aws-sdk-go/issues/1208 and https://github.com/aws/aws-sdk-go/pull/1213.
log.Debugf("Checking for code=%s", notFoundCode)
if aerr.Code() == notFoundCode {
log.Debug("Object doesn't exist - got not found")
return false, nil
}
}
return false, errors.WithStack(err)
}
return false, errors.WithStack(err)
log.Debug("Object exists")
return true, nil
}
func (o *ObjectStore) GetObject(bucket, key string) (io.ReadCloser, error) {
+1 -1
View File
@@ -1,5 +1,5 @@
/*
Copyright 2018 the Heptio Ark contributors.
Copyright 2018, 2019 the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
+1 -1
View File
@@ -1,5 +1,5 @@
/*
Copyright 2018 the Heptio Ark contributors.
Copyright 2018, 2019 the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
+6 -6
View File
@@ -125,14 +125,14 @@ func (o *ObjectStore) PutObject(bucket, key string, body io.Reader) error {
func (o *ObjectStore) ObjectExists(bucket, key string) (bool, error) {
_, err := o.bucketWriter.getAttrs(bucket, key)
switch err {
case nil:
return true, nil
case storage.ErrObjectNotExist:
return false, nil
if err != nil {
if err == storage.ErrObjectNotExist {
return false, nil
}
return false, errors.WithStack(err)
}
return false, errors.WithStack(err)
return true, nil
}
func (o *ObjectStore) GetObject(bucket, key string) (io.ReadCloser, error) {
+1 -2
View File
@@ -76,8 +76,7 @@ func (o *InMemoryObjectStore) ObjectExists(bucket, key string) (bool, error) {
return false, errors.New("bucket not found")
}
_, ok = bucketData[key]
if !ok {
if _, ok = bucketData[key]; !ok {
return false, errors.New("key not found")
}