[#40] object/put: Assign zero return of MaxObjectSize invalid

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-10-22 17:20:59 +03:00 committed by Alex Vanin
parent 43533c991e
commit 968033deed
2 changed files with 10 additions and 1 deletions

View file

@ -13,6 +13,10 @@ import (
) )
type MaxSizeSource interface { type MaxSizeSource interface {
// MaxObjectSize returns maximum payload size
// of physically stored object in system.
//
// Must return 0 if value can not be obtained.
MaxObjectSize() uint64 MaxObjectSize() uint64
} }

View file

@ -66,8 +66,13 @@ func (p *Streamer) initTarget(prm *PutInitPrm) error {
return errors.Wrapf(err, "(%T) could not receive session key", p) return errors.Wrapf(err, "(%T) could not receive session key", p)
} }
maxSz := p.maxSizeSrc.MaxObjectSize()
if maxSz == 0 {
return errors.Errorf("(%T) could not obtain max object size parameter", p)
}
p.target = transformer.NewPayloadSizeLimiter( p.target = transformer.NewPayloadSizeLimiter(
p.maxSizeSrc.MaxObjectSize(), maxSz,
func() transformer.ObjectTarget { func() transformer.ObjectTarget {
return transformer.NewFormatTarget(&transformer.FormatterParams{ return transformer.NewFormatTarget(&transformer.FormatterParams{
Key: sessionKey, Key: sessionKey,