From 9ef9e51500add0337626ec36775509175d58c85e Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Wed, 11 Sep 2024 13:13:46 +0300 Subject: [PATCH] [#268] client: Fix `PatchPayload` method * 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 --- client/object_patch.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/client/object_patch.go b/client/object_patch.go index b30bebe..4d83389 100644 --- a/client/object_patch.go +++ b/client/object_patch.go @@ -178,6 +178,20 @@ func (x *objectPatcher) PatchPayload(_ context.Context, rng *object.Range, paylo return false } if n == 0 { + if rng.GetLength() != 0 && x.firstPatchPayload { + x.firstPatchPayload = false + + // 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 + } + } break }