[#682] cli: Unify array of ranges type

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-09-12 10:41:29 +03:00
parent f435ab1b26
commit 3c76884182
2 changed files with 6 additions and 15 deletions

View file

@ -739,7 +739,7 @@ type HashPayloadRangesPrm struct {
tz bool tz bool
rngs []*objectSDK.Range rngs []objectSDK.Range
salt []byte salt []byte
} }
@ -750,7 +750,7 @@ func (x *HashPayloadRangesPrm) TZ() {
} }
// SetRanges sets a list of payload ranges to hash. // SetRanges sets a list of payload ranges to hash.
func (x *HashPayloadRangesPrm) SetRanges(rngs []*objectSDK.Range) { func (x *HashPayloadRangesPrm) SetRanges(rngs []objectSDK.Range) {
x.rngs = rngs x.rngs = rngs
} }
@ -774,14 +774,6 @@ func (x HashPayloadRangesRes) HashList() [][]byte {
// Returns any error which prevented the operation from completing correctly in error return. // Returns any error which prevented the operation from completing correctly in error return.
// Returns an error if number of received hashes differs with the number of requested ranges. // Returns an error if number of received hashes differs with the number of requested ranges.
func HashPayloadRanges(ctx context.Context, prm HashPayloadRangesPrm) (*HashPayloadRangesRes, error) { func HashPayloadRanges(ctx context.Context, prm HashPayloadRangesPrm) (*HashPayloadRangesRes, error) {
rngs := make([]objectSDK.Range, len(prm.rngs))
for i, r := range prm.rngs {
if r != nil {
rngs[i] = *r
}
}
cs := checksum.SHA256 cs := checksum.SHA256
if prm.tz { if prm.tz {
cs = checksum.TZ cs = checksum.TZ
@ -794,7 +786,7 @@ func HashPayloadRanges(ctx context.Context, prm HashPayloadRangesPrm) (*HashPayl
ObjectID: &obj, ObjectID: &obj,
Local: prm.local, Local: prm.local,
Salt: prm.salt, Salt: prm.salt,
Ranges: rngs, Ranges: prm.rngs,
ChecksumType: cs, ChecksumType: cs,
Session: prm.sessionToken, Session: prm.sessionToken,
BearerToken: prm.bearerToken, BearerToken: prm.bearerToken,

View file

@ -84,7 +84,7 @@ func getObjectRange(cmd *cobra.Command, _ []string) {
raw, _ := cmd.Flags().GetBool(rawFlag) raw, _ := cmd.Flags().GetBool(rawFlag)
prm.SetRawFlag(raw) prm.SetRawFlag(raw)
prm.SetAddress(objAddr) prm.SetAddress(objAddr)
prm.SetRange(ranges[0]) prm.SetRange(&ranges[0])
prm.SetPayloadWriter(out) prm.SetPayloadWriter(out)
_, err = internalclient.PayloadRange(cmd.Context(), prm) _, err = internalclient.PayloadRange(cmd.Context(), prm)
@ -146,13 +146,13 @@ func marshalSplitInfo(cmd *cobra.Command, info *objectSDK.SplitInfo) ([]byte, er
} }
} }
func getRangeList(cmd *cobra.Command) ([]*objectSDK.Range, error) { func getRangeList(cmd *cobra.Command) ([]objectSDK.Range, error) {
v := cmd.Flag("range").Value.String() v := cmd.Flag("range").Value.String()
if len(v) == 0 { if len(v) == 0 {
return nil, nil return nil, nil
} }
vs := strings.Split(v, ",") vs := strings.Split(v, ",")
rs := make([]*objectSDK.Range, len(vs)) rs := make([]objectSDK.Range, len(vs))
for i := range vs { for i := range vs {
before, after, found := strings.Cut(vs[i], rangeSep) before, after, found := strings.Cut(vs[i], rangeSep)
if !found { if !found {
@ -176,7 +176,6 @@ func getRangeList(cmd *cobra.Command) ([]*objectSDK.Range, error) {
return nil, fmt.Errorf("invalid '%s' range: uint64 overflow", vs[i]) return nil, fmt.Errorf("invalid '%s' range: uint64 overflow", vs[i])
} }
rs[i] = objectSDK.NewRange()
rs[i].SetOffset(offset) rs[i].SetOffset(offset)
rs[i].SetLength(length) rs[i].SetLength(length)
} }