{"thread":{"id":"2233","subject":"[PATCH 4/4] Test in git-init-db if the filemode can be trusted","startedAt":"2005-10-25T23:43:03Z","lastAt":"2005-10-26T07:01:58Z","messageCount":2,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"10630","messageId":"Pine.LNX.4.63.0510260141220.30576@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2233","inReplyTo":null,"subject":"[PATCH 4/4] Test in git-init-db if the filemode can be trusted","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-10-25T23:43:03Z","receivedAt":"2005-10-25T23:43:03Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"... and if not, write an appropriate .git/config. Of course, that happens \nonly if no config file was yet created (by a template or a hook).\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n\tThis might be a bit controversial, as we probably need a way to \n\twrite to .git/config anyway. Until there are such functions, I'll\n\tlive with this patch.\n\n init-db.c |   37 +++++++++++++++++++++++++++++++++++++\n 1 files changed, 37 insertions(+), 0 deletions(-)\n\napplies-to: 047019cf0b103c8350c6b4da7836b15795c69498\n64ca59712d766e8264f9208d70b8f5c811dfd3ea\ndiff --git a/init-db.c b/init-db.c\nindex 2c27e18..b242fbf 100644\n--- a/init-db.c\n+++ b/init-db.c\n@@ -196,6 +196,43 @@ static void create_default_files(const c\n \t}\n \tpath[len] = 0;\n \tcopy_templates(path, len, template_path);\n+\n+\t/*\n+\t * Find out if we can trust the executable bit.\n+\t */\n+\tsafe_create_dir(path);\n+\tstrcpy(path + len, \"config\");\n+\tif (access(path, R_OK) < 0) {\n+\t\tstatic const char contents[] =\n+\t\t\t\"#\\n\"\n+\t\t\t\"# This is the config file\\n\"\n+\t\t\t\"#\\n\"\n+\t\t\t\"\\n\"\n+\t\t\t\"; core variables\\n\"\n+\t\t\t\"[core]\\n\"\n+\t\t\t\"\t; Don't trust file modes\\n\"\n+\t\t\t\"\tfilemode = false\\n\"\n+\t\t\t\"\\n\";\n+\t\tFILE *config = fopen(path, \"w\");\n+\t\tstruct stat st;\n+\n+\t\tif (!config)\n+\t\t\tdie(\"Can not write to %s?\", path);\n+\n+\t\tfwrite(contents, sizeof(contents)-1, 1, config);\n+\n+\t\tfclose(config);\n+\n+\t\tif (!lstat(path, &st)) {\n+\t\t\tstruct stat st2;\n+\t\t\tif (!chmod(path, st.st_mode ^ S_IXUSR) &&\n+\t\t\t\t\t!lstat(path, &st2) &&\n+\t\t\t\t\tst.st_mode != st2.st_mode)\n+\t\t\t\tunlink(path);\n+\t\t\telse\n+\t\t\t\tfprintf(stderr, \"Ignoring file modes\\n\");\n+\t\t}\n+\t}\n }\n \n static const char init_db_usage[] =\n---\n0.99.8.GIT\n"},{"id":"10642","messageId":"7vhdb4ahi1.fsf@assigned-by-dhcp.cox.net","threadId":"2233","inReplyTo":"Pine.LNX.4.63.0510260141220.30576@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH 4/4] Test in git-init-db if the filemode can be trusted","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-10-26T07:01:58Z","receivedAt":"2005-10-26T07:01:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> ... and if not, write an appropriate .git/config. Of course, that happens \n> only if no config file was yet created (by a template or a hook).\n>\n> Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n>\n> ---\n>\n> \tThis might be a bit controversial, as we probably need a way to \n> \twrite to .git/config anyway. Until there are such functions, I'll\n> \tlive with this patch.\n\nHmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm.  Yes, we discussed something\nlike this earlier.  It probably is a good usability patch, but\nat the same time it does not feel quite right, but I cannot\nexplain why.  Probably because I have not suffered from FAT for\nsome time, lucky me, I guess.\n \n"}]}