Merge branch 'jh/close-index-before-stat' into maint
The timestamp of the index file is now taken after the file is closed, to help Windows, on which a stale timestamp is reported by fstat() on a file that is opened for writing and data was written but not yet closed. * jh/close-index-before-stat: read-cache: close index.lock in do_write_index
This commit is contained in:
commit
f24e079cb6
13
read-cache.c
13
read-cache.c
@ -2187,9 +2187,10 @@ void update_index_if_able(struct index_state *istate, struct lock_file *lockfile
|
|||||||
rollback_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 strip_extensions)
|
||||||
{
|
{
|
||||||
|
int newfd = tempfile->fd;
|
||||||
git_SHA_CTX c;
|
git_SHA_CTX c;
|
||||||
struct cache_header hdr;
|
struct cache_header hdr;
|
||||||
int i, err, removed, extended, hdr_version;
|
int i, err, removed, extended, hdr_version;
|
||||||
@ -2298,7 +2299,11 @@ static int do_write_index(struct index_state *istate, int newfd,
|
|||||||
return -1;
|
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 (stat(tempfile->filename.buf, &st))
|
||||||
return -1;
|
return -1;
|
||||||
istate->timestamp.sec = (unsigned int)st.st_mtime;
|
istate->timestamp.sec = (unsigned int)st.st_mtime;
|
||||||
istate->timestamp.nsec = ST_MTIME_NSEC(st);
|
istate->timestamp.nsec = ST_MTIME_NSEC(st);
|
||||||
@ -2321,7 +2326,7 @@ static int commit_locked_index(struct lock_file *lk)
|
|||||||
static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,
|
static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,
|
||||||
unsigned flags)
|
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)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
assert((flags & (COMMIT_LOCK | CLOSE_LOCK)) !=
|
assert((flags & (COMMIT_LOCK | CLOSE_LOCK)) !=
|
||||||
@ -2418,7 +2423,7 @@ static int write_shared_index(struct index_state *istate,
|
|||||||
return do_write_locked_index(istate, lock, flags);
|
return do_write_locked_index(istate, lock, flags);
|
||||||
}
|
}
|
||||||
move_cache_to_base_index(istate);
|
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) {
|
if (ret) {
|
||||||
delete_tempfile(&temporary_sharedindex);
|
delete_tempfile(&temporary_sharedindex);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user