git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: Robert Buck <buck.robert.j@gmail.com>,
	"git@vger.kernel.org List" <git@vger.kernel.org>,
	Chris Packham <judge.packham@gmail.com>
Subject: Re: [remote rejected] master -> master (n/a (unpacker error))
Date: Thu, 13 May 2010 08:56:19 -0500	[thread overview]
Message-ID: <20100513135619.GA16848@progeny.tock> (raw)
In-Reply-To: <m2r5lgaqdb.fsf@igel.home>

Andreas Schwab wrote:
> Jonathan Nieder <jrnieder@gmail.com> writes:

>> In your case, all 16384 trials yielded the same result: file already
>> existed.
>
> IMHO it is much more likely that a race happened between two git
> processes each wanting to create the .git/objects/e6 directory.

Good catch.  But wasn’t the problem reproducible?

In any event, that such a race is possible is not so nice.  Here’s
a naïve fix; it does not address other races, such as hash-object
versus prune.  Maybe git ought to acquire some sort of lock before
writing to the object dir in a shared clone.

diff --git a/sha1_file.c b/sha1_file.c
index bbb819f..d305e53 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2244,6 +2244,13 @@ static inline int directory_size(const char *filename)
 	return s - filename + 1;
 }
 
+static int ensure_directory_exists(const char *dir)
+{
+	if (mkdir(dir, 0777) && errno != EEXIST)
+		return -1;
+	return adjust_shared_perm(dir);
+}
+
 /*
  * This creates a temporary file in the same directory as the final
  * 'filename'
@@ -2266,7 +2273,7 @@ static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)
 		/* Make sure the directory exists */
 		memcpy(buffer, filename, dirlen);
 		buffer[dirlen-1] = 0;
-		if (mkdir(buffer, 0777) || adjust_shared_perm(buffer))
+		if (ensure_directory_exists(buffer))
 			return -1;
 
 		/* Try again */
-- 

  reply	other threads:[~2010-05-13 13:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-12 19:45 [remote rejected] master -> master (n/a (unpacker error)) Robert Buck
2010-05-13  0:06 ` Chris Packham
2010-05-13  0:52 ` Jonathan Nieder
2010-05-13  9:30   ` Robert Buck
2010-05-13 12:05     ` Greg Troxel
2010-05-13 13:22   ` Andreas Schwab
2010-05-13 13:56     ` Jonathan Nieder [this message]
2015-11-27 21:37   ` DavidLeeCrites

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100513135619.GA16848@progeny.tock \
    --to=jrnieder@gmail.com \
    --cc=buck.robert.j@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=judge.packham@gmail.com \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).