From df801f3f9f5be52842239f0d0233d5c3fb0cdffd Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 25 Jun 2017 06:34:27 +0200 Subject: read-cache: use shared perms when writing shared index 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 Signed-off-by: Junio C Hamano --- read-cache.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'read-cache.c') diff --git a/read-cache.c b/read-cache.c index f12da0dbb..6238df448 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2428,6 +2428,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) { -- cgit v1.2.1