[#268] client: Fix PatchPayload method
Some checks failed
DCO / DCO (pull_request) Successful in 1m33s
Tests and linters / Lint (pull_request) Successful in 1m44s
Tests and linters / Tests (pull_request) Failing after 1m59s

* Make the method `PatchPayload` send a patch with empty
  payload patch if range's length is non-zero and if it's the
  first call.
* Empty payload patches just cut original object payload. So, these
  patches are also valid.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
Airat Arifullin 2024-09-11 13:13:46 +03:00
parent 7d84d104fb
commit cfa90cf232

View file

@ -178,6 +178,21 @@ func (x *objectPatcher) PatchPayload(_ context.Context, rng *object.Range, paylo
return false
}
if n == 0 {
if rng.GetLength() != 0 {
// the empty patch just cuts `rng.GetLength()` bytes from original object payload
if !x.patch(&object.Patch{
Address: x.addr,
PayloadPatch: &object.PayloadPatch{
Range: rng,
Chunk: []byte{},
},
}) {
return false
}
} else {
x.err = errors.New("zero-length empty payload patch can't be applied")
return false
}
break
}