Skip to content

Commit 0f4e178

Browse files
committed
Merge branch 'ps/reftable-compacted-tables-permission-fix'
Reftable bugfix. * ps/reftable-compacted-tables-permission-fix: reftable/stack: adjust permissions of compacted tables
2 parents b6fdf9a + b3a79dd commit 0f4e178

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
@@ -849,6 +849,12 @@ static int stack_compact_locked(struct reftable_stack *st, int first, int last,
849849
strbuf_addstr(temp_tab, ".temp.XXXXXX");
850850

851851
tab_fd = mkstemp(temp_tab->buf);
852+
if (st->config.default_permissions &&
853+
chmod(temp_tab->buf, st->config.default_permissions) < 0) {
854+
err = REFTABLE_IO_ERROR;
855+
goto done;
856+
}
857+
852858
wr = reftable_new_writer(reftable_fd_write, reftable_fd_flush, &tab_fd, &st->config);
853859

854860
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)