Skip to content

Commit df801f3

Browse files
chriscoolgitster
authored andcommitted
read-cache: use shared perms when writing shared index
Since f6ecc62 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fd99e2b commit df801f3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

read-cache.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,6 +2428,14 @@ static int write_shared_index(struct index_state *istate,
24282428
delete_tempfile(&temporary_sharedindex);
24292429
return ret;
24302430
}
2431+
ret = adjust_shared_perm(get_tempfile_path(&temporary_sharedindex));
2432+
if (ret) {
2433+
int save_errno = errno;
2434+
error("cannot fix permission bits on %s", get_tempfile_path(&temporary_sharedindex));
2435+
delete_tempfile(&temporary_sharedindex);
2436+
errno = save_errno;
2437+
return ret;
2438+
}
24312439
ret = rename_tempfile(&temporary_sharedindex,
24322440
git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
24332441
if (!ret) {

0 commit comments

Comments
 (0)