Skip to content

Commit

Permalink
Merge pull request #148 from akevdmeer/revert-s3-stat-object-instead-…
Browse files Browse the repository at this point in the history
…of-empty-read

Revert "s3: stat object instead of empty read"
  • Loading branch information
MichaHoffmann authored Oct 10, 2024
2 parents 8897e65 + 25c6a36 commit f90c89a
Showing 1 changed file with 13 additions and 3 deletions.
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

0 comments on commit f90c89a

Please sign in to comment.