{"thread":{"id":"46253","subject":"[PATCH v3 1/3] read-cache: use shared perms when writing shared index","startedAt":"2017-06-25T04:35:06Z","lastAt":"2017-06-25T04:35:08Z","messageCount":3,"participants":["Christian Couder"],"isPatch":true,"patchVersion":3,"patchTotal":3},"messages":[{"id":"323229","messageId":"20170625043429.23337-1-chriscool@tuxfamily.org","threadId":"46253","inReplyTo":null,"subject":"[PATCH v3 1/3] read-cache: use shared perms when writing shared index","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2017-06-25T04:34:27Z","receivedAt":"2017-06-25T04:35:06Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Since f6ecc62dbf (write_shared_index(): use tempfile module, 2015-08-10)\nwrite_shared_index() has been using mks_tempfile() to create the\ntemporary file that will become the shared index.\n\nBut even before that, it looks like the functions used to create this\nfile didn't call adjust_shared_perm(), which means that the shared\nindex file has always been created with 600 permissions regardless\nof the shared permission settings.\n\nBecause of that, on repositories created with `git init --shared=all`\nand using the split index feature, one gets an error like:\n\nfatal: .git/sharedindex.a52f910b489bc462f187ab572ba0086f7b5157de: index file open failed: Permission denied\n\nwhen another user performs any operation that reads the shared index.\n\nCall adjust_shared_perm() on the temporary file created by\nmks_tempfile() ourselves to adjust the permission bits.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n read-cache.c | 8 ++++++++\n 1 file changed, 8 insertions(+)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex bc156a133e..1f4ec1b022 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2425,6 +2425,14 @@ static int write_shared_index(struct index_state *istate,\n \t\tdelete_tempfile(&temporary_sharedindex);\n \t\treturn ret;\n \t}\n+\tret = adjust_shared_perm(get_tempfile_path(&temporary_sharedindex));\n+\tif (ret) {\n+\t\tint save_errno = errno;\n+\t\terror(\"cannot fix permission bits on %s\", get_tempfile_path(&temporary_sharedindex));\n+\t\tdelete_tempfile(&temporary_sharedindex);\n+\t\terrno = save_errno;\n+\t\treturn ret;\n+\t}\n \tret = rename_tempfile(&temporary_sharedindex,\n \t\t\t      git_path(\"sharedindex.%s\", sha1_to_hex(si->base->sha1)));\n \tif (!ret) {\n-- \n2.13.1.517.gf6399a5ea5\n\n"},{"id":"323230","messageId":"20170625043429.23337-2-chriscool@tuxfamily.org","threadId":"46253","inReplyTo":"20170625043429.23337-1-chriscool@tuxfamily.org","subject":"[PATCH v3 2/3] t1301: move modebits() to test-lib-functions.sh","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2017-06-25T04:34:28Z","receivedAt":"2017-06-25T04:35:07Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"As the modebits() function can be useful outside t1301,\nlet's move it into test-lib-functions.sh, and while at\nit let's rename it test_modebits().\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n t/t1301-shared-repo.sh  | 18 +++++++-----------\n t/test-lib-functions.sh |  5 +++++\n 2 files changed, 12 insertions(+), 11 deletions(-)\n\ndiff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh\nindex 1312004f8c..dfece751b5 100755\n--- a/t/t1301-shared-repo.sh\n+++ b/t/t1301-shared-repo.sh\n@@ -19,10 +19,6 @@ test_expect_success 'shared = 0400 (faulty permission u-w)' '\n \t)\n '\n \n-modebits () {\n-\tls -l \"$1\" | sed -e 's|^\\(..........\\).*|\\1|'\n-}\n-\n for u in 002 022\n do\n \ttest_expect_success POSIXPERM \"shared=1 does not clear bits preset by umask $u\" '\n@@ -88,7 +84,7 @@ do\n \n \t\trm -f .git/info/refs &&\n \t\tgit update-server-info &&\n-\t\tactual=\"$(modebits .git/info/refs)\" &&\n+\t\tactual=\"$(test_modebits .git/info/refs)\" &&\n \t\tverbose test \"x$actual\" = \"x-$y\"\n \n \t'\n@@ -98,7 +94,7 @@ do\n \n \t\trm -f .git/info/refs &&\n \t\tgit update-server-info &&\n-\t\tactual=\"$(modebits .git/info/refs)\" &&\n+\t\tactual=\"$(test_modebits .git/info/refs)\" &&\n \t\tverbose test \"x$actual\" = \"x-$x\"\n \n \t'\n@@ -111,7 +107,7 @@ test_expect_success POSIXPERM 'info/refs respects umask in unshared repo' '\n \tumask 002 &&\n \tgit update-server-info &&\n \techo \"-rw-rw-r--\" >expect &&\n-\tmodebits .git/info/refs >actual &&\n+\ttest_modebits .git/info/refs >actual &&\n \ttest_cmp expect actual\n '\n \n@@ -177,7 +173,7 @@ test_expect_success POSIXPERM 'remote init does not use config from cwd' '\n \tumask 0022 &&\n \tgit init --bare child.git &&\n \techo \"-rw-r--r--\" >expect &&\n-\tmodebits child.git/config >actual &&\n+\ttest_modebits child.git/config >actual &&\n \ttest_cmp expect actual\n '\n \n@@ -187,7 +183,7 @@ test_expect_success POSIXPERM 're-init respects core.sharedrepository (local)' '\n \techo whatever >templates/foo &&\n \tgit init --template=templates &&\n \techo \"-rw-rw-rw-\" >expect &&\n-\tmodebits .git/foo >actual &&\n+\ttest_modebits .git/foo >actual &&\n \ttest_cmp expect actual\n '\n \n@@ -198,7 +194,7 @@ test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)'\n \ttest_path_is_missing child.git/foo &&\n \tgit init --bare --template=../templates child.git &&\n \techo \"-rw-rw-rw-\" >expect &&\n-\tmodebits child.git/foo >actual &&\n+\ttest_modebits child.git/foo >actual &&\n \ttest_cmp expect actual\n '\n \n@@ -209,7 +205,7 @@ test_expect_success POSIXPERM 'template can set core.sharedrepository' '\n \tcp .git/config templates/config &&\n \tgit init --bare --template=../templates child.git &&\n \techo \"-rw-rw-rw-\" >expect &&\n-\tmodebits child.git/HEAD >actual &&\n+\ttest_modebits child.git/HEAD >actual &&\n \ttest_cmp expect actual\n '\n \ndiff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\nindex 5ee124332a..db622c3555 100644\n--- a/t/test-lib-functions.sh\n+++ b/t/test-lib-functions.sh\n@@ -216,6 +216,11 @@ test_chmod () {\n \tgit update-index --add \"--chmod=$@\"\n }\n \n+# Get the modebits from a file.\n+test_modebits () {\n+\tls -l \"$1\" | sed -e 's|^\\(..........\\).*|\\1|'\n+}\n+\n # Unset a configuration variable, but don't fail if it doesn't exist.\n test_unconfig () {\n \tconfig_dir=\n-- \n2.13.1.517.gf6399a5ea5\n\n"},{"id":"323231","messageId":"20170625043429.23337-3-chriscool@tuxfamily.org","threadId":"46253","inReplyTo":"20170625043429.23337-1-chriscool@tuxfamily.org","subject":"[PATCH v3 3/3] t1700: make sure split-index respects core.sharedrepository","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2017-06-25T04:34:29Z","receivedAt":"2017-06-25T04:35:08Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Add a few tests to check that both the split-index file and the\nshared-index file are created using the right permissions when\ncore.sharedrepository is set.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n t/t1700-split-index.sh | 30 ++++++++++++++++++++++++++++++\n 1 file changed, 30 insertions(+)\n\ndiff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh\nindex af3ec0da5a..22f69a410b 100755\n--- a/t/t1700-split-index.sh\n+++ b/t/t1700-split-index.sh\n@@ -370,4 +370,34 @@ test_expect_success 'check splitIndex.sharedIndexExpire set to \"never\" and \"now\"\n \ttest $(ls .git/sharedindex.* | wc -l) -le 2\n '\n \n+while read -r mode modebits\n+do\n+\ttest_expect_success POSIXPERM \"split index respects core.sharedrepository $mode\" '\n+\t\t# Remove existing shared index files\n+\t\tgit config core.splitIndex false &&\n+\t\tgit update-index --force-remove one &&\n+\t\trm -f .git/sharedindex.* &&\n+\t\t# Create one new shared index file\n+\t\tgit config core.sharedrepository \"$mode\" &&\n+\t\tgit config core.splitIndex true &&\n+\t\t: >one &&\n+\t\tgit update-index --add one &&\n+\t\techo \"$modebits\" >expect &&\n+\t\ttest_modebits .git/index >actual &&\n+\t\ttest_cmp expect actual &&\n+\t\tshared=$(ls .git/sharedindex.*) &&\n+\t\tcase \"$shared\" in\n+\t\t*\" \"*)\n+\t\t\t# we have more than one???\n+\t\t\tfalse ;;\n+\t\t*)\n+\t\t\ttest_modebits \"$shared\" >actual &&\n+\t\t\ttest_cmp expect actual ;;\n+\t\tesac\n+\t'\n+done <<\\EOF\n+0666 -rw-rw-rw-\n+0642 -rw-r---w-\n+EOF\n+\n test_done\n-- \n2.13.1.517.gf6399a5ea5\n\n"}]}