@@ -469,7 +469,7 @@ static int reftable_stack_init_addition(struct reftable_addition *add,
469469 strbuf_addstr (& add -> lock_file_name , ".lock" );
470470
471471 add -> lock_file_fd = open (add -> lock_file_name .buf ,
472- O_EXCL | O_CREAT | O_WRONLY , 0644 );
472+ O_EXCL | O_CREAT | O_WRONLY , 0666 );
473473 if (add -> lock_file_fd < 0 ) {
474474 if (errno == EEXIST ) {
475475 err = REFTABLE_LOCK_ERROR ;
@@ -478,6 +478,13 @@ static int reftable_stack_init_addition(struct reftable_addition *add,
478478 }
479479 goto done ;
480480 }
481+ if (st -> config .default_permissions ) {
482+ if (chmod (add -> lock_file_name .buf , st -> config .default_permissions ) < 0 ) {
483+ err = REFTABLE_IO_ERROR ;
484+ goto done ;
485+ }
486+ }
487+
481488 err = stack_uptodate (st );
482489 if (err < 0 )
483490 goto done ;
@@ -644,7 +651,12 @@ int reftable_addition_add(struct reftable_addition *add,
644651 err = REFTABLE_IO_ERROR ;
645652 goto done ;
646653 }
647-
654+ if (add -> stack -> config .default_permissions ) {
655+ if (chmod (temp_tab_file_name .buf , add -> stack -> config .default_permissions )) {
656+ err = REFTABLE_IO_ERROR ;
657+ goto done ;
658+ }
659+ }
648660 wr = reftable_new_writer (reftable_fd_write , & tab_fd ,
649661 & add -> stack -> config );
650662 err = write_table (wr , arg );
@@ -900,7 +912,7 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last,
900912 strbuf_addstr (& lock_file_name , ".lock" );
901913
902914 lock_file_fd =
903- open (lock_file_name .buf , O_EXCL | O_CREAT | O_WRONLY , 0644 );
915+ open (lock_file_name .buf , O_EXCL | O_CREAT | O_WRONLY , 0666 );
904916 if (lock_file_fd < 0 ) {
905917 if (errno == EEXIST ) {
906918 err = 1 ;
@@ -931,8 +943,8 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last,
931943 strbuf_addstr (& subtab_lock , ".lock" );
932944
933945 sublock_file_fd = open (subtab_lock .buf ,
934- O_EXCL | O_CREAT | O_WRONLY , 0644 );
935- if (sublock_file_fd > 0 ) {
946+ O_EXCL | O_CREAT | O_WRONLY , 0666 );
947+ if (sublock_file_fd >= 0 ) {
936948 close (sublock_file_fd );
937949 } else if (sublock_file_fd < 0 ) {
938950 if (errno == EEXIST ) {
@@ -967,7 +979,7 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last,
967979 goto done ;
968980
969981 lock_file_fd =
970- open (lock_file_name .buf , O_EXCL | O_CREAT | O_WRONLY , 0644 );
982+ open (lock_file_name .buf , O_EXCL | O_CREAT | O_WRONLY , 0666 );
971983 if (lock_file_fd < 0 ) {
972984 if (errno == EEXIST ) {
973985 err = 1 ;
@@ -977,6 +989,12 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last,
977989 goto done ;
978990 }
979991 have_lock = 1 ;
992+ if (st -> config .default_permissions ) {
993+ if (chmod (lock_file_name .buf , st -> config .default_permissions ) < 0 ) {
994+ err = REFTABLE_IO_ERROR ;
995+ goto done ;
996+ }
997+ }
980998
981999 format_name (& new_table_name , st -> readers [first ]-> min_update_index ,
9821000 st -> readers [last ]-> max_update_index );
0 commit comments