git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Problem pushing to a Novell share

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 2, 2012, 23:45 UTC
Message-ID
<7vmx90vlyr.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CAJ4nRM0-3GWN=OYOXDdGtktU0mc8mhcoKqbo=U4Jm5AmSbPAyQ@mail.gmail.com>
Rüdiger Kessel <ruediger.kessel@gmail.com> writes:
Show 27 quoted lines
> A quick fix is to improve the create_tmpfile() function in sha1_file.c:
>
> static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)
> {
>     static struct stat sb;
>     int fd, dirlen = directory_size(filename);
>
>     if (dirlen + 20 > bufsiz) {
>         errno = ENAMETOOLONG;
>         return -1;
>     }
>
>     memcpy(buffer, filename, dirlen);
>     buffer[dirlen-1] = 0;
>     if (stat(buffer, &sb) != 0 && errno == ENOENT) {
>         if (mkdir(buffer, 0777) || adjust_shared_perm(buffer))
>             return -1;
>     }
>
>     memcpy(buffer, filename, dirlen);
>     strcpy(buffer + dirlen, "tmp_obj_XXXXXX");
>     fd = git_mkstemp_mode(buffer, 0444);
>     return fd;
> }
>
> The function will create one missing directory level if it does not
> exist prior to creating the tmp-file.

Please remove your modification above, and follow the code we have. We try git_mkstemp_mode() first, because it is more common than not having the leading directory and we do not want to waste an extra stat() every tie we come here. Only when the first attempt fails by returning error (i.e. fd < 0 and errno == ENOENT), we try mkdir() and then try again.

If you see "missing directory", it would be because on your system the code somehow does not notice the failure from the first attempt. Why?

The breakage you are seeing could come from either:
 - git_mkstemp_mode(), more specifically, the underlying mkstemp(), not
   returning negative when it fails for some reason; or
 - when the above fails, it fails to set errno to ENOENT.
and *that* is what needs to be fixed.

I think pessimizing create_tmpfile() like you did is not a fix; it is sweeping the real problem under the rug.

Previous: Rüdiger KesselNext: Junio C Hamano
Message 2 of 4 in “Problem pushing to a Novell share”
  1. Rüdiger KesselFeb 2, 2012
  2. Junio C HamanoFeb 2, 2012
  3. Junio C HamanoFeb 3, 2012
  4. Junio C HamanoFeb 3, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.