git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3] reftable/stack: adjust permissions of compacted tables

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 26, 2024, 10:09 UTC
Message-ID
<a211818108053754aca002726d0206623a347952.1706263589.git.ps@pks.im>
In-Reply-To
<cover.1706099090.git.ps@pks.im>

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 <ps@pks.im>
---
Changes compared to v2:
  - Extended the commit message to say why we don't test on Windows
    systems.
  - Renamed the `scratch` variable to `path`.
Thanks!
Patrick
 reftable/stack.c      |  6 ++++++
 reftable/stack_test.c | 25 +++++++++++++++++++++++--
 2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/reftable/stack.c b/reftable/stack.c
index 7ffeb3ee10..38e784a8ab 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -731,6 +731,12 @@ static int stack_compact_locked(struct reftable_stack *st, int first, int last,
 	strbuf_addstr(temp_tab, ".temp.XXXXXX");
 
 	tab_fd = mkstemp(temp_tab->buf);
+	if (st->config.default_permissions &&
+	    chmod(temp_tab->buf, st->config.default_permissions) < 0) {
+		err = REFTABLE_IO_ERROR;
+		goto done;
+	}
+
 	wr = reftable_new_writer(reftable_fd_write, &tab_fd, &st->config);
 
 	err = stack_write_compact(st, wr, first, last, config);
diff --git a/reftable/stack_test.c b/reftable/stack_test.c
index 289e902146..5089392f7b 100644
--- a/reftable/stack_test.c
+++ b/reftable/stack_test.c
@@ -443,15 +443,16 @@ static void test_reftable_stack_add(void)
 	int err = 0;
 	struct reftable_write_options cfg = {
 		.exact_log_message = 1,
+		.default_permissions = 0660,
 	};
 	struct reftable_stack *st = NULL;
 	char *dir = get_tmp_dir(__LINE__);
-
 	struct reftable_ref_record refs[2] = { { NULL } };
 	struct reftable_log_record logs[2] = { { NULL } };
+	struct strbuf path = STRBUF_INIT;
+	struct stat stat_result;
 	int N = ARRAY_SIZE(refs);
 
-
 	err = reftable_new_stack(&st, dir, cfg);
 	EXPECT_ERR(err);
 	st->disable_auto_compact = 1;
@@ -509,12 +510,32 @@ static void test_reftable_stack_add(void)
 		reftable_log_record_release(&dest);
 	}
 
+#ifndef GIT_WINDOWS_NATIVE
+	strbuf_addstr(&path, dir);
+	strbuf_addstr(&path, "/tables.list");
+	err = stat(path.buf, &stat_result);
+	EXPECT(!err);
+	EXPECT((stat_result.st_mode & 0777) == cfg.default_permissions);
+
+	strbuf_reset(&path);
+	strbuf_addstr(&path, dir);
+	strbuf_addstr(&path, "/");
+	/* do not try at home; not an external API for reftable. */
+	strbuf_addstr(&path, st->readers[0]->name);
+	err = stat(path.buf, &stat_result);
+	EXPECT(!err);
+	EXPECT((stat_result.st_mode & 0777) == cfg.default_permissions);
+#else
+	(void) stat_result;
+#endif
+
 	/* cleanup */
 	reftable_stack_destroy(st);
 	for (i = 0; i < N; i++) {
 		reftable_ref_record_release(&refs[i]);
 		reftable_log_record_release(&logs[i]);
 	}
+	strbuf_release(&path);
 	clear_dir(dir);
 }
 

base-commit: e02ecfcc534e2021aae29077a958dd11c3897e4c
-- 
2.43.GIT
Previous: Patrick SteinhardtNext: Justin Tobler
Message 8 of 9 in “reftable: adjust permissions of compacted tables”
  1. 0/2 reftable: adjust permissions of compacted tablesPatrick Steinhardt, Jan 24, 2024
  2. 1/2 reftable/stack: use fchmod(3P) to set permissionsPatrick Steinhardt, Jan 24, 2024
  3. 2/2 reftable/stack: adjust permissions of compacted tablesPatrick Steinhardt, Jan 24, 2024
  4. reftable/stack: adjust permissions of compacted tablesPatrick Steinhardt, Jan 24, 2024
  5. Karthik NayakJan 25, 2024
  6. Justin ToblerJan 25, 2024
  7. Patrick SteinhardtJan 26, 2024
  8. reftable/stack: adjust permissions of compacted tablesPatrick Steinhardt, Jan 26, 2024
  9. Justin ToblerJan 30, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.