@@ -2241,9 +2241,10 @@ void update_index_if_able(struct index_state *istate, struct lock_file *lockfile
2241
2241
rollback_lock_file (lockfile );
2242
2242
}
2243
2243
2244
- static int do_write_index (struct index_state * istate , int newfd ,
2244
+ static int do_write_index (struct index_state * istate , struct tempfile * tempfile ,
2245
2245
int strip_extensions )
2246
2246
{
2247
+ int newfd = tempfile -> fd ;
2247
2248
git_SHA_CTX c ;
2248
2249
struct cache_header hdr ;
2249
2250
int i , err , removed , extended , hdr_version ;
@@ -2355,7 +2356,11 @@ static int do_write_index(struct index_state *istate, int newfd,
2355
2356
return -1 ;
2356
2357
}
2357
2358
2358
- if (ce_flush (& c , newfd , istate -> sha1 ) || fstat (newfd , & st ))
2359
+ if (ce_flush (& c , newfd , istate -> sha1 ))
2360
+ return -1 ;
2361
+ if (close_tempfile (tempfile ))
2362
+ return error (_ ("could not close '%s'" ), tempfile -> filename .buf );
2363
+ if (lstat (tempfile -> filename .buf , & st ))
2359
2364
return -1 ;
2360
2365
istate -> timestamp .sec = (unsigned int )st .st_mtime ;
2361
2366
istate -> timestamp .nsec = ST_MTIME_NSEC (st );
@@ -2378,7 +2383,7 @@ static int commit_locked_index(struct lock_file *lk)
2378
2383
static int do_write_locked_index (struct index_state * istate , struct lock_file * lock ,
2379
2384
unsigned flags )
2380
2385
{
2381
- int ret = do_write_index (istate , get_lock_file_fd ( lock ) , 0 );
2386
+ int ret = do_write_index (istate , & lock -> tempfile , 0 );
2382
2387
if (ret )
2383
2388
return ret ;
2384
2389
assert ((flags & (COMMIT_LOCK | CLOSE_LOCK )) !=
@@ -2475,7 +2480,7 @@ static int write_shared_index(struct index_state *istate,
2475
2480
return do_write_locked_index (istate , lock , flags );
2476
2481
}
2477
2482
move_cache_to_base_index (istate );
2478
- ret = do_write_index (si -> base , fd , 1 );
2483
+ ret = do_write_index (si -> base , & temporary_sharedindex , 1 );
2479
2484
if (ret ) {
2480
2485
delete_tempfile (& temporary_sharedindex );
2481
2486
return ret ;
0 commit comments