Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15

Re: [PATCH] safe_create_leading_directories: fix race that could give a false negative

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:56:25

Possibly related (same subject, not in this thread)

Steven Walter [off-list ref] writes:
If two processes are racing to create the same directory tree, they will
both see that the directory doesn't exist, both try to mkdir(), and one
of them will fail.  This is okay, as we only care that the directory
gets created.  So, we add a check for EEXIST from mkdir, and continue if
the directory now exists.
---
Thanks.  Please sign-off your patch.
quoted hunk
 sha1_file.c |    7 +++++++
 1 file changed, 7 insertions(+)
diff --git a/sha1_file.c b/sha1_file.c
index 40b2329..c7b7fec 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -123,6 +123,13 @@ int safe_create_leading_directories(char *path)
 			}
 		}
 		else if (mkdir(path, 0777)) {
+			if (errno == EEXIST) {
+				/* We could be racing with another process to
+				 * create the directory.  As long as the
+				 * directory gets created, we don't care. */
+				if (stat(path, &st) && S_ISDIR(st.st_mode))
+					continue;
	/*
         * Nice explanation, but we try to format our
         * multi-line comments like this, slash-asterisk
         * and nothing else on the opening line, and
         * asterisk-slash and nothing else on the closing
         * line.
         */

Thanks.
+			}
 			*pos = '/';
 			return -1;
 		}
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help