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

[PATCH v3 1/3] read-cache: use shared perms when writing shared index

From
Christian Couder <christian.couder@gmail.com>
Date
Jun 25, 2017, 04:34 UTC
Message-ID
<20170625043429.23337-1-chriscool@tuxfamily.org>

Since f6ecc62dbf (write_shared_index(): use tempfile module, 2015-08-10) write_shared_index() has been using mks_tempfile() to create the temporary file that will become the shared index.

But even before that, it looks like the functions used to create this file didn't call adjust_shared_perm(), which means that the shared index file has always been created with 600 permissions regardless of the shared permission settings.

Because of that, on repositories created with `git init --shared=all` and using the split index feature, one gets an error like:

fatal: .git/sharedindex.a52f910b489bc462f187ab572ba0086f7b5157de: index file open failed: Permission denied
when another user performs any operation that reads the shared index.

Call adjust_shared_perm() on the temporary file created by mks_tempfile() ourselves to adjust the permission bits.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 read-cache.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff --git a/read-cache.c b/read-cache.c
index bc156a133e..1f4ec1b022 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2425,6 +2425,14 @@ static int write_shared_index(struct index_state *istate,
 		delete_tempfile(&temporary_sharedindex);
 		return ret;
 	}
+	ret = adjust_shared_perm(get_tempfile_path(&temporary_sharedindex));
+	if (ret) {
+		int save_errno = errno;
+		error("cannot fix permission bits on %s", get_tempfile_path(&temporary_sharedindex));
+		delete_tempfile(&temporary_sharedindex);
+		errno = save_errno;
+		return ret;
+	}
 	ret = rename_tempfile(&temporary_sharedindex,
 			      git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
 	if (!ret) {
-- 
2.13.1.517.gf6399a5ea5
Next: Christian Couder
Message 1 of 3 in “read-cache: use shared perms when writing shared index”
  1. 1/3 read-cache: use shared perms when writing shared indexChristian Couder, Jun 25, 2017
  2. 2/3 t1301: move modebits() to test-lib-functions.shChristian Couder, Jun 25, 2017
  3. 3/3 t1700: make sure split-index respects core.sharedrepositoryChristian Couder, Jun 25, 2017

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.