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>
Shawn O. Pearce committed
Feb 27, 2007 at 23:47 UTC
a91d49cd369ac5fc8e1a17357a975d09cf6c8cb3
1 file changed
+8
-2
index-pack.c
+8
-2
@@ -277,13 +277,19 @@ static void *get_data_from_pack(struct object_entry *obj)
277
{
278
unsigned long from = obj[0].offset + obj[0].hdr_size;
279
unsigned long len = obj[1].offset - from;
280
+ unsigned long rdy = 0;
281
unsigned char *src, *data;
282
z_stream stream;
283
int st;
284
285
src = xmalloc(len);
285
- if (pread(pack_fd, src, len, from) != len)
286
- die("cannot pread pack file: %s", strerror(errno));
286
+ data = src;
287
+ do {
288
+ ssize_t n = pread(pack_fd, data + rdy, len - rdy, from + rdy);
289
+ if (n <= 0)
290
+ die("cannot pread pack file: %s", strerror(errno));
291
+ rdy += n;
292
+ } while (rdy < len);
293
data = xmalloc(obj->size);
294
memset(&stream, 0, sizeof(stream));
295
stream.next_out = data;