index-pack: Loop over pread until data loading is complete.
A filesystem might not be able to completely supply our pread request in one system call, such as if we are reading data from a network file system and the requested length is just simply huge. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:

committed by
Junio C Hamano

parent
ae64860622
commit
a91d49cd36
10
index-pack.c
10
index-pack.c
@ -277,13 +277,19 @@ static void *get_data_from_pack(struct object_entry *obj)
|
|||||||
{
|
{
|
||||||
unsigned long from = obj[0].offset + obj[0].hdr_size;
|
unsigned long from = obj[0].offset + obj[0].hdr_size;
|
||||||
unsigned long len = obj[1].offset - from;
|
unsigned long len = obj[1].offset - from;
|
||||||
|
unsigned long rdy = 0;
|
||||||
unsigned char *src, *data;
|
unsigned char *src, *data;
|
||||||
z_stream stream;
|
z_stream stream;
|
||||||
int st;
|
int st;
|
||||||
|
|
||||||
src = xmalloc(len);
|
src = xmalloc(len);
|
||||||
if (pread(pack_fd, src, len, from) != len)
|
data = src;
|
||||||
die("cannot pread pack file: %s", strerror(errno));
|
do {
|
||||||
|
ssize_t n = pread(pack_fd, data + rdy, len - rdy, from + rdy);
|
||||||
|
if (n <= 0)
|
||||||
|
die("cannot pread pack file: %s", strerror(errno));
|
||||||
|
rdy += n;
|
||||||
|
} while (rdy < len);
|
||||||
data = xmalloc(obj->size);
|
data = xmalloc(obj->size);
|
||||||
memset(&stream, 0, sizeof(stream));
|
memset(&stream, 0, sizeof(stream));
|
||||||
stream.next_out = data;
|
stream.next_out = data;
|
||||||
|
Reference in New Issue
Block a user