@@ -2206,9 +2206,10 @@ void update_index_if_able(struct index_state *istate, struct lock_file *lockfile
2206
2206
rollback_lock_file (lockfile );
2207
2207
}
2208
2208
2209
- static int do_write_index (struct index_state * istate , int newfd ,
2209
+ static int do_write_index (struct index_state * istate , struct tempfile * tempfile ,
2210
2210
int strip_extensions )
2211
2211
{
2212
+ int newfd = tempfile -> fd ;
2212
2213
git_SHA_CTX c ;
2213
2214
struct cache_header hdr ;
2214
2215
int i , err , removed , extended , hdr_version ;
@@ -2317,7 +2318,11 @@ static int do_write_index(struct index_state *istate, int newfd,
2317
2318
return -1 ;
2318
2319
}
2319
2320
2320
- if (ce_flush (& c , newfd , istate -> sha1 ) || fstat (newfd , & st ))
2321
+ if (ce_flush (& c , newfd , istate -> sha1 ))
2322
+ return -1 ;
2323
+ if (close_tempfile (tempfile ))
2324
+ return error (_ ("could not close '%s'" ), tempfile -> filename .buf );
2325
+ if (lstat (tempfile -> filename .buf , & st ))
2321
2326
return -1 ;
2322
2327
istate -> timestamp .sec = (unsigned int )st .st_mtime ;
2323
2328
istate -> timestamp .nsec = ST_MTIME_NSEC (st );
@@ -2340,7 +2345,7 @@ static int commit_locked_index(struct lock_file *lk)
2340
2345
static int do_write_locked_index (struct index_state * istate , struct lock_file * lock ,
2341
2346
unsigned flags )
2342
2347
{
2343
- int ret = do_write_index (istate , get_lock_file_fd ( lock ) , 0 );
2348
+ int ret = do_write_index (istate , & lock -> tempfile , 0 );
2344
2349
if (ret )
2345
2350
return ret ;
2346
2351
assert ((flags & (COMMIT_LOCK | CLOSE_LOCK )) !=
@@ -2378,7 +2383,7 @@ static int write_shared_index(struct index_state *istate,
2378
2383
return do_write_locked_index (istate , lock , flags );
2379
2384
}
2380
2385
move_cache_to_base_index (istate );
2381
- ret = do_write_index (si -> base , fd , 1 );
2386
+ ret = do_write_index (si -> base , & temporary_sharedindex , 1 );
2382
2387
if (ret ) {
2383
2388
delete_tempfile (& temporary_sharedindex );
2384
2389
return ret ;
0 commit comments