git/fetch: ensure we clean packfiles on failure

When pulling into a git repository that is group
writable as a non-owner, the pack file is left
in place because we do not have permission to
remove it.

We also leave it behind if we bail out early due
to an error, or due to only listing the changes.

This pushes down the creation of the file, and
cleans it up on error.

thanks to Anthony Martin for spotting the bug.
git/fetch: ensure we clean packfiles on failure

When pulling into a git repository that is group
writable as a non-owner, the pack file is left
in place because we do not have permission to
remove it.

We also leave it behind if we bail out early due
to an error, or due to only listing the changes.

This pushes down the creation of the file, and
cleans it up on error.

Also, while we're here, clean up index caching,
and ensure we close the fd in all cases.

thanks to Anthony Martin for spotting the bug.
This commit is contained in:
Ori Bernstein 2021-07-17 00:10:44 +00:00
parent fad1b3f7f7
commit 2204634275
2 changed files with 45 additions and 29 deletions

View file

@ -197,23 +197,22 @@ loadpack(Packf *pf, char *name)
}
}
if((ifd = open(buf, OREAD)) == -1)
goto error;
if((d = dirfstat(ifd)) == nil)
goto error;
return -1;
if((d = dirfstat(ifd)) == nil){
close(ifd);
return -1;
}
pf->nidx = d->length;
pf->idx = emalloc(pf->nidx);
if(readn(ifd, pf->idx, pf->nidx) != pf->nidx){
close(ifd);
free(pf->idx);
free(d);
goto error;
return -1;
}
close(ifd);
free(d);
return 0;
error:
if(ifd != -1)
close(ifd);
return -1;
}
static void