{"thread":{"id":"16414","subject":"[PATCH] sha1_file: avoid bogus \"file exists\" error message","startedAt":"2008-11-20T18:56:28Z","lastAt":"2008-11-28T17:00:15Z","messageCount":4,"participants":["Joey Hess","Ian Hilt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"96280","messageId":"20081120185628.GA25604@kodama.kitenet.net","threadId":"16414","inReplyTo":null,"subject":"[PATCH] sha1_file: avoid bogus \"file exists\" error message","fromName":"Joey Hess","fromEmail":"joey@kitenet.net","sentAt":"2008-11-20T18:56:28Z","receivedAt":"2008-11-20T18:56:28Z","isPatch":true,"sender":{"key":"joey@kitenet.net","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"This avoids the following misleading error message:\n\nerror: unable to create temporary sha1 filename ./objects/15: File exists\n\nmkstemp can fail for many reasons, one of which, ENOENT, can occur if\nthe directory for the temp file doesn't exist. create_tmpfile tried to\nhandle this case by always trying to mkdir the directory, even if it\nalready existed. This caused errno to be clobbered, so one cannot tell\nwhy mkstemp really failed, and it truncated the buffer to just the\ndirectory name, resulting in the strange error message shown above.\n\nNote that in both occasions that I've seen this failure, it has not been\ndue to a missing directory, or bad permissions, but some other, unknown\nmkstemp failure mode that did not occur when I ran git again. This code\ncould perhaps be made more robust by retrying mkstemp, in case it was a\ntransient failure.\n\nSigned-off-by: Joey Hess <joey@kitenet.net>\n---\n sha1_file.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex ab2b520..927fb64 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2231,7 +2231,7 @@ static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)\n \tmemcpy(buffer, filename, dirlen);\n \tstrcpy(buffer + dirlen, \"tmp_obj_XXXXXX\");\n \tfd = mkstemp(buffer);\n-\tif (fd < 0 && dirlen) {\n+\tif (fd < 0 && dirlen && errno == ENOENT) {\n \t\t/* Make sure the directory exists */\n \t\tmemcpy(buffer, filename, dirlen);\n \t\tbuffer[dirlen-1] = 0;\n-- \n1.5.6.5\n"},{"id":"96566","messageId":"20081126181928.GA31007@kodama.kitenet.net","threadId":"16414","inReplyTo":"20081120185628.GA25604@kodama.kitenet.net","subject":"Re: [PATCH] sha1_file: avoid bogus \"file exists\" error message","fromName":"Joey Hess","fromEmail":"joey@kitenet.net","sentAt":"2008-11-26T18:19:28Z","receivedAt":"2008-11-26T18:19:28Z","isPatch":true,"sender":{"key":"joey@kitenet.net","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"Joey Hess wrote:\n> Note that in both occasions that I've seen this failure, it has not been\n> due to a missing directory, or bad permissions\n\nActually, it was due to bad permissions. :-) Once git was fixed to\nactually say that, I figured out where to look to fix them.\n\n-- \nsee shy jo\n"},{"id":"96628","messageId":"alpine.LFD.2.00.0811271233590.2883@sys-0.hiltweb.site","threadId":"16414","inReplyTo":"20081126181928.GA31007@kodama.kitenet.net","subject":"Re: [PATCH] sha1_file: avoid bogus \"file exists\" error message","fromName":"Ian Hilt","fromEmail":"ian.hilt@gmx.com","sentAt":"2008-11-27T17:41:18Z","receivedAt":"2008-11-27T17:41:18Z","isPatch":true,"sender":{"key":"ian.hilt@gmx.com","avatar":null},"body":"On Wed, 26 Nov 2008, Joey Hess wrote:\n> Joey Hess wrote:\n> > Note that in both occasions that I've seen this failure, it has not been\n> > due to a missing directory, or bad permissions\n> \n> Actually, it was due to bad permissions. :-) Once git was fixed to\n> actually say that, I figured out where to look to fix them.\n\nThis is strange since write_loose_object() which calls create_tmpfile()\nchecks for EPERM.  Perhaps this should be done in create_tmpfile()?\n"},{"id":"96689","messageId":"20081128170015.GA9744@kodama.kitenet.net","threadId":"16414","inReplyTo":"alpine.LFD.2.00.0811271233590.2883@sys-0.hiltweb.site","subject":"Re: [PATCH] sha1_file: avoid bogus \"file exists\" error message","fromName":"Joey Hess","fromEmail":"joey@kitenet.net","sentAt":"2008-11-28T17:00:15Z","receivedAt":"2008-11-28T17:00:15Z","isPatch":true,"sender":{"key":"joey@kitenet.net","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"Ian Hilt wrote:\n> On Wed, 26 Nov 2008, Joey Hess wrote:\n> > Joey Hess wrote:\n> > > Note that in both occasions that I've seen this failure, it has not been\n> > > due to a missing directory, or bad permissions\n> > \n> > Actually, it was due to bad permissions. :-) Once git was fixed to\n> > actually say that, I figured out where to look to fix them.\n> \n> This is strange since write_loose_object() which calls create_tmpfile()\n> checks for EPERM.  Perhaps this should be done in create_tmpfile()?\n\nerrno is clobbered by the mkdir in create_tmpfile(), that's what my patch\ncorrects.\n\nI suspect that in my case, mkstemp failed with EACCES, not EPERM. git\nwas running as a group that did not have write access to (some) object\ndirectories.\n\n-- \nsee shy jo\n"}]}