@@ -2471,32 +2471,21 @@ static int clean_shared_index_files(const char *current_hex)
2471
2471
}
2472
2472
2473
2473
static int write_shared_index (struct index_state * istate ,
2474
- struct lock_file * lock , unsigned flags )
2474
+ struct tempfile * * temp )
2475
2475
{
2476
- struct tempfile * temp ;
2477
2476
struct split_index * si = istate -> split_index ;
2478
2477
int ret ;
2479
2478
2480
- temp = mks_tempfile (git_path ("sharedindex_XXXXXX" ));
2481
- if (!temp ) {
2482
- hashclr (si -> base_sha1 );
2483
- return do_write_locked_index (istate , lock , flags );
2484
- }
2485
2479
move_cache_to_base_index (istate );
2486
- ret = do_write_index (si -> base , temp , 1 );
2487
- if (ret ) {
2488
- delete_tempfile (& temp );
2480
+ ret = do_write_index (si -> base , * temp , 1 );
2481
+ if (ret )
2489
2482
return ret ;
2490
- }
2491
- ret = adjust_shared_perm (get_tempfile_path (temp ));
2483
+ ret = adjust_shared_perm (get_tempfile_path (* temp ));
2492
2484
if (ret ) {
2493
- int save_errno = errno ;
2494
- error ("cannot fix permission bits on %s" , get_tempfile_path (temp ));
2495
- delete_tempfile (& temp );
2496
- errno = save_errno ;
2485
+ error ("cannot fix permission bits on %s" , get_tempfile_path (* temp ));
2497
2486
return ret ;
2498
2487
}
2499
- ret = rename_tempfile (& temp ,
2488
+ ret = rename_tempfile (temp ,
2500
2489
git_path ("sharedindex.%s" , sha1_to_hex (si -> base -> sha1 )));
2501
2490
if (!ret ) {
2502
2491
hashcpy (si -> base_sha1 , si -> base -> sha1 );
@@ -2564,7 +2553,22 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
2564
2553
new_shared_index = istate -> cache_changed & SPLIT_INDEX_ORDERED ;
2565
2554
2566
2555
if (new_shared_index ) {
2567
- ret = write_shared_index (istate , lock , flags );
2556
+ struct tempfile * temp ;
2557
+ int saved_errno ;
2558
+
2559
+ temp = mks_tempfile (git_path ("sharedindex_XXXXXX" ));
2560
+ if (!temp ) {
2561
+ hashclr (si -> base_sha1 );
2562
+ ret = do_write_locked_index (istate , lock , flags );
2563
+ goto out ;
2564
+ }
2565
+ ret = write_shared_index (istate , & temp );
2566
+
2567
+ saved_errno = errno ;
2568
+ if (is_tempfile_active (temp ))
2569
+ delete_tempfile (& temp );
2570
+ errno = saved_errno ;
2571
+
2568
2572
if (ret )
2569
2573
goto out ;
2570
2574
}
0 commit comments