Skip to content

Commit

Permalink
slicer: Do not drop link object's payload
Browse files Browse the repository at this point in the history
Another header == object cool thing.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
  • Loading branch information
carpawell committed Feb 28, 2024
1 parent e292150 commit 8af8c9f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
4 changes: 3 additions & 1 deletion object/slicer/slicer.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,9 @@ func (x *PayloadWriter) _writeChild(ctx context.Context, meta dynamicObjectMetad
obj.ResetID()
obj.SetSignature(nil)

_, err = writeInMemObject(ctx, x.signer, x.stream, obj, nil, meta, x.prmObjectPutInit)
payloadAsBuffers := [][]byte{obj.Payload()}

_, err = writeInMemObject(ctx, x.signer, x.stream, obj, payloadAsBuffers, meta, x.prmObjectPutInit)
if err != nil {
return fmt.Errorf("write linking object: %w", err)
}
Expand Down
45 changes: 24 additions & 21 deletions object/slicer/slicer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,15 +478,14 @@ func (x *slicedObjectChecker) ObjectPutInit(_ context.Context, hdr object.Object
}

type writeSizeChecker struct {
tb testing.TB
hdr object.Object
limit uint64
processed uint64
base io.Writer
payloadSeen bool
tb testing.TB
hdr object.Object
limit uint64
processed uint64
base *bytes.Buffer
}

func newSizeChecker(tb testing.TB, hdr object.Object, base io.Writer, sizeLimit uint64) *writeSizeChecker {
func newSizeChecker(tb testing.TB, hdr object.Object, base *bytes.Buffer, sizeLimit uint64) *writeSizeChecker {
return &writeSizeChecker{
tb: tb,
hdr: hdr,
Expand All @@ -496,28 +495,32 @@ func newSizeChecker(tb testing.TB, hdr object.Object, base io.Writer, sizeLimit
}

func (x *writeSizeChecker) Write(p []byte) (int, error) {
if !x.payloadSeen && len(p) > 0 {
x.payloadSeen = true
}
require.NotZero(x.tb, len(p), "non of the split object should be empty")

if x.payloadSeen {
if len(x.hdr.Children()) == 0 {
// only linking objects should be streamed with
// empty payload
require.NotZero(x.tb, len(p))
} else {
// linking object should have empty payload
require.Zero(x.tb, x.hdr.PayloadSize())
}
n, err := x.base.Write(p)

_, firstSet := x.hdr.FirstID()
_, previousSet := x.hdr.PreviousID()

if firstSet && !previousSet {
// link object case; not user's payload

Check warning on line 506 in object/slicer/slicer_test.go

View workflow job for this annotation

GitHub Actions / lint

empty-block: this block is empty, you can remove it (revive)
} else {
x.processed += uint64(n)
}

n, err := x.base.Write(p)
x.processed += uint64(n)
return n, err
}

func (x *writeSizeChecker) Close() error {
require.LessOrEqual(x.tb, x.processed, x.limit, "object payload must not overflow the limit")

if x.hdr.Type() == object.TypeLink {
payload := x.base.Bytes()

var testLink object.Link
require.NoError(x.tb, testLink.Unmarshal(payload), "link object's payload must be structed")
}

return nil
}

Expand Down

0 comments on commit 8af8c9f

Please sign in to comment.