Skip to content

read-cache: close index.lock in do_write_index #1149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2141,9 +2141,10 @@ void update_index_if_able(struct index_state *istate, struct lock_file *lockfile
rollback_lock_file(lockfile);
}

static int do_write_index(struct index_state *istate, int newfd,
static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
int strip_extensions)
{
int newfd = tempfile->fd;
git_SHA_CTX c;
struct cache_header hdr;
int i, err, removed, extended, hdr_version;
Expand Down Expand Up @@ -2252,7 +2253,11 @@ static int do_write_index(struct index_state *istate, int newfd,
return -1;
}

if (ce_flush(&c, newfd, istate->sha1) || fstat(newfd, &st))
if (ce_flush(&c, newfd, istate->sha1))
return -1;
if (close_tempfile(tempfile))
return error(_("could not close '%s'"), tempfile->filename.buf);
if (lstat(tempfile->filename.buf, &st))
return -1;
istate->timestamp.sec = (unsigned int)st.st_mtime;
istate->timestamp.nsec = ST_MTIME_NSEC(st);
Expand All @@ -2275,7 +2280,7 @@ static int commit_locked_index(struct lock_file *lk)
static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,
unsigned flags)
{
int ret = do_write_index(istate, get_lock_file_fd(lock), 0);
int ret = do_write_index(istate, &lock->tempfile, 0);
if (ret)
return ret;
assert((flags & (COMMIT_LOCK | CLOSE_LOCK)) !=
Expand Down Expand Up @@ -2313,7 +2318,7 @@ static int write_shared_index(struct index_state *istate,
return do_write_locked_index(istate, lock, flags);
}
move_cache_to_base_index(istate);
ret = do_write_index(si->base, fd, 1);
ret = do_write_index(si->base, &temporary_sharedindex, 1);
if (ret) {
delete_tempfile(&temporary_sharedindex);
return ret;
Expand Down