Skip to content

Commit

Permalink
Remove duplicated code for StatObject() (#1584)
Browse files Browse the repository at this point in the history
Clean up duplicate internal functions.

fixes #1583
  • Loading branch information
klauspost committed Nov 15, 2021
1 parent f18c9fc commit fd3932c
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 22 deletions.
2 changes: 1 addition & 1 deletion api-compose-object.go
Expand Up @@ -398,7 +398,7 @@ func (c *Client) ComposeObject(ctx context.Context, dst CopyDestOptions, srcs ..
var err error
for i, src := range srcs {
opts := StatObjectOptions{ServerSideEncryption: encrypt.SSE(src.Encryption), VersionID: src.VersionID}
srcObjectInfos[i], err = c.statObject(context.Background(), src.Bucket, src.Object, opts)
srcObjectInfos[i], err = c.StatObject(context.Background(), src.Bucket, src.Object, opts)
if err != nil {
return UploadInfo{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion api-get-object-acl.go
Expand Up @@ -75,7 +75,7 @@ func (c *Client) GetObjectACL(ctx context.Context, bucketName, objectName string
return nil, err
}

objInfo, err := c.statObject(ctx, bucketName, objectName, StatObjectOptions{})
objInfo, err := c.StatObject(ctx, bucketName, objectName, StatObjectOptions{})
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions api-get-object.go
Expand Up @@ -139,7 +139,7 @@ func (c *Client) GetObject(ctx context.Context, bucketName, objectName string, o

// Remove range header if already set, for stat Operations to get original file size.
delete(opts.headers, "Range")
objectInfo, err = c.statObject(ctx, bucketName, objectName, StatObjectOptions(opts))
objectInfo, err = c.StatObject(ctx, bucketName, objectName, StatObjectOptions(opts))
if err != nil {
resCh <- getResponse{
Error: err,
Expand All @@ -162,7 +162,7 @@ func (c *Client) GetObject(ctx context.Context, bucketName, objectName string, o
if etag != "" && !snowball {
opts.SetMatchETag(etag)
}
objectInfo, err := c.statObject(ctx, bucketName, objectName, StatObjectOptions(opts))
objectInfo, err := c.StatObject(ctx, bucketName, objectName, StatObjectOptions(opts))
if err != nil {
resCh <- getResponse{
Error: err,
Expand Down
12 changes: 0 additions & 12 deletions api-stat.go
Expand Up @@ -59,18 +59,6 @@ func (c *Client) BucketExists(ctx context.Context, bucketName string) (bool, err

// StatObject verifies if object exists and you have permission to access.
func (c *Client) StatObject(ctx context.Context, bucketName, objectName string, opts StatObjectOptions) (ObjectInfo, error) {
// Input validation.
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return ObjectInfo{}, err
}
if err := s3utils.CheckValidObjectName(objectName); err != nil {
return ObjectInfo{}, err
}
return c.statObject(ctx, bucketName, objectName, opts)
}

// Lower level API for statObject supporting pre-conditions and range headers.
func (c *Client) statObject(ctx context.Context, bucketName, objectName string, opts StatObjectOptions) (ObjectInfo, error) {
// Input validation.
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return ObjectInfo{}, err
Expand Down
6 changes: 0 additions & 6 deletions core.go
Expand Up @@ -125,9 +125,3 @@ func (c Core) PutBucketPolicy(ctx context.Context, bucket, bucketPolicy string)
func (c Core) GetObject(ctx context.Context, bucketName, objectName string, opts GetObjectOptions) (io.ReadCloser, ObjectInfo, http.Header, error) {
return c.getObject(ctx, bucketName, objectName, opts)
}

// StatObject is a lower level API implemented to support special
// conditions matching etag, modtime on a request.
func (c Core) StatObject(ctx context.Context, bucketName, objectName string, opts StatObjectOptions) (ObjectInfo, error) {
return c.statObject(ctx, bucketName, objectName, opts)
}

0 comments on commit fd3932c

Please sign in to comment.