forked from TrueCloudLab/frostfs-sdk-go
[#268] client: Fix sequential PayloadPatch
calls
* The flag 'firstPayloadPatch' keeps its state after first `PatchPayload` that make other calls incorrectly set patch ranges. Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
7d84d104fb
commit
f0c599d06d
2 changed files with 7 additions and 12 deletions
|
@ -106,7 +106,6 @@ func (c *Client) ObjectPatchInit(ctx context.Context, prm PrmObjectPatch) (Objec
|
||||||
}
|
}
|
||||||
objectPatcher.client = c
|
objectPatcher.client = c
|
||||||
objectPatcher.stream = stream
|
objectPatcher.stream = stream
|
||||||
objectPatcher.firstPatchPayload = true
|
|
||||||
|
|
||||||
if prm.MaxChunkLength > 0 {
|
if prm.MaxChunkLength > 0 {
|
||||||
objectPatcher.maxChunkLen = prm.MaxChunkLength
|
objectPatcher.maxChunkLen = prm.MaxChunkLength
|
||||||
|
@ -154,8 +153,6 @@ type objectPatcher struct {
|
||||||
respV2 v2object.PatchResponse
|
respV2 v2object.PatchResponse
|
||||||
|
|
||||||
maxChunkLen int
|
maxChunkLen int
|
||||||
|
|
||||||
firstPatchPayload bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *objectPatcher) PatchAttributes(_ context.Context, newAttrs []object.Attribute, replace bool) bool {
|
func (x *objectPatcher) PatchAttributes(_ context.Context, newAttrs []object.Attribute, replace bool) bool {
|
||||||
|
@ -171,7 +168,7 @@ func (x *objectPatcher) PatchPayload(_ context.Context, rng *object.Range, paylo
|
||||||
|
|
||||||
buf := make([]byte, x.maxChunkLen)
|
buf := make([]byte, x.maxChunkLen)
|
||||||
|
|
||||||
for {
|
for patchIter := 0; ; patchIter++ {
|
||||||
n, err := payloadReader.Read(buf)
|
n, err := payloadReader.Read(buf)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
x.err = fmt.Errorf("read payload: %w", err)
|
x.err = fmt.Errorf("read payload: %w", err)
|
||||||
|
@ -182,8 +179,7 @@ func (x *objectPatcher) PatchPayload(_ context.Context, rng *object.Range, paylo
|
||||||
}
|
}
|
||||||
|
|
||||||
rngPart := object.NewRange()
|
rngPart := object.NewRange()
|
||||||
if x.firstPatchPayload {
|
if patchIter == 0 {
|
||||||
x.firstPatchPayload = false
|
|
||||||
rngPart.SetOffset(offset)
|
rngPart.SetOffset(offset)
|
||||||
rngPart.SetLength(rng.GetLength())
|
rngPart.SetLength(rng.GetLength())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -175,7 +175,6 @@ func TestObjectPatcher(t *testing.T) {
|
||||||
addr: oidtest.Address(),
|
addr: oidtest.Address(),
|
||||||
key: pk,
|
key: pk,
|
||||||
maxChunkLen: test.maxChunkLen,
|
maxChunkLen: test.maxChunkLen,
|
||||||
firstPatchPayload: true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
success := patcher.PatchAttributes(context.Background(), nil, false)
|
success := patcher.PatchAttributes(context.Background(), nil, false)
|
||||||
|
|
Loading…
Reference in a new issue