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

Re: [PATCH v2] sha1_file.c:create_tmpfile(): Fix race when creating loose object dirs

From
Jeff King <peff@peff.net>
Date
Oct 30, 2013, 09:30 UTC
Message-ID
<20131030093017.GA12125@sigill.intra.peff.net>
In-Reply-To
<20131030091927.GQ11317@sigill.intra.peff.net>
On Wed, Oct 30, 2013 at 05:19:27AM -0400, Jeff King wrote:
Show 14 quoted lines
> > To achieve this, I guess we have to follow the same procedure we do for
> > loose object creation:
> > 
> >  1. Create a temporary directory with a unique name (mkdtemp?)
> > 
> >  2. Adjust permissions
> > 
> >  3. Rename into place
> > 
> > Can this be done sufficiently atomically across all platforms?
> 
> Yeah, I think that is the only way to do it. I do not know offhand of
> any platforms that have problems with atomic directory renames, though I
> would not be surprised if some network filesystems don't handle it well.

Actually, thinking on this more, we do not want "rename into place" semantics, as that usually implies overwrite. We would prefer a hard-link solution, where only one linker "wins", and the other gets EEXIST. But you cannot hard-link directories.

POSIX does specify that rename() should return EEXIST rather than overwriting if the destination directory exists and is not empty. So in theory that would work, as we would then just be racing against the other process creating the actual object (and either we replace the directory with ours before they write the object, or they write the object first and we get EEXIST).

But I don't know how well that is followed in the real world.
-Peff
Previous: Jeff King
Message 3 of 3 in “sha1_file.c:create_tmpfile(): Fix race when creating loose object dirs”
  1. sha1_file.c:create_tmpfile(): Fix race when creating loose object dirsJohan Herland, Oct 27, 2013
  2. Jeff KingOct 30, 2013
  3. Jeff KingOct 30, 2013

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.