Commit 3e8c5e45 by Edward Thomson

Merge pull request #3174 from libgit2/cmn/idx-fill-hole

indexer: use lseek to extend the packfile
parents 7f8cd672 aa57231f
...@@ -478,13 +478,14 @@ static int write_at(git_indexer *idx, const void *data, git_off_t offset, size_t ...@@ -478,13 +478,14 @@ static int write_at(git_indexer *idx, const void *data, git_off_t offset, size_t
static int append_to_pack(git_indexer *idx, const void *data, size_t size) static int append_to_pack(git_indexer *idx, const void *data, size_t size)
{ {
git_off_t current_size = idx->pack->mwf.size; git_off_t current_size = idx->pack->mwf.size;
int fd = idx->pack->mwf.fd;
if (!size) if (!size)
return 0; return 0;
/* add the extra space we need at the end */ if (p_lseek(fd, current_size + size - 1, SEEK_SET) < 0 ||
if (p_ftruncate(idx->pack->mwf.fd, current_size + size) < 0) { p_write(idx->pack->mwf.fd, data, 1) < 0) {
giterr_set(GITERR_OS, "Failed to increase size of pack file '%s'", idx->pack->pack_name); giterr_set(GITERR_OS, "cannot extend packfile '%s'", idx->pack->pack_name);
return -1; return -1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment