git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Error "fatal: cannot pread pack file: Success"

From
Junio C Hamano <junkio@cox.net>
Date
Feb 28, 2007, 05:55 UTC
Message-ID
<7vbqje3jx9.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20070228044719.GA6068@spearce.org>
"Shawn O. Pearce" <spearce@spearce.org> writes:
Show 15 quoted lines
> "Shawn O. Pearce" <spearce@spearce.org> wrote:
>> Bill Lear <rael@zopyra.com> wrote:
>> > Using 1.5.0.1.  Can't see what is wrong with this clone...
>> ...
>> > Indexing 4589 objects.
>> > remote: Total 4589 (delta 2209), reused 4589 (delta 2209)
>> >  100% (4589/4589) done
>> > Resolving 2209 deltas.
>> > fatal: cannot pread pack file: Success
>> > fatal: index-pack died with error code 128
>> > fetch-pack from '/home/rael/devel/project/.git' failed.
>> 
>> I think the pread() in get_data_from_pack of index-pack is wrong,
>> it really should be looping until we fill the buffer in case the
>> OS doesn't fully satisfy our read request the first time.

The patch looks correct, even if this was not the problem Bill is suffering from.

Show 42 quoted lines
> [PATCH] 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>
> ---
>  index-pack.c |   10 ++++++++--
>  1 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/index-pack.c b/index-pack.c
> index 859ec01..cf81a99 100644
> --- a/index-pack.c
> +++ b/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 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;
> -- 
> 1.5.0.2.775.g1a500
>
> -- 
> Shawn.
Previous: Shawn O. PearceNext: Linus Torvalds
Message 4 of 34 in “Error "fatal: cannot pread pack file: Success"”
  1. Bill LearFeb 28, 2007
  2. Shawn O. PearceFeb 28, 2007
  3. Shawn O. PearceFeb 28, 2007
  4. Junio C HamanoFeb 28, 2007
  5. Linus TorvaldsFeb 28, 2007
  6. Bill LearFeb 28, 2007
  7. Bill LearFeb 28, 2007
  8. Shawn O. PearceFeb 28, 2007
  9. Bill LearFeb 28, 2007
  10. Bill LearFeb 28, 2007
  11. Shawn O. PearceFeb 28, 2007
  12. Bill LearFeb 28, 2007
  13. Shawn O. PearceFeb 28, 2007
  14. Morten WelinderFeb 28, 2007
  15. Shawn O. PearceFeb 28, 2007
  16. Bill LearFeb 28, 2007
  17. Shawn O. PearceFeb 28, 2007
  18. Bill LearFeb 28, 2007
  19. Shawn O. PearceFeb 28, 2007
  20. Nicolas PitreFeb 28, 2007
  21. Shawn O. PearceFeb 28, 2007
  22. Bill LearFeb 28, 2007
  23. Bill LearFeb 28, 2007
  24. Nicolas PitreFeb 28, 2007
  25. Bill LearMar 1, 2007
  26. Linus TorvaldsFeb 28, 2007
  27. Bill LearFeb 28, 2007
  28. Linus TorvaldsFeb 28, 2007
  29. Bill LearFeb 28, 2007
  30. Linus TorvaldsFeb 28, 2007
  31. Nicolas PitreFeb 28, 2007
  32. Linus TorvaldsFeb 28, 2007
  33. Nicolas PitreFeb 28, 2007
  34. Linus TorvaldsFeb 28, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.