diff --git a/api/handler/acl.go b/api/handler/acl.go index 89939a55e..767718638 100644 --- a/api/handler/acl.go +++ b/api/handler/acl.go @@ -307,7 +307,7 @@ func (h *handler) GetObjectACLHandler(w http.ResponseWriter, r *http.Request) { return } - if err = api.EncodeToResponse(w, h.encodeObjectACL(bucketACL, reqInfo.BucketName, objInfo.ObjectInfo.VersionID())); err != nil { + if err = api.EncodeToResponse(w, h.encodeObjectACL(bucketACL, reqInfo.BucketName, objInfo.VersionID())); err != nil { h.logAndSendError(w, "failed to encode response", reqInfo, err) } } @@ -363,7 +363,7 @@ func (h *handler) PutObjectACLHandler(w http.ResponseWriter, r *http.Request) { VersionID: versionID, } - extendedInfo, err := h.obj.GetObjectInfo(r.Context(), p) + objInfo, err := h.obj.GetObjectInfo(r.Context(), p) if err != nil { h.logAndSendError(w, "could not get object info", reqInfo, err) return @@ -377,7 +377,7 @@ func (h *handler) PutObjectACLHandler(w http.ResponseWriter, r *http.Request) { if updated { s := &SendNotificationParams{ Event: EventObjectACLPut, - NotificationInfo: data.NotificationInfoFromObject(extendedInfo.ObjectInfo), + NotificationInfo: data.NotificationInfoFromObject(objInfo), BktInfo: bktInfo, ReqInfo: reqInfo, } diff --git a/api/handler/attributes.go b/api/handler/attributes.go index 0a2650a0a..eeab8ed82 100644 --- a/api/handler/attributes.go +++ b/api/handler/attributes.go @@ -86,7 +86,7 @@ func (h *handler) GetObjectAttributesHandler(w http.ResponseWriter, r *http.Requ VersionID: params.VersionID, } - extendedInfo, err := h.obj.GetObjectInfo(r.Context(), p) + extendedInfo, err := h.obj.GetExtendedObjectInfo(r.Context(), p) if err != nil { h.logAndSendError(w, "could not fetch object info", reqInfo, err) return diff --git a/api/handler/copy.go b/api/handler/copy.go index 36b23390e..641f6b915 100644 --- a/api/handler/copy.go +++ b/api/handler/copy.go @@ -90,33 +90,32 @@ func (h *handler) CopyObjectHandler(w http.ResponseWriter, r *http.Request) { } } - extendedInfo, err := h.obj.GetObjectInfo(r.Context(), p) + objInfo, err := h.obj.GetObjectInfo(r.Context(), p) if err != nil { h.logAndSendError(w, "could not find object", reqInfo, err) return } - info := extendedInfo.ObjectInfo - if err = checkPreconditions(info, args.Conditional); err != nil { + if err = checkPreconditions(objInfo, args.Conditional); err != nil { h.logAndSendError(w, "precondition failed", reqInfo, errors.GetAPIError(errors.ErrPreconditionFailed)) return } if metadata == nil { - if len(info.ContentType) > 0 { - info.Headers[api.ContentType] = info.ContentType + if len(objInfo.ContentType) > 0 { + objInfo.Headers[api.ContentType] = objInfo.ContentType } - metadata = info.Headers + metadata = objInfo.Headers } else if contentType := r.Header.Get(api.ContentType); len(contentType) > 0 { metadata[api.ContentType] = contentType } params := &layer.CopyObjectParams{ - SrcObject: info, + SrcObject: objInfo, ScrBktInfo: p.BktInfo, DstBktInfo: dstBktInfo, DstObject: reqInfo.ObjectName, - SrcSize: info.Size, + SrcSize: objInfo.Size, Header: metadata, } @@ -133,16 +132,16 @@ func (h *handler) CopyObjectHandler(w http.ResponseWriter, r *http.Request) { } additional := []zap.Field{zap.String("src_bucket_name", srcBucket), zap.String("src_object_name", srcObject)} - if info, err = h.obj.CopyObject(r.Context(), params); err != nil { + if objInfo, err = h.obj.CopyObject(r.Context(), params); err != nil { h.logAndSendError(w, "couldn't copy object", reqInfo, err, additional...) return - } else if err = api.EncodeToResponse(w, &CopyObjectResponse{LastModified: info.Created.UTC().Format(time.RFC3339), ETag: info.HashSum}); err != nil { + } else if err = api.EncodeToResponse(w, &CopyObjectResponse{LastModified: objInfo.Created.UTC().Format(time.RFC3339), ETag: objInfo.HashSum}); err != nil { h.logAndSendError(w, "something went wrong", reqInfo, err, additional...) return } if containsACL { - newEaclTable, err := h.getNewEAclTable(r, dstBktInfo, info) + newEaclTable, err := h.getNewEAclTable(r, dstBktInfo, objInfo) if err != nil { h.logAndSendError(w, "could not get new eacl table", reqInfo, err) return @@ -161,13 +160,13 @@ func (h *handler) CopyObjectHandler(w http.ResponseWriter, r *http.Request) { } h.log.Info("object is copied", - zap.String("bucket", info.Bucket), - zap.String("object", info.Name), - zap.Stringer("object_id", info.ID)) + zap.String("bucket", objInfo.Bucket), + zap.String("object", objInfo.Name), + zap.Stringer("object_id", objInfo.ID)) s := &SendNotificationParams{ Event: EventObjectCreatedCopy, - NotificationInfo: data.NotificationInfoFromObject(info), + NotificationInfo: data.NotificationInfoFromObject(objInfo), BktInfo: dstBktInfo, ReqInfo: reqInfo, } diff --git a/api/handler/get.go b/api/handler/get.go index 262897bc6..a287c1fb2 100644 --- a/api/handler/get.go +++ b/api/handler/get.go @@ -122,7 +122,7 @@ func (h *handler) GetObjectHandler(w http.ResponseWriter, r *http.Request) { VersionID: reqInfo.URL.Query().Get(api.QueryVersionID), } - extendedInfo, err := h.obj.GetObjectInfo(r.Context(), p) + extendedInfo, err := h.obj.GetExtendedObjectInfo(r.Context(), p) if err != nil { h.logAndSendError(w, "could not find object", reqInfo, err) return diff --git a/api/handler/head.go b/api/handler/head.go index 97198e043..b2ea61af1 100644 --- a/api/handler/head.go +++ b/api/handler/head.go @@ -46,7 +46,7 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) { VersionID: reqInfo.URL.Query().Get(api.QueryVersionID), } - extendedInfo, err := h.obj.GetObjectInfo(r.Context(), p) + extendedInfo, err := h.obj.GetExtendedObjectInfo(r.Context(), p) if err != nil { h.logAndSendError(w, "could not find object", reqInfo, err) return diff --git a/api/handler/multipart_upload.go b/api/handler/multipart_upload.go index b1fb55d0c..a7ac0f13c 100644 --- a/api/handler/multipart_upload.go +++ b/api/handler/multipart_upload.go @@ -261,7 +261,7 @@ func (h *handler) UploadPartCopy(w http.ResponseWriter, r *http.Request) { return } - extSrcInfo, err := h.obj.GetObjectInfo(r.Context(), &layer.HeadObjectParams{ + srcInfo, err := h.obj.GetObjectInfo(r.Context(), &layer.HeadObjectParams{ BktInfo: srcBktInfo, Object: srcObject, VersionID: versionID, @@ -283,7 +283,7 @@ func (h *handler) UploadPartCopy(w http.ResponseWriter, r *http.Request) { return } - if err = checkPreconditions(extSrcInfo.ObjectInfo, args.Conditional); err != nil { + if err = checkPreconditions(srcInfo, args.Conditional); err != nil { h.logAndSendError(w, "precondition failed", reqInfo, errors.GetAPIError(errors.ErrPreconditionFailed), additional...) return @@ -295,7 +295,7 @@ func (h *handler) UploadPartCopy(w http.ResponseWriter, r *http.Request) { Bkt: bktInfo, Key: reqInfo.ObjectName, }, - SrcObjInfo: extSrcInfo.ObjectInfo, + SrcObjInfo: srcInfo, SrcBktInfo: srcBktInfo, PartNumber: partNumber, Range: srcRange, diff --git a/api/layer/layer.go b/api/layer/layer.go index c61890c1b..91ab72ad2 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -205,7 +205,8 @@ type ( DeleteBucket(ctx context.Context, p *DeleteBucketParams) error GetObject(ctx context.Context, p *GetObjectParams) error - GetObjectInfo(ctx context.Context, p *HeadObjectParams) (*data.ExtendedObjectInfo, error) + GetObjectInfo(ctx context.Context, p *HeadObjectParams) (*data.ObjectInfo, error) + GetExtendedObjectInfo(ctx context.Context, p *HeadObjectParams) (*data.ExtendedObjectInfo, error) GetLockInfo(ctx context.Context, obj *ObjectVersion) (*data.LockInfo, error) PutLockInfo(ctx context.Context, p *ObjectVersion, lock *data.ObjectLock) error @@ -418,7 +419,17 @@ func (n *layer) GetObject(ctx context.Context, p *GetObjectParams) error { } // GetObjectInfo returns meta information about the object. -func (n *layer) GetObjectInfo(ctx context.Context, p *HeadObjectParams) (*data.ExtendedObjectInfo, error) { +func (n *layer) GetObjectInfo(ctx context.Context, p *HeadObjectParams) (*data.ObjectInfo, error) { + extendedObjectInfo, err := n.GetExtendedObjectInfo(ctx, p) + if err != nil { + return nil, err + } + + return extendedObjectInfo.ObjectInfo, nil +} + +// GetExtendedObjectInfo returns meta information and corresponding info from the tree service about the object. +func (n *layer) GetExtendedObjectInfo(ctx context.Context, p *HeadObjectParams) (*data.ExtendedObjectInfo, error) { if len(p.VersionID) == 0 { return n.headLastVersionIfNotDeleted(ctx, p.BktInfo, p.Object) } diff --git a/api/layer/versioning_test.go b/api/layer/versioning_test.go index 07ac368f9..d8e5281cf 100644 --- a/api/layer/versioning_test.go +++ b/api/layer/versioning_test.go @@ -31,7 +31,7 @@ func (tc *testContext) putObject(content []byte) *data.ObjectInfo { } func (tc *testContext) getObject(objectName, versionID string, needError bool) (*data.ObjectInfo, []byte) { - extendedInfo, err := tc.layer.GetObjectInfo(tc.ctx, &HeadObjectParams{ + objInfo, err := tc.layer.GetObjectInfo(tc.ctx, &HeadObjectParams{ BktInfo: tc.bktInfo, Object: objectName, VersionID: versionID, @@ -44,13 +44,13 @@ func (tc *testContext) getObject(objectName, versionID string, needError bool) ( content := bytes.NewBuffer(nil) err = tc.layer.GetObject(tc.ctx, &GetObjectParams{ - ObjectInfo: extendedInfo.ObjectInfo, + ObjectInfo: objInfo, Writer: content, BucketInfo: tc.bktInfo, }) require.NoError(tc.t, err) - return extendedInfo.ObjectInfo, content.Bytes() + return objInfo, content.Bytes() } func (tc *testContext) deleteObject(objectName, versionID string, settings *data.BucketSettings) {