From 5936eea60b46dac89ed10b2dd89b45fe7d9de268 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Tue, 13 Aug 2024 18:56:11 +0300 Subject: [PATCH] [#XX] patcher: Fix applying patch from the same offset Signed-off-by: Airat Arifullin --- object/patcher/patcher.go | 2 ++ object/patcher/patcher_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/object/patcher/patcher.go b/object/patcher/patcher.go index ec448c9..aad1f2a 100644 --- a/object/patcher/patcher.go +++ b/object/patcher/patcher.go @@ -190,6 +190,8 @@ func (p *patcher) copyRange(ctx context.Context, rng *objectSDK.Range) error { } func (p *patcher) applyPatch(ctx context.Context, payloadPatch *objectSDK.PayloadPatch, offset uint64) (newOffset uint64, err error) { + newOffset = offset + // write the original payload chunk before the start of the patch if payloadPatch.Range.GetOffset() > offset { rng := new(objectSDK.Range) diff --git a/object/patcher/patcher_test.go b/object/patcher/patcher_test.go index bf2402b..3abb939 100644 --- a/object/patcher/patcher_test.go +++ b/object/patcher/patcher_test.go @@ -508,6 +508,31 @@ func TestPatch(t *testing.T) { originalObjectPayload: []byte("0123456789ABCDEF"), patchedPayload: []byte("0123456789aaaaaDEFbbbbb"), }, + { + name: "starting from the same offset", + patches: []objectSDK.Patch{ + { + PayloadPatch: &objectSDK.PayloadPatch{ + Range: rangeWithOffestWithLength(8, 3), + Chunk: []byte("1"), + }, + }, + { + PayloadPatch: &objectSDK.PayloadPatch{ + Range: rangeWithOffestWithLength(11, 0), + Chunk: []byte("2"), + }, + }, + { + PayloadPatch: &objectSDK.PayloadPatch{ + Range: rangeWithOffestWithLength(11, 0), + Chunk: []byte("3"), + }, + }, + }, + originalObjectPayload: []byte("abcdefghijklmnop"), + patchedPayload: []byte("abcdefgh123lmnop"), + }, { name: "a few patches: various modifiactions", patches: []objectSDK.Patch{