From: Ramsay Jones <ramsay@ramsay1•demon.co.uk>
To: Michael Haggerty <mhagger@alum•mit.edu>,
Junio C Hamano <gitster@pobox•com>
Cc: git@vger•kernel.org
Subject: Re: [PATCH 4/5] safe_create_leading_directories(): fix a mkdir/rmdir race
Date: Sun, 22 Dec 2013 22:42:55 +0000 [thread overview]
Message-ID: <52B76AEF.70200@ramsay1.demon.co.uk> (raw)
In-Reply-To: <1387696451-32224-5-git-send-email-mhagger@alum.mit.edu>
On 22/12/13 07:14, Michael Haggerty wrote:
> It could be that some other process is trying to clean up empty
> directories at the same time that safe_create_leading_directories() is
> attempting to create them. In this case, it could happen that
> directory "a/b" was present at the end of one iteration of the loop
> (either it was already present or we just created it ourselves), but
> by the time we try to create directory "a/b/c", directory "a/b" has
> been deleted. In fact, directory "a" might also have been deleted.
>
> So, if a call to mkdir() fails with ENOENT, then try checking/making
> all directories again from the beginning. Attempt up to three times
> before giving up.
>
> Signed-off-by: Michael Haggerty <mhagger@alum•mit.edu>
> ---
> sha1_file.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/sha1_file.c b/sha1_file.c
> index dcfd35a..abcb56b 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -108,6 +108,7 @@ int mkdir_in_gitdir(const char *path)
> int safe_create_leading_directories(char *path)
> {
> char *next_component = path + offset_1st_component(path);
> + int attempts = 3;
> int retval = 0;
>
> while (!retval && next_component) {
> @@ -132,6 +133,16 @@ int safe_create_leading_directories(char *path)
> if (errno == EEXIST &&
> !stat(path, &st) && S_ISDIR(st.st_mode)) {
> ; /* somebody created it since we checked */
> + } else if (errno == ENOENT && --attempts) {
> + /*
> + * Either mkdir() failed bacause
s/bacause/because/
> + * somebody just pruned the containing
> + * directory, or stat() failed because
> + * the file that was in our way was
> + * just removed. Either way, try
> + * again from the beginning:
> + */
> + next_component = path + offset_1st_component(path);
> } else {
> retval = -1;
> }
>
ATB,
Ramsay Jones
next prev parent reply other threads:[~2013-12-22 22:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-22 7:14 [PATCH 0/5] Fix two mkdir/rmdir races Michael Haggerty
2013-12-22 7:14 ` [PATCH 1/5] safe_create_leading_directories(): modernize format of "if" chaining Michael Haggerty
2013-12-26 21:52 ` Jonathan Nieder
2013-12-22 7:14 ` [PATCH 2/5] safe_create_leading_directories(): reduce scope of local variable Michael Haggerty
2013-12-26 21:55 ` Jonathan Nieder
2014-01-01 12:39 ` Michael Haggerty
2013-12-22 7:14 ` [PATCH 3/5] safe_create_leading_directories(): add "slash" pointer Michael Haggerty
2013-12-26 22:34 ` Jonathan Nieder
2014-01-01 21:10 ` Michael Haggerty
2013-12-22 7:14 ` [PATCH 4/5] safe_create_leading_directories(): fix a mkdir/rmdir race Michael Haggerty
2013-12-22 22:42 ` Ramsay Jones [this message]
2013-12-26 23:02 ` Jonathan Nieder
2014-01-02 0:53 ` Michael Haggerty
2013-12-22 7:14 ` [PATCH 5/5] rename_ref(): fix a mkdir()/rmdir() race Michael Haggerty
2013-12-26 23:20 ` Jonathan Nieder
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=52B76AEF.70200@ramsay1.demon.co.uk \
--to=ramsay@ramsay1$(echo .)demon.co.uk \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=mhagger@alum$(echo .)mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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