Skip to content

Commit b3a79dd

Browse files
pks-tgitster
authored andcommitted
reftable/stack: adjust permissions of compacted tables
When creating a new compacted table from a range of preexisting ones we don't set the default permissions on the resulting table when specified by the user. This has the effect that the "core.sharedRepository" config will not be honored correctly. Fix this bug and add a test to catch this issue. Note that we only test on non-Windows platforms because Windows does not use POSIX permissions natively. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e02ecfc commit b3a79dd

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

reftable/stack.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,12 @@ static int stack_compact_locked(struct reftable_stack *st, int first, int last,
731731
strbuf_addstr(temp_tab, ".temp.XXXXXX");
732732

733733
tab_fd = mkstemp(temp_tab->buf);
734+
if (st->config.default_permissions &&
735+
chmod(temp_tab->buf, st->config.default_permissions) < 0) {
736+
err = REFTABLE_IO_ERROR;
737+
goto done;
738+
}
739+
734740
wr = reftable_new_writer(reftable_fd_write, &tab_fd, &st->config);
735741

736742
err = stack_write_compact(st, wr, first, last, config);

reftable/stack_test.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,16 @@ static void test_reftable_stack_add(void)
443443
int err = 0;
444444
struct reftable_write_options cfg = {
445445
.exact_log_message = 1,
446+
.default_permissions = 0660,
446447
};
447448
struct reftable_stack *st = NULL;
448449
char *dir = get_tmp_dir(__LINE__);
449-
450450
struct reftable_ref_record refs[2] = { { NULL } };
451451
struct reftable_log_record logs[2] = { { NULL } };
452+
struct strbuf path = STRBUF_INIT;
453+
struct stat stat_result;
452454
int N = ARRAY_SIZE(refs);
453455

454-
455456
err = reftable_new_stack(&st, dir, cfg);
456457
EXPECT_ERR(err);
457458
st->disable_auto_compact = 1;
@@ -509,12 +510,32 @@ static void test_reftable_stack_add(void)
509510
reftable_log_record_release(&dest);
510511
}
511512

513+
#ifndef GIT_WINDOWS_NATIVE
514+
strbuf_addstr(&path, dir);
515+
strbuf_addstr(&path, "/tables.list");
516+
err = stat(path.buf, &stat_result);
517+
EXPECT(!err);
518+
EXPECT((stat_result.st_mode & 0777) == cfg.default_permissions);
519+
520+
strbuf_reset(&path);
521+
strbuf_addstr(&path, dir);
522+
strbuf_addstr(&path, "/");
523+
/* do not try at home; not an external API for reftable. */
524+
strbuf_addstr(&path, st->readers[0]->name);
525+
err = stat(path.buf, &stat_result);
526+
EXPECT(!err);
527+
EXPECT((stat_result.st_mode & 0777) == cfg.default_permissions);
528+
#else
529+
(void) stat_result;
530+
#endif
531+
512532
/* cleanup */
513533
reftable_stack_destroy(st);
514534
for (i = 0; i < N; i++) {
515535
reftable_ref_record_release(&refs[i]);
516536
reftable_log_record_release(&logs[i]);
517537
}
538+
strbuf_release(&path);
518539
clear_dir(dir);
519540
}
520541

0 commit comments

Comments
 (0)