Skip to content

Commit

Permalink
index-pack: Loop over pread until data loading is complete.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Shawn O. Pearce authored and Junio C Hamano committed Feb 28, 2007
1 parent ae64860 commit a91d49c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a91d49c

Please sign in to comment.