@@ -2141,9 +2141,10 @@ void update_index_if_able(struct index_state *istate, struct lock_file *lockfile
21412141 rollback_lock_file (lockfile );
21422142}
21432143
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 ,
21452145 int strip_extensions )
21462146{
2147+ int newfd = tempfile -> fd ;
21472148 git_SHA_CTX c ;
21482149 struct cache_header hdr ;
21492150 int i , err , removed , extended , hdr_version ;
@@ -2252,7 +2253,11 @@ static int do_write_index(struct index_state *istate, int newfd,
22522253 return -1 ;
22532254 }
22542255
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 ))
22562261 return -1 ;
22572262 istate -> timestamp .sec = (unsigned int )st .st_mtime ;
22582263 istate -> timestamp .nsec = ST_MTIME_NSEC (st );
@@ -2275,7 +2280,7 @@ static int commit_locked_index(struct lock_file *lk)
22752280static int do_write_locked_index (struct index_state * istate , struct lock_file * lock ,
22762281 unsigned flags )
22772282{
2278- int ret = do_write_index (istate , get_lock_file_fd ( lock ) , 0 );
2283+ int ret = do_write_index (istate , & lock -> tempfile , 0 );
22792284 if (ret )
22802285 return ret ;
22812286 assert ((flags & (COMMIT_LOCK | CLOSE_LOCK )) !=
@@ -2313,7 +2318,7 @@ static int write_shared_index(struct index_state *istate,
23132318 return do_write_locked_index (istate , lock , flags );
23142319 }
23152320 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 );
23172322 if (ret ) {
23182323 delete_tempfile (& temporary_sharedindex );
23192324 return ret ;
0 commit comments