From 3c76884182450c48f2cb4723cd5c61fbc401d409 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 12 Sep 2023 10:41:29 +0300 Subject: [PATCH] [#682] cli: Unify array of ranges type Signed-off-by: Evgenii Stratonikov --- cmd/frostfs-cli/internal/client/client.go | 14 +++----------- cmd/frostfs-cli/modules/object/range.go | 7 +++---- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/cmd/frostfs-cli/internal/client/client.go b/cmd/frostfs-cli/internal/client/client.go index 4cc20692..e8869bc8 100644 --- a/cmd/frostfs-cli/internal/client/client.go +++ b/cmd/frostfs-cli/internal/client/client.go @@ -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, diff --git a/cmd/frostfs-cli/modules/object/range.go b/cmd/frostfs-cli/modules/object/range.go index 591355b9..0eee7bdb 100644 --- a/cmd/frostfs-cli/modules/object/range.go +++ b/cmd/frostfs-cli/modules/object/range.go @@ -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) }