[#XX] patcher: Fix applying patch from the same offset
Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
908c96a94d
commit
5936eea60b
2 changed files with 27 additions and 0 deletions
|
@ -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) {
|
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
|
// write the original payload chunk before the start of the patch
|
||||||
if payloadPatch.Range.GetOffset() > offset {
|
if payloadPatch.Range.GetOffset() > offset {
|
||||||
rng := new(objectSDK.Range)
|
rng := new(objectSDK.Range)
|
||||||
|
|
|
@ -508,6 +508,31 @@ func TestPatch(t *testing.T) {
|
||||||
originalObjectPayload: []byte("0123456789ABCDEF"),
|
originalObjectPayload: []byte("0123456789ABCDEF"),
|
||||||
patchedPayload: []byte("0123456789aaaaaDEFbbbbb"),
|
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",
|
name: "a few patches: various modifiactions",
|
||||||
patches: []objectSDK.Patch{
|
patches: []objectSDK.Patch{
|
||||||
|
|
Loading…
Reference in a new issue