{"thread":{"id":"61724","subject":"[PATCH] unpack-objects: Fix EACCES pushing to remote on vmhgfs","startedAt":"2024-07-03T13:41:17Z","lastAt":"2024-07-03T22:40:32Z","messageCount":2,"participants":["Ivan Pozdeev","brian m. carlson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"498018","messageId":"20240703134028.876-1-vano@mail.mipt.ru","threadId":"61724","inReplyTo":null,"subject":"[PATCH] unpack-objects: Fix EACCES pushing to remote on vmhgfs","fromName":"Ivan Pozdeev","fromEmail":"vano@mail.mipt.ru","sentAt":"2024-07-03T13:40:28Z","receivedAt":"2024-07-03T13:41:17Z","isPatch":true,"sender":{"key":"vano@mail.mipt.ru","avatar":null},"body":"Creating files with 0444 mode causes EACCES opening them for writing\nin some setups where the creating user does not automatically have\nwrite access.\nE.g. on a vmhgfs (VMWare shared folders) with Windows host, this causes\nthe file on the host to be created with the read-only attribute set\nwhich prohibits writing for everyone.\n\nChange the mode to 0644, explicitly signaling we want write access.\n\nSigned-off-by: Ivan Pozdeev <vano@mail.mipt.ru>\n---\n object-file.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/object-file.c b/object-file.c\nindex 610b1f465c..bc71106ea8 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -2002,7 +2002,7 @@ static int create_tmpfile(struct strbuf *tmp, const char *filename)\n \tstrbuf_reset(tmp);\n \tstrbuf_add(tmp, filename, dirlen);\n \tstrbuf_addstr(tmp, \"tmp_obj_XXXXXX\");\n-\tfd = git_mkstemp_mode(tmp->buf, 0444);\n+\tfd = git_mkstemp_mode(tmp->buf, 0644);\n \tif (fd < 0 && dirlen && errno == ENOENT) {\n \t\t/*\n \t\t * Make sure the directory exists; note that the contents\n@@ -2019,7 +2019,7 @@ static int create_tmpfile(struct strbuf *tmp, const char *filename)\n \n \t\t/* Try again */\n \t\tstrbuf_addstr(tmp, \"/tmp_obj_XXXXXX\");\n-\t\tfd = git_mkstemp_mode(tmp->buf, 0444);\n+\t\tfd = git_mkstemp_mode(tmp->buf, 0644);\n \t}\n \treturn fd;\n }\n-- \n2.36.1.windows.1\n\n"},{"id":"498064","messageId":"ZoXTWECfLzaA-tmU@tapette.crustytoothpaste.net","threadId":"61724","inReplyTo":"20240703134028.876-1-vano@mail.mipt.ru","subject":"Re: [PATCH] unpack-objects: Fix EACCES pushing to remote on vmhgfs","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2024-07-03T22:40:24Z","receivedAt":"2024-07-03T22:40:32Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2024-07-03 at 13:40:28, Ivan Pozdeev wrote:\n> Creating files with 0444 mode causes EACCES opening them for writing\n> in some setups where the creating user does not automatically have\n> write access.\n> E.g. on a vmhgfs (VMWare shared folders) with Windows host, this causes\n> the file on the host to be created with the read-only attribute set\n> which prohibits writing for everyone.\n> \n> Change the mode to 0644, explicitly signaling we want write access.\n\nBut we don't.  We don't want people to write to these files, since\nthey're objects and modifying them corrupts the repository.  The 0444\nmode is completely intentional here.\n\nWhat you're reporting actually also occurs on some broken NFS\nimplementations as well.  POSIX requires that implementations accept\nO_RDWR with 0444[0], and we require POSIX compliance from file systems.\nThe solution here is to fix this in the file system so it behaves as\nPOSIX requires[1], which I admit may be difficult.\n\nIn addition, I'll mention that what you're doing is likely to cause you\na bunch of pain.  A Unix system is going to store different data in the\nindex from a Windows system, so when you do `git status` on one system\nafter having done it on the other, Git is going to re-read the entire\nworking tree, including re-hashing it, to fix the data in the index.\nThat's one of the reasons we don't recommend sharing a working tree\nbetween different OSes.\n\n[0] From https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html:\n\n    “The argument following the oflag argument does not affect whether the\n    file is open for reading, writing, or for both.”\n\n[1] There are a lot of instances where Git fails when the file system is\n    not POSIX compliant on Unix.  Notably, I believe chmod operations fail\n    under WSL for Windows partitions, so doing a `git init` under WSL on a\n    Windows mount tends to fail when it writes the config since the file\n    system isn't POSIX compliant.\n-- \nbrian m. carlson (they/them or he/him)\nToronto, Ontario, CA\n"}]}