summaryrefslogtreecommitdiff
path: root/src/indexer.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2017-01-21 17:15:33 +0000
committerEdward Thomson <ethomson@github.com>2017-01-21 17:15:33 +0000
commitd030bba9fa64c4363368f9e3e0ed3f115dc06dc2 (patch)
treea15cff8ff2f983d23c071a5f069902742161b989 /src/indexer.c
parentf5586f5c73ac162393df10feec0117f59bbd1409 (diff)
downloadlibgit2-d030bba9fa64c4363368f9e3e0ed3f115dc06dc2.tar.gz
indexer: only delete temp file if it was unused
Only try to `unlink` our temp file when we know that we didn't copy it into its permanent location.
Diffstat (limited to 'src/indexer.c')
-rw-r--r--src/indexer.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/indexer.c b/src/indexer.c
index 3d1c81c86..aa5646023 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -33,7 +33,7 @@ struct entry {
struct git_indexer {
unsigned int parsed_header :1,
- opened_pack :1,
+ pack_committed :1,
have_stream :1,
have_delta :1;
struct git_pack_header hdr;
@@ -1060,6 +1060,7 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
/* And don't forget to rename the packfile to its new place. */
p_rename(idx->pack->pack_name, git_buf_cstr(&filename));
+ idx->pack_committed = 1;
git_buf_free(&filename);
git_hash_ctx_cleanup(&ctx);
@@ -1092,12 +1093,13 @@ void git_indexer_free(git_indexer *idx)
/* Try to delete the temporary file in case it was not committed. */
git_mwindow_free_all(&idx->pack->mwf);
+
/* We need to close the descriptor here so Windows doesn't choke on unlink */
- if (idx->pack->mwf.fd != -1) {
+ if (idx->pack->mwf.fd != -1)
p_close(idx->pack->mwf.fd);
- idx->pack->mwf.fd = -1;
- }
- p_unlink(idx->pack->pack_name);
+
+ if (!idx->pack_committed)
+ p_unlink(idx->pack->pack_name);
if (!git_mutex_lock(&git__mwindow_mutex)) {
git_packfile_free(idx->pack);