1
0
Fork 0
mirror of https://github.com/pygos/pkg-utils.git synced 2024-11-21 20:39:46 +01:00

pkg reader: try to read *entire* requested chunk

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2019-04-09 16:02:22 +02:00
parent aa6bbf2ef4
commit c78dc2255f

View file

@ -235,26 +235,32 @@ record_t *pkg_reader_current_record_header(pkg_reader_t *rd)
ssize_t pkg_reader_read_payload(pkg_reader_t *rd, void *out, size_t size) ssize_t pkg_reader_read_payload(pkg_reader_t *rd, void *out, size_t size)
{ {
ssize_t ret; ssize_t ret, total = 0;
if (rd->have_error) do {
return -1; if (rd->have_error)
return -1;
if (rd->have_eof || rd->offset_raw == rd->current.raw_size) if (rd->have_eof || rd->offset_raw == rd->current.raw_size)
return 0; break;
if (prefetch_compressed(rd)) if (prefetch_compressed(rd))
return -1; return -1;
if (size >= (rd->current.raw_size - rd->offset_raw)) if (size >= (rd->current.raw_size - rd->offset_raw))
rd->stream->flush(rd->stream); rd->stream->flush(rd->stream);
ret = rd->stream->read(rd->stream, out, size); ret = rd->stream->read(rd->stream, out, size);
if (ret < 0) if (ret < 0)
return -1; return -1;
rd->offset_raw += ret; rd->offset_raw += ret;
return ret; out = (char *)out + ret;
size -= ret;
total += ret;
} while (size > 0);
return total;
} }
int pkg_reader_rewind(pkg_reader_t *rd) int pkg_reader_rewind(pkg_reader_t *rd)