From 91d8e0a4deb4137cc2eb70d1763874ff8bd467f5 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 8 Dec 2020 14:58:38 +0300 Subject: [PATCH] [#238] engine: Support raw flag in Head method Signed-off-by: Alex Vanin --- pkg/local_object_storage/engine/head.go | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/pkg/local_object_storage/engine/head.go b/pkg/local_object_storage/engine/head.go index a8a12bb59..78020f7f1 100644 --- a/pkg/local_object_storage/engine/head.go +++ b/pkg/local_object_storage/engine/head.go @@ -11,6 +11,7 @@ import ( // HeadPrm groups the parameters of Head operation. type HeadPrm struct { addr *objectSDK.Address + raw bool } // HeadRes groups resulting values of Head operation. @@ -29,6 +30,17 @@ func (p *HeadPrm) WithAddress(addr *objectSDK.Address) *HeadPrm { return p } +// WithRaw is a Head option to set raw flag value. If flag is unset, then Head +// returns header of virtual object, otherwise it returns SplitInfo of virtual +// object. +func (p *HeadPrm) WithRaw(raw bool) *HeadPrm { + if p != nil { + p.raw = raw + } + + return p +} + // Header returns the requested object header. // // Instance has empty payload. @@ -51,7 +63,8 @@ func (e *StorageEngine) Head(prm *HeadPrm) (*HeadRes, error) { ) shPrm := new(shard.HeadPrm). - WithAddress(prm.addr) + WithAddress(prm.addr). + WithRaw(prm.raw) e.iterateOverSortedShards(prm.addr, func(_ int, sh *shard.Shard) (stop bool) { res, err := sh.Head(shPrm) @@ -102,3 +115,17 @@ func Head(storage *StorageEngine, addr *objectSDK.Address) (*object.Object, erro return res.Header(), nil } + +// HeadRaw reads object header from local storage by provided address and raw +// flag. +func HeadRaw(storage *StorageEngine, addr *objectSDK.Address, raw bool) (*object.Object, error) { + res, err := storage.Head(new(HeadPrm). + WithAddress(addr). + WithRaw(raw), + ) + if err != nil { + return nil, err + } + + return res.Header(), nil +}