MCPcopy
hub / github.com/minio/minio-go / StatObject

Method StatObject

api-stat.go:61–124  ·  view source on GitHub ↗

StatObject verifies if object exists, you have permission to access it and returns information about the object.

(ctx context.Context, bucketName, objectName string, opts StatObjectOptions)

Source from the content-addressed store, hash-verified

59// StatObject verifies if object exists, you have permission to access it
60// and returns information about the object.
61func (c *Client) StatObject(ctx context.Context, bucketName, objectName string, opts StatObjectOptions) (ObjectInfo, error) {
62 // Input validation.
63 if err := s3utils.CheckValidBucketName(bucketName); err != nil {
64 return ObjectInfo{}, ErrorResponse{
65 StatusCode: http.StatusBadRequest,
66 Code: InvalidBucketName,
67 Message: err.Error(),
68 }
69 }
70 if err := s3utils.CheckValidObjectName(objectName); err != nil {
71 return ObjectInfo{}, ErrorResponse{
72 StatusCode: http.StatusBadRequest,
73 Code: XMinioInvalidObjectName,
74 Message: err.Error(),
75 }
76 }
77 headers := opts.Header()
78 if opts.Internal.ReplicationDeleteMarker {
79 headers.Set(minIOBucketReplicationDeleteMarker, "true")
80 }
81 if opts.Internal.IsReplicationReadyForDeleteMarker {
82 headers.Set(isMinioTgtReplicationReady, "true")
83 }
84
85 // Execute HEAD on objectName.
86 resp, err := c.executeMethod(ctx, http.MethodHead, requestMetadata{
87 bucketName: bucketName,
88 objectName: objectName,
89 queryValues: opts.toQueryValues(),
90 contentSHA256Hex: emptySHA256Hex,
91 customHeader: headers,
92 })
93 defer closeResponse(resp)
94 if err != nil {
95 return ObjectInfo{}, err
96 }
97
98 if resp != nil {
99 deleteMarker := resp.Header.Get(amzDeleteMarker) == "true"
100 replicationReady := resp.Header.Get(minioTgtReplicationReady) == "true"
101 if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent {
102 if resp.StatusCode == http.StatusMethodNotAllowed && opts.VersionID != "" && deleteMarker {
103 errResp := ErrorResponse{
104 StatusCode: resp.StatusCode,
105 Code: MethodNotAllowed,
106 Message: s3ErrorResponseMap[MethodNotAllowed],
107 BucketName: bucketName,
108 Key: objectName,
109 }
110 return ObjectInfo{
111 VersionID: resp.Header.Get(amzVersionID),
112 IsDeleteMarker: deleteMarker,
113 }, errResp
114 }
115 return ObjectInfo{
116 VersionID: resp.Header.Get(amzVersionID),
117 IsDeleteMarker: deleteMarker,
118 ReplicationReady: replicationReady, // whether delete marker can be replicated

Callers 15

FGetObjectMethod · 0.95
GetObjectACLMethod · 0.95
AppendObjectMethod · 0.95
ComposeObjectMethod · 0.95
GetObjectMethod · 0.95
testPutObjectStreamingFunction · 0.95
testFPutObjectFunction · 0.95
testFPutObjectContextFunction · 0.95

Calls 11

executeMethodMethod · 0.95
CheckValidBucketNameFunction · 0.92
CheckValidObjectNameFunction · 0.92
httpRespToErrorResponseFunction · 0.85
ToObjectInfoFunction · 0.85
closeResponseFunction · 0.70
ErrorMethod · 0.45
HeaderMethod · 0.45
SetMethod · 0.45
toQueryValuesMethod · 0.45
GetMethod · 0.45

Tested by 3

TestGetObjectCoreFunction · 0.64
TestCoreCopyObjectFunction · 0.64
TestCoreCopyObjectPartFunction · 0.64