@@ -16,7 +16,6 @@ license that can be found in the LICENSE file or at
16
16
#include "reftable-record.h"
17
17
#include "reftable-merged.h"
18
18
#include "writer.h"
19
- #include "tempfile.h"
20
19
21
20
static int stack_try_add (struct reftable_stack * st ,
22
21
int (* write_table )(struct reftable_writer * wr ,
@@ -867,7 +866,7 @@ int reftable_addition_add(struct reftable_addition *add,
867
866
struct reftable_buf tab_file_name = REFTABLE_BUF_INIT ;
868
867
struct reftable_buf next_name = REFTABLE_BUF_INIT ;
869
868
struct reftable_writer * wr = NULL ;
870
- struct tempfile * tab_file = NULL ;
869
+ struct reftable_tmpfile tab_file = REFTABLE_TMPFILE_INIT ;
871
870
struct fd_writer writer = {
872
871
.opts = & add -> stack -> opts ,
873
872
};
@@ -887,20 +886,18 @@ int reftable_addition_add(struct reftable_addition *add,
887
886
if (err < 0 )
888
887
goto done ;
889
888
890
- tab_file = mks_tempfile (temp_tab_file_name .buf );
891
- if (!tab_file ) {
892
- err = REFTABLE_IO_ERROR ;
889
+ err = tmpfile_from_pattern (& tab_file , temp_tab_file_name .buf );
890
+ if (err < 0 )
893
891
goto done ;
894
- }
895
892
if (add -> stack -> opts .default_permissions ) {
896
- if (chmod (get_tempfile_path ( tab_file ) ,
893
+ if (chmod (tab_file . path ,
897
894
add -> stack -> opts .default_permissions )) {
898
895
err = REFTABLE_IO_ERROR ;
899
896
goto done ;
900
897
}
901
898
}
902
899
903
- writer .fd = get_tempfile_fd ( tab_file ) ;
900
+ writer .fd = tab_file . fd ;
904
901
err = reftable_writer_new (& wr , fd_writer_write , fd_writer_flush ,
905
902
& writer , & add -> stack -> opts );
906
903
if (err < 0 )
@@ -918,11 +915,9 @@ int reftable_addition_add(struct reftable_addition *add,
918
915
if (err < 0 )
919
916
goto done ;
920
917
921
- err = close_tempfile_gently (tab_file );
922
- if (err < 0 ) {
923
- err = REFTABLE_IO_ERROR ;
918
+ err = tmpfile_close (& tab_file );
919
+ if (err < 0 )
924
920
goto done ;
925
- }
926
921
927
922
if (wr -> min_update_index < add -> next_update_index ) {
928
923
err = REFTABLE_API_ERROR ;
@@ -945,11 +940,9 @@ int reftable_addition_add(struct reftable_addition *add,
945
940
On windows, this relies on rand() picking a unique destination name.
946
941
Maybe we should do retry loop as well?
947
942
*/
948
- err = rename_tempfile (& tab_file , tab_file_name .buf );
949
- if (err < 0 ) {
950
- err = REFTABLE_IO_ERROR ;
943
+ err = tmpfile_rename (& tab_file , tab_file_name .buf );
944
+ if (err < 0 )
951
945
goto done ;
952
- }
953
946
954
947
REFTABLE_ALLOC_GROW (add -> new_tables , add -> new_tables_len + 1 ,
955
948
add -> new_tables_cap );
@@ -960,7 +953,7 @@ int reftable_addition_add(struct reftable_addition *add,
960
953
add -> new_tables [add -> new_tables_len ++ ] = reftable_buf_detach (& next_name );
961
954
962
955
done :
963
- delete_tempfile (& tab_file );
956
+ tmpfile_delete (& tab_file );
964
957
reftable_buf_release (& temp_tab_file_name );
965
958
reftable_buf_release (& tab_file_name );
966
959
reftable_buf_release (& next_name );
@@ -980,15 +973,15 @@ uint64_t reftable_stack_next_update_index(struct reftable_stack *st)
980
973
static int stack_compact_locked (struct reftable_stack * st ,
981
974
size_t first , size_t last ,
982
975
struct reftable_log_expiry_config * config ,
983
- struct tempfile * * tab_file_out )
976
+ struct reftable_tmpfile * tab_file_out )
984
977
{
985
978
struct reftable_buf next_name = REFTABLE_BUF_INIT ;
986
979
struct reftable_buf tab_file_path = REFTABLE_BUF_INIT ;
987
980
struct reftable_writer * wr = NULL ;
988
981
struct fd_writer writer = {
989
982
.opts = & st -> opts ,
990
983
};
991
- struct tempfile * tab_file ;
984
+ struct reftable_tmpfile tab_file = REFTABLE_TMPFILE_INIT ;
992
985
int err = 0 ;
993
986
994
987
err = format_name (& next_name , reftable_reader_min_update_index (st -> readers [first ]),
@@ -1004,19 +997,17 @@ static int stack_compact_locked(struct reftable_stack *st,
1004
997
if (err < 0 )
1005
998
goto done ;
1006
999
1007
- tab_file = mks_tempfile (tab_file_path .buf );
1008
- if (!tab_file ) {
1009
- err = REFTABLE_IO_ERROR ;
1000
+ err = tmpfile_from_pattern (& tab_file , tab_file_path .buf );
1001
+ if (err < 0 )
1010
1002
goto done ;
1011
- }
1012
1003
1013
1004
if (st -> opts .default_permissions &&
1014
- chmod (get_tempfile_path ( tab_file ) , st -> opts .default_permissions ) < 0 ) {
1005
+ chmod (tab_file . path , st -> opts .default_permissions ) < 0 ) {
1015
1006
err = REFTABLE_IO_ERROR ;
1016
1007
goto done ;
1017
1008
}
1018
1009
1019
- writer .fd = get_tempfile_fd ( tab_file ) ;
1010
+ writer .fd = tab_file . fd ;
1020
1011
err = reftable_writer_new (& wr , fd_writer_write , fd_writer_flush ,
1021
1012
& writer , & st -> opts );
1022
1013
if (err < 0 )
@@ -1030,15 +1021,15 @@ static int stack_compact_locked(struct reftable_stack *st,
1030
1021
if (err < 0 )
1031
1022
goto done ;
1032
1023
1033
- err = close_tempfile_gently ( tab_file );
1024
+ err = tmpfile_close ( & tab_file );
1034
1025
if (err < 0 )
1035
1026
goto done ;
1036
1027
1037
1028
* tab_file_out = tab_file ;
1038
- tab_file = NULL ;
1029
+ tab_file = REFTABLE_TMPFILE_INIT ;
1039
1030
1040
1031
done :
1041
- delete_tempfile (& tab_file );
1032
+ tmpfile_delete (& tab_file );
1042
1033
reftable_writer_free (wr );
1043
1034
reftable_buf_release (& next_name );
1044
1035
reftable_buf_release (& tab_file_path );
@@ -1171,7 +1162,7 @@ static int stack_compact_range(struct reftable_stack *st,
1171
1162
struct reftable_buf table_name = REFTABLE_BUF_INIT ;
1172
1163
struct lock_file tables_list_lock = LOCK_INIT ;
1173
1164
struct lock_file * table_locks = NULL ;
1174
- struct tempfile * new_table = NULL ;
1165
+ struct reftable_tmpfile new_table = REFTABLE_TMPFILE_INIT ;
1175
1166
int is_empty_table = 0 , err = 0 ;
1176
1167
size_t first_to_replace , last_to_replace ;
1177
1168
size_t i , nlocks = 0 ;
@@ -1439,11 +1430,9 @@ static int stack_compact_range(struct reftable_stack *st,
1439
1430
if (err < 0 )
1440
1431
goto done ;
1441
1432
1442
- err = rename_tempfile (& new_table , new_table_path .buf );
1443
- if (err < 0 ) {
1444
- err = REFTABLE_IO_ERROR ;
1433
+ err = tmpfile_rename (& new_table , new_table_path .buf );
1434
+ if (err < 0 )
1445
1435
goto done ;
1446
- }
1447
1436
}
1448
1437
1449
1438
/*
@@ -1515,7 +1504,7 @@ static int stack_compact_range(struct reftable_stack *st,
1515
1504
rollback_lock_file (& table_locks [i ]);
1516
1505
reftable_free (table_locks );
1517
1506
1518
- delete_tempfile (& new_table );
1507
+ tmpfile_delete (& new_table );
1519
1508
reftable_buf_release (& new_table_name );
1520
1509
reftable_buf_release (& new_table_path );
1521
1510
reftable_buf_release (& tables_list_buf );
0 commit comments