Prevent race condition with mkdir in distutils.  Patch by Arfrever on #9281.
diff --git a/Lib/distutils/dir_util.py b/Lib/distutils/dir_util.py
index 54376e5..c7c9fcc 100644
--- a/Lib/distutils/dir_util.py
+++ b/Lib/distutils/dir_util.py
@@ -69,10 +69,11 @@
         if not dry_run:
             try:
                 os.mkdir(head, mode)
-                created_dirs.append(head)
             except OSError as exc:
-                raise DistutilsFileError(
-                      "could not create '%s': %s" % (head, exc.args[-1]))
+                if not (exc.errno == errno.EEXIST and os.path.isdir(head)):
+                    raise DistutilsFileError(
+                          "could not create '%s': %s" % (head, exc.args[-1]))
+            created_dirs.append(head)
 
         _path_created[abs_head] = 1
     return created_dirs