mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-21 07:24:19 +00:00
@@ -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,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,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.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user