[#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
rngs []*objectSDK.Range
rngs []objectSDK.Range
salt []byte
}
@ -750,7 +750,7 @@ func (x *HashPayloadRangesPrm) TZ() {
}
// 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
}
@ -774,14 +774,6 @@ func (x HashPayloadRangesRes) HashList() [][]byte {
// 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.
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
if prm.tz {
cs = checksum.TZ
@ -794,7 +786,7 @@ func HashPayloadRanges(ctx context.Context, prm HashPayloadRangesPrm) (*HashPayl
ObjectID: &obj,
Local: prm.local,
Salt: prm.salt,
Ranges: rngs,
Ranges: prm.rngs,
ChecksumType: cs,
Session: prm.sessionToken,
BearerToken: prm.bearerToken,

View file

@ -84,7 +84,7 @@ func getObjectRange(cmd *cobra.Command, _ []string) {
raw, _ := cmd.Flags().GetBool(rawFlag)
prm.SetRawFlag(raw)
prm.SetAddress(objAddr)
prm.SetRange(ranges[0])
prm.SetRange(&ranges[0])
prm.SetPayloadWriter(out)
_, 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()
if len(v) == 0 {
return nil, nil
}
vs := strings.Split(v, ",")
rs := make([]*objectSDK.Range, len(vs))
rs := make([]objectSDK.Range, len(vs))
for i := range vs {
before, after, found := strings.Cut(vs[i], rangeSep)
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])
}
rs[i] = objectSDK.NewRange()
rs[i].SetOffset(offset)
rs[i].SetLength(length)
}