@@ -2247,9 +2247,10 @@ void update_index_if_able(struct index_state *istate, struct lock_file *lockfile
2247
2247
rollback_lock_file (lockfile );
2248
2248
}
2249
2249
2250
- static int do_write_index (struct index_state * istate , int newfd ,
2250
+ static int do_write_index (struct index_state * istate , struct tempfile * tempfile ,
2251
2251
int strip_extensions )
2252
2252
{
2253
+ int newfd = tempfile -> fd ;
2253
2254
git_SHA_CTX c ;
2254
2255
struct cache_header hdr ;
2255
2256
int i , err , removed , extended , hdr_version ;
@@ -2361,7 +2362,11 @@ static int do_write_index(struct index_state *istate, int newfd,
2361
2362
return -1 ;
2362
2363
}
2363
2364
2364
- if (ce_flush (& c , newfd , istate -> sha1 ) || fstat (newfd , & st ))
2365
+ if (ce_flush (& c , newfd , istate -> sha1 ))
2366
+ return -1 ;
2367
+ if (close_tempfile (tempfile ))
2368
+ return error (_ ("could not close '%s'" ), tempfile -> filename .buf );
2369
+ if (lstat (tempfile -> filename .buf , & st ))
2365
2370
return -1 ;
2366
2371
istate -> timestamp .sec = (unsigned int )st .st_mtime ;
2367
2372
istate -> timestamp .nsec = ST_MTIME_NSEC (st );
@@ -2384,7 +2389,7 @@ static int commit_locked_index(struct lock_file *lk)
2384
2389
static int do_write_locked_index (struct index_state * istate , struct lock_file * lock ,
2385
2390
unsigned flags )
2386
2391
{
2387
- int ret = do_write_index (istate , get_lock_file_fd ( lock ) , 0 );
2392
+ int ret = do_write_index (istate , & lock -> tempfile , 0 );
2388
2393
if (ret )
2389
2394
return ret ;
2390
2395
assert ((flags & (COMMIT_LOCK | CLOSE_LOCK )) !=
@@ -2481,7 +2486,7 @@ static int write_shared_index(struct index_state *istate,
2481
2486
return do_write_locked_index (istate , lock , flags );
2482
2487
}
2483
2488
move_cache_to_base_index (istate );
2484
- ret = do_write_index (si -> base , fd , 1 );
2489
+ ret = do_write_index (si -> base , & temporary_sharedindex , 1 );
2485
2490
if (ret ) {
2486
2491
delete_tempfile (& temporary_sharedindex );
2487
2492
return ret ;
0 commit comments