diff --git a/cmd/client-s3.go b/cmd/client-s3.go index 11fb87e9..cd0178da 100644 --- a/cmd/client-s3.go +++ b/cmd/client-s3.go @@ -1600,13 +1600,9 @@ func (c *S3Client) Stat(ctx context.Context, opts StatOptions) (*ClientContent, // - /path/to/directory_marker // - /path/to/directory_marker/ - // First an HEAD call is issued, this is faster than doing listing even if the object exists - // because the list could be very large. At the same time, the HEAD call is avoided if the - // object already contains a trailing prefix or we passed rewind flag to know the object version - // created just before the rewind parameter. + // Start with a HEAD request first to return object metadata information. + // If the object is not found, continue to look for a directory marker or a prefix if !strings.HasSuffix(path, string(c.targetURL.Separator)) && opts.timeRef.IsZero() { - // Issue HEAD request first but ignore no such key error - // so we can check if there is such prefix which exists o := minio.StatObjectOptions{ServerSideEncryption: opts.sse, VersionID: opts.versionID} if opts.isZip { o.Set("x-minio-extract", "true") @@ -1615,16 +1611,11 @@ func (c *S3Client) Stat(ctx context.Context, opts StatOptions) (*ClientContent, if err == nil { return ctnt, nil } - // Ignore object missing error but return for other errors if !errors.As(err.ToGoError(), &ObjectMissing{}) && !errors.As(err.ToGoError(), &ObjectIsDeleteMarker{}) { return nil, err } - } - - // No object found, start looking for a prefix with the same name - // or a directory marker. Add a trailing slash if it is not in the path - if !strings.HasSuffix(path, string(c.targetURL.Separator)) { + // The object is not found, look for a directory marker or a prefix path += string(c.targetURL.Separator) }