From 95ee8f07142d05d956d038f31575fb459de2fb02 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 3 Jan 2021 11:34:53 -0800 Subject: [PATCH] list with maxKeys=1 for url2Stat() calls (#3557) --- cmd/client-s3.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/client-s3.go b/cmd/client-s3.go index 568b025d..11896ff2 100644 --- a/cmd/client-s3.go +++ b/cmd/client-s3.go @@ -1315,6 +1315,19 @@ func (c *S3Client) SetAccess(ctx context.Context, bucketPolicy string, isJSON bo return nil } +func (c *S3Client) listObjectWrapperSingleKey(ctx context.Context, bucket, object string, isRecursive bool, timeRef time.Time, withVersions, withDeleteMarkers bool, metadata bool) <-chan minio.ObjectInfo { + if !timeRef.IsZero() || withVersions { + return c.listVersions(ctx, bucket, object, isRecursive, timeRef, withVersions, withDeleteMarkers) + } + + if isGoogle(c.targetURL.Host) { + // Google Cloud S3 layer doesn't implement ListObjectsV2 implementation + // https://github.com/minio/mc/issues/3073 + return c.api.ListObjects(ctx, bucket, minio.ListObjectsOptions{Prefix: object, Recursive: isRecursive, UseV1: true, MaxKeys: 1}) + } + return c.api.ListObjects(ctx, bucket, minio.ListObjectsOptions{Prefix: object, Recursive: isRecursive, WithMetadata: metadata, MaxKeys: 1}) +} + // listObjectWrapper - select ObjectList mode depending on arguments func (c *S3Client) listObjectWrapper(ctx context.Context, bucket, object string, isRecursive bool, timeRef time.Time, withVersions, withDeleteMarkers bool, metadata bool) <-chan minio.ObjectInfo { if !timeRef.IsZero() || withVersions { @@ -1418,7 +1431,7 @@ func (c *S3Client) Stat(ctx context.Context, opts StatOptions) (*ClientContent, // Prefix to pass to minio-go listing in order to fetch if a prefix exists prefix := strings.TrimRight(object, string(c.targetURL.Separator)) - for objectStat := range c.listObjectWrapper(ctx, bucket, prefix, nonRecursive, opts.timeRef, false, false, false) { + for objectStat := range c.listObjectWrapperSingleKey(ctx, bucket, prefix, nonRecursive, opts.timeRef, false, false, false) { if objectStat.Err != nil { return nil, probe.NewError(objectStat.Err) }