Code

index-pack: Loop over pread until data loading is complete.
authorShawn O. Pearce <spearce@spearce.org>
Wed, 28 Feb 2007 04:47:19 +0000 (23:47 -0500)
committerJunio C Hamano <junkio@cox.net>
Wed, 28 Feb 2007 05:58:46 +0000 (21:58 -0800)
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>
index-pack.c

index 72e0962415d74c856917f6bb56e6fa2fea950c25..f9177442afb6daef9feef43696165be5b6eb224c 100644 (file)
@@ -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 len = obj[1].offset - from;
+       unsigned long rdy = 0;
        unsigned char *src, *data;
        z_stream stream;
        int st;
 
        src = xmalloc(len);
-       if (pread(pack_fd, src, len, from) != len)
-               die("cannot pread pack file: %s", strerror(errno));
+       data = src;
+       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);
        memset(&stream, 0, sizeof(stream));
        stream.next_out = data;