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

Revert "s3: stat object instead of empty read" #148

Merged
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
16 changes: 13 additions & 3 deletions providers/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strings"
"testing"

"github.com/efficientgo/core/logerrcapture"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/minio/minio-go/v7"
Expand Down Expand Up @@ -437,12 +438,21 @@ func (b *Bucket) getRange(ctx context.Context, name string, off, length int64) (
return nil, err
}
}
r, err := b.client.GetObject(ctx, b.name, name, *opts)
if err != nil {
return nil, err
}

// StatObject to see if the object exists and we have permissions to read it
if _, err := b.client.StatObject(ctx, b.name, name, *opts); err != nil {
// NotFoundObject error is revealed only after first Read. This does the initial GetRequest. Prefetch this here
// for convenience.
if _, err := r.Read(nil); err != nil {
defer logerrcapture.Do(b.logger, r.Close, "s3 get range obj close")

// First GET Object request error.
return nil, err
}
return b.client.GetObject(ctx, b.name, name, *opts)

return r, nil
}

// Get returns a reader for the given object name.
Expand Down
Loading