@@ -8,7 +8,6 @@ license that can be found in the LICENSE file or at
88
99#include "stack.h"
1010
11- #include "../write-or-die.h"
1211#include "system.h"
1312#include "constants.h"
1413#include "merged.h"
@@ -43,17 +42,28 @@ static int stack_filename(struct reftable_buf *dest, struct reftable_stack *st,
4342 return 0 ;
4443}
4544
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 )
4746{
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 );
5050}
5151
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 )
5358{
54- int * fdp = (int * )arg ;
59+ struct fd_writer * writer = arg ;
60+ return write_in_full (writer -> fd , data , sz );
61+ }
5562
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 );
5767}
5868
5969int reftable_new_stack (struct reftable_stack * * dest , const char * dir ,
@@ -765,7 +775,7 @@ int reftable_addition_commit(struct reftable_addition *add)
765775 goto done ;
766776 }
767777
768- err = fsync_component ( FSYNC_COMPONENT_REFERENCE , lock_file_fd );
778+ err = stack_fsync ( & add -> stack -> opts , lock_file_fd );
769779 if (err < 0 ) {
770780 err = REFTABLE_IO_ERROR ;
771781 goto done ;
@@ -858,8 +868,10 @@ int reftable_addition_add(struct reftable_addition *add,
858868 struct reftable_buf next_name = REFTABLE_BUF_INIT ;
859869 struct reftable_writer * wr = NULL ;
860870 struct tempfile * tab_file = NULL ;
871+ struct fd_writer writer = {
872+ .opts = & add -> stack -> opts ,
873+ };
861874 int err = 0 ;
862- int tab_fd ;
863875
864876 reftable_buf_reset (& next_name );
865877
@@ -887,10 +899,10 @@ int reftable_addition_add(struct reftable_addition *add,
887899 goto done ;
888900 }
889901 }
890- tab_fd = get_tempfile_fd (tab_file );
891902
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 );
894906 if (err < 0 )
895907 goto done ;
896908
@@ -973,8 +985,11 @@ static int stack_compact_locked(struct reftable_stack *st,
973985 struct reftable_buf next_name = REFTABLE_BUF_INIT ;
974986 struct reftable_buf tab_file_path = REFTABLE_BUF_INIT ;
975987 struct reftable_writer * wr = NULL ;
988+ struct fd_writer writer = {
989+ .opts = & st -> opts ,
990+ };
976991 struct tempfile * tab_file ;
977- int tab_fd , err = 0 ;
992+ int err = 0 ;
978993
979994 err = format_name (& next_name , reftable_reader_min_update_index (st -> readers [first ]),
980995 reftable_reader_max_update_index (st -> readers [last ]));
@@ -994,16 +1009,16 @@ static int stack_compact_locked(struct reftable_stack *st,
9941009 err = REFTABLE_IO_ERROR ;
9951010 goto done ;
9961011 }
997- tab_fd = get_tempfile_fd (tab_file );
9981012
9991013 if (st -> opts .default_permissions &&
10001014 chmod (get_tempfile_path (tab_file ), st -> opts .default_permissions ) < 0 ) {
10011015 err = REFTABLE_IO_ERROR ;
10021016 goto done ;
10031017 }
10041018
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 );
10071022 if (err < 0 )
10081023 goto done ;
10091024
@@ -1460,7 +1475,7 @@ static int stack_compact_range(struct reftable_stack *st,
14601475 goto done ;
14611476 }
14621477
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 ));
14641479 if (err < 0 ) {
14651480 err = REFTABLE_IO_ERROR ;
14661481 unlink (new_table_path .buf );
0 commit comments