[#149] client: Do not finish on empty ID list in ObjectListReader

In previous implementation `ObjectListReader.Read` returned `false` on
server responded with empty ID list. This could cause premature end of
reading since the protocol does not forbid intermediate empty lists.

Do not stop if ID list from response body is empty.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-02-24 14:09:26 +03:00 committed by LeL
parent 32af7251f2
commit 8e99e8a818

View file

@ -136,34 +136,42 @@ func (x *ObjectListReader) Read(buf []oid.ID) (int, bool) {
return read, true
}
// receive next message
ok := x.ctxCall.readResponse()
if !ok {
return read, false
var ok bool
var ids []*v2refs.ObjectID
var i, ln, rem int
for {
// receive next message
ok = x.ctxCall.readResponse()
if !ok {
return read, false
}
// read new chunk of objects
ids = x.bodyResp.GetIDList()
ln = len(ids)
if ln == 0 {
// just skip empty lists since they are not prohibited by protocol
continue
}
if rem = len(buf) - read; ln > rem {
ln = rem
}
for i = 0; i < ln; i++ {
buf[read+i] = *oid.NewIDFromV2(ids[i]) // need smth better
}
read += ln
// save the tail and break
x.tail = append(x.tail, ids[ln:]...)
break
}
// read new chunk of objects
ids := x.bodyResp.GetIDList()
ln := len(ids)
if ln == 0 {
x.ctxCall.err = io.EOF
return read, false
}
buf = buf[read:]
if ln > len(buf) {
ln = len(buf)
}
for i := 0; i < ln; i++ {
buf[i] = *oid.NewIDFromV2(ids[i]) // need smth better
}
read += ln
// save the tail
x.tail = append(x.tail, ids[ln:]...)
return read, true
}