@@ -552,7 +552,7 @@ void unuse_pack(struct pack_window **w_cursor)
552
552
}
553
553
}
554
554
555
- static void open_packed_git (struct packed_git * p )
555
+ static int open_packed_git (struct packed_git * p )
556
556
{
557
557
struct stat st ;
558
558
struct pack_header hdr ;
@@ -562,49 +562,50 @@ static void open_packed_git(struct packed_git *p)
562
562
563
563
p -> pack_fd = open (p -> pack_name , O_RDONLY );
564
564
if (p -> pack_fd < 0 || fstat (p -> pack_fd , & st ))
565
- die ( "packfile %s cannot be opened" , p -> pack_name ) ;
565
+ return -1 ;
566
566
567
567
/* If we created the struct before we had the pack we lack size. */
568
568
if (!p -> pack_size ) {
569
569
if (!S_ISREG (st .st_mode ))
570
- die ("packfile %s not a regular file" , p -> pack_name );
570
+ return error ("packfile %s not a regular file" , p -> pack_name );
571
571
p -> pack_size = st .st_size ;
572
572
} else if (p -> pack_size != st .st_size )
573
- die ("packfile %s size changed" , p -> pack_name );
573
+ return error ("packfile %s size changed" , p -> pack_name );
574
574
575
575
/* We leave these file descriptors open with sliding mmap;
576
576
* there is no point keeping them open across exec(), though.
577
577
*/
578
578
fd_flag = fcntl (p -> pack_fd , F_GETFD , 0 );
579
579
if (fd_flag < 0 )
580
- die ("cannot determine file descriptor flags" );
580
+ return error ("cannot determine file descriptor flags" );
581
581
fd_flag |= FD_CLOEXEC ;
582
582
if (fcntl (p -> pack_fd , F_SETFD , fd_flag ) == -1 )
583
- die ("cannot set FD_CLOEXEC" );
583
+ return error ("cannot set FD_CLOEXEC" );
584
584
585
585
/* Verify we recognize this pack file format. */
586
586
if (read_in_full (p -> pack_fd , & hdr , sizeof (hdr )) != sizeof (hdr ))
587
- die ("file %s is far too short to be a packfile" , p -> pack_name );
587
+ return error ("file %s is far too short to be a packfile" , p -> pack_name );
588
588
if (hdr .hdr_signature != htonl (PACK_SIGNATURE ))
589
- die ("file %s is not a GIT packfile" , p -> pack_name );
589
+ return error ("file %s is not a GIT packfile" , p -> pack_name );
590
590
if (!pack_version_ok (hdr .hdr_version ))
591
- die ("packfile %s is version %u and not supported"
591
+ return error ("packfile %s is version %u and not supported"
592
592
" (try upgrading GIT to a newer version)" ,
593
593
p -> pack_name , ntohl (hdr .hdr_version ));
594
594
595
595
/* Verify the pack matches its index. */
596
596
if (num_packed_objects (p ) != ntohl (hdr .hdr_entries ))
597
- die ("packfile %s claims to have %u objects"
597
+ return error ("packfile %s claims to have %u objects"
598
598
" while index size indicates %u objects" ,
599
599
p -> pack_name , ntohl (hdr .hdr_entries ),
600
600
num_packed_objects (p ));
601
601
if (lseek (p -> pack_fd , p -> pack_size - sizeof (sha1 ), SEEK_SET ) == -1 )
602
- die ("end of packfile %s is unavailable" , p -> pack_name );
602
+ return error ("end of packfile %s is unavailable" , p -> pack_name );
603
603
if (read_in_full (p -> pack_fd , sha1 , sizeof (sha1 )) != sizeof (sha1 ))
604
- die ("packfile %s signature is unavailable" , p -> pack_name );
604
+ return error ("packfile %s signature is unavailable" , p -> pack_name );
605
605
idx_sha1 = ((unsigned char * )p -> index_base ) + p -> index_size - 40 ;
606
606
if (hashcmp (sha1 , idx_sha1 ))
607
- die ("packfile %s does not match index" , p -> pack_name );
607
+ return error ("packfile %s does not match index" , p -> pack_name );
608
+ return 0 ;
608
609
}
609
610
610
611
static int in_window (struct pack_window * win , unsigned long offset )
@@ -627,8 +628,8 @@ unsigned char* use_pack(struct packed_git *p,
627
628
{
628
629
struct pack_window * win = * w_cursor ;
629
630
630
- if (p -> pack_fd == -1 )
631
- open_packed_git ( p );
631
+ if (p -> pack_fd == -1 && open_packed_git ( p ) )
632
+ die ( "packfile %s cannot be accessed" , p -> pack_name );
632
633
633
634
/* Since packfiles end in a hash of their content and its
634
635
* pointless to ask for an offset into the middle of that
0 commit comments