4 void fixup_pack_header_footer(int pack_fd
,
5 unsigned char *pack_file_sha1
,
9 static const int buf_sz
= 128 * 1024;
11 struct pack_header hdr
;
14 if (lseek(pack_fd
, 0, SEEK_SET
) != 0)
15 die("Failed seeking to start: %s", strerror(errno
));
16 if (read_in_full(pack_fd
, &hdr
, sizeof(hdr
)) != sizeof(hdr
))
17 die("Unable to reread header of %s: %s", pack_name
, strerror(errno
));
18 if (lseek(pack_fd
, 0, SEEK_SET
) != 0)
19 die("Failed seeking to start: %s", strerror(errno
));
20 hdr
.hdr_entries
= htonl(object_count
);
21 write_or_die(pack_fd
, &hdr
, sizeof(hdr
));
24 SHA1_Update(&c
, &hdr
, sizeof(hdr
));
26 buf
= xmalloc(buf_sz
);
28 ssize_t n
= xread(pack_fd
, buf
, buf_sz
);
32 die("Failed to checksum %s: %s", pack_name
, strerror(errno
));
33 SHA1_Update(&c
, buf
, n
);
37 SHA1_Final(pack_file_sha1
, &c
);
38 write_or_die(pack_fd
, pack_file_sha1
, 20);