@@ -8,7 +8,6 @@ license that can be found in the LICENSE file or at
8
8
9
9
#include "stack.h"
10
10
11
- #include "../write-or-die.h"
12
11
#include "system.h"
13
12
#include "constants.h"
14
13
#include "merged.h"
@@ -43,17 +42,28 @@ static int stack_filename(struct reftable_buf *dest, struct reftable_stack *st,
43
42
return 0 ;
44
43
}
45
44
46
- static ssize_t reftable_fd_write ( void * arg , const void * data , size_t sz )
45
+ static int stack_fsync ( const struct reftable_write_options * opts , int fd )
47
46
{
48
- int * fdp = (int * )arg ;
49
- return write_in_full (* fdp , data , sz );
47
+ if (opts -> fsync )
48
+ return opts -> fsync (fd );
49
+ return fsync (fd );
50
50
}
51
51
52
- static int reftable_fd_flush (void * arg )
52
+ struct fd_writer {
53
+ const struct reftable_write_options * opts ;
54
+ int fd ;
55
+ };
56
+
57
+ static ssize_t fd_writer_write (void * arg , const void * data , size_t sz )
53
58
{
54
- int * fdp = (int * )arg ;
59
+ struct fd_writer * writer = arg ;
60
+ return write_in_full (writer -> fd , data , sz );
61
+ }
55
62
56
- return fsync_component (FSYNC_COMPONENT_REFERENCE , * fdp );
63
+ static int fd_writer_flush (void * arg )
64
+ {
65
+ struct fd_writer * writer = arg ;
66
+ return stack_fsync (writer -> opts , writer -> fd );
57
67
}
58
68
59
69
int reftable_new_stack (struct reftable_stack * * dest , const char * dir ,
@@ -765,7 +775,7 @@ int reftable_addition_commit(struct reftable_addition *add)
765
775
goto done ;
766
776
}
767
777
768
- err = fsync_component ( FSYNC_COMPONENT_REFERENCE , lock_file_fd );
778
+ err = stack_fsync ( & add -> stack -> opts , lock_file_fd );
769
779
if (err < 0 ) {
770
780
err = REFTABLE_IO_ERROR ;
771
781
goto done ;
@@ -858,8 +868,10 @@ int reftable_addition_add(struct reftable_addition *add,
858
868
struct reftable_buf next_name = REFTABLE_BUF_INIT ;
859
869
struct reftable_writer * wr = NULL ;
860
870
struct tempfile * tab_file = NULL ;
871
+ struct fd_writer writer = {
872
+ .opts = & add -> stack -> opts ,
873
+ };
861
874
int err = 0 ;
862
- int tab_fd ;
863
875
864
876
reftable_buf_reset (& next_name );
865
877
@@ -887,10 +899,10 @@ int reftable_addition_add(struct reftable_addition *add,
887
899
goto done ;
888
900
}
889
901
}
890
- tab_fd = get_tempfile_fd (tab_file );
891
902
892
- err = reftable_writer_new (& wr , reftable_fd_write , reftable_fd_flush ,
893
- & tab_fd , & add -> stack -> opts );
903
+ writer .fd = get_tempfile_fd (tab_file );
904
+ err = reftable_writer_new (& wr , fd_writer_write , fd_writer_flush ,
905
+ & writer , & add -> stack -> opts );
894
906
if (err < 0 )
895
907
goto done ;
896
908
@@ -973,8 +985,11 @@ static int stack_compact_locked(struct reftable_stack *st,
973
985
struct reftable_buf next_name = REFTABLE_BUF_INIT ;
974
986
struct reftable_buf tab_file_path = REFTABLE_BUF_INIT ;
975
987
struct reftable_writer * wr = NULL ;
988
+ struct fd_writer writer = {
989
+ .opts = & st -> opts ,
990
+ };
976
991
struct tempfile * tab_file ;
977
- int tab_fd , err = 0 ;
992
+ int err = 0 ;
978
993
979
994
err = format_name (& next_name , reftable_reader_min_update_index (st -> readers [first ]),
980
995
reftable_reader_max_update_index (st -> readers [last ]));
@@ -994,16 +1009,16 @@ static int stack_compact_locked(struct reftable_stack *st,
994
1009
err = REFTABLE_IO_ERROR ;
995
1010
goto done ;
996
1011
}
997
- tab_fd = get_tempfile_fd (tab_file );
998
1012
999
1013
if (st -> opts .default_permissions &&
1000
1014
chmod (get_tempfile_path (tab_file ), st -> opts .default_permissions ) < 0 ) {
1001
1015
err = REFTABLE_IO_ERROR ;
1002
1016
goto done ;
1003
1017
}
1004
1018
1005
- err = reftable_writer_new (& wr , reftable_fd_write , reftable_fd_flush ,
1006
- & tab_fd , & st -> opts );
1019
+ writer .fd = get_tempfile_fd (tab_file );
1020
+ err = reftable_writer_new (& wr , fd_writer_write , fd_writer_flush ,
1021
+ & writer , & st -> opts );
1007
1022
if (err < 0 )
1008
1023
goto done ;
1009
1024
@@ -1460,7 +1475,7 @@ static int stack_compact_range(struct reftable_stack *st,
1460
1475
goto done ;
1461
1476
}
1462
1477
1463
- err = fsync_component ( FSYNC_COMPONENT_REFERENCE , get_lock_file_fd (& tables_list_lock ));
1478
+ err = stack_fsync ( & st -> opts , get_lock_file_fd (& tables_list_lock ));
1464
1479
if (err < 0 ) {
1465
1480
err = REFTABLE_IO_ERROR ;
1466
1481
unlink (new_table_path .buf );
0 commit comments