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