@@ -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 ;
@@ -2358,7 +2359,11 @@ static int do_write_index(struct index_state *istate, int newfd,
2358
2359
return -1 ;
2359
2360
}
2360
2361
2361
- if (ce_flush (& c , newfd , istate -> sha1 ) || fstat (newfd , & st ))
2362
+ if (ce_flush (& c , newfd , istate -> sha1 ))
2363
+ return -1 ;
2364
+ if (close_tempfile (tempfile ))
2365
+ return error (_ ("could not close '%s'" ), tempfile -> filename .buf );
2366
+ if (lstat (tempfile -> filename .buf , & st ))
2362
2367
return -1 ;
2363
2368
istate -> timestamp .sec = (unsigned int )st .st_mtime ;
2364
2369
istate -> timestamp .nsec = ST_MTIME_NSEC (st );
@@ -2381,7 +2386,7 @@ static int commit_locked_index(struct lock_file *lk)
2381
2386
static int do_write_locked_index (struct index_state * istate , struct lock_file * lock ,
2382
2387
unsigned flags )
2383
2388
{
2384
- int ret = do_write_index (istate , get_lock_file_fd ( lock ) , 0 );
2389
+ int ret = do_write_index (istate , & lock -> tempfile , 0 );
2385
2390
if (ret )
2386
2391
return ret ;
2387
2392
assert ((flags & (COMMIT_LOCK | CLOSE_LOCK )) !=
@@ -2478,7 +2483,7 @@ static int write_shared_index(struct index_state *istate,
2478
2483
return do_write_locked_index (istate , lock , flags );
2479
2484
}
2480
2485
move_cache_to_base_index (istate );
2481
- ret = do_write_index (si -> base , fd , 1 );
2486
+ ret = do_write_index (si -> base , & temporary_sharedindex , 1 );
2482
2487
if (ret ) {
2483
2488
delete_tempfile (& temporary_sharedindex );
2484
2489
return ret ;
0 commit comments