@@ -2141,9 +2141,10 @@ void update_index_if_able(struct index_state *istate, struct lock_file *lockfile
2141
2141
rollback_lock_file (lockfile );
2142
2142
}
2143
2143
2144
- static int do_write_index (struct index_state * istate , int newfd ,
2144
+ static int do_write_index (struct index_state * istate , struct tempfile * tempfile ,
2145
2145
int strip_extensions )
2146
2146
{
2147
+ int newfd = tempfile -> fd ;
2147
2148
git_SHA_CTX c ;
2148
2149
struct cache_header hdr ;
2149
2150
int i , err , removed , extended , hdr_version ;
@@ -2252,7 +2253,11 @@ static int do_write_index(struct index_state *istate, int newfd,
2252
2253
return -1 ;
2253
2254
}
2254
2255
2255
- if (ce_flush (& c , newfd , istate -> sha1 ) || fstat (newfd , & st ))
2256
+ if (ce_flush (& c , newfd , istate -> sha1 ))
2257
+ return -1 ;
2258
+ if (close_tempfile (tempfile ))
2259
+ return error (_ ("could not close '%s'" ), tempfile -> filename .buf );
2260
+ if (lstat (tempfile -> filename .buf , & st ))
2256
2261
return -1 ;
2257
2262
istate -> timestamp .sec = (unsigned int )st .st_mtime ;
2258
2263
istate -> timestamp .nsec = ST_MTIME_NSEC (st );
@@ -2275,7 +2280,7 @@ static int commit_locked_index(struct lock_file *lk)
2275
2280
static int do_write_locked_index (struct index_state * istate , struct lock_file * lock ,
2276
2281
unsigned flags )
2277
2282
{
2278
- int ret = do_write_index (istate , get_lock_file_fd ( lock ) , 0 );
2283
+ int ret = do_write_index (istate , & lock -> tempfile , 0 );
2279
2284
if (ret )
2280
2285
return ret ;
2281
2286
assert ((flags & (COMMIT_LOCK | CLOSE_LOCK )) !=
@@ -2313,7 +2318,7 @@ static int write_shared_index(struct index_state *istate,
2313
2318
return do_write_locked_index (istate , lock , flags );
2314
2319
}
2315
2320
move_cache_to_base_index (istate );
2316
- ret = do_write_index (si -> base , fd , 1 );
2321
+ ret = do_write_index (si -> base , & temporary_sharedindex , 1 );
2317
2322
if (ret ) {
2318
2323
delete_tempfile (& temporary_sharedindex );
2319
2324
return ret ;
0 commit comments