From ac6fe958a3efd45bfb3cc0f0013d257dd8e357df Mon Sep 17 00:00:00 2001
From: Ted Mielczarek <ted.mielczarek@gmail.com>
Date: Fri, 30 Oct 2009 13:00:20 -0400
Subject: [PATCH] bug 463411 - nsinstall.exe can race creating directories.
 r=timeless

---
 config/nsinstall_win.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/config/nsinstall_win.c b/config/nsinstall_win.c
index 4a0656364d37..d9b723b2c7c5 100644
--- a/config/nsinstall_win.c
+++ b/config/nsinstall_win.c
@@ -150,15 +150,18 @@ shellMkdir (wchar_t **pArgv)
 
             /* check if directory already exists */
             _wgetcwd ( path, _MAX_PATH );
-            if ( _wchdir ( tmpPath ) != -1 ) {
-                _wchdir ( path );
+            if ( _wchdir ( tmpPath ) == -1 &&
+                 _wmkdir ( tmpPath ) == -1 && // might have hit EEXIST
+                 _wchdir ( tmpPath ) == -1) { // so try again
+                char buf[2048];
+                _snprintf(buf, 2048, "Could not create the directory: %S",
+                          tmpPath);
+                perror ( buf );
+                retVal = 3;
+                break;
             } else {
-                if ( _wmkdir ( tmpPath ) == -1 ) {
-                    printf ( "%ls: ", tmpPath );
-                    perror ( "Could not create the directory" );
-                    retVal = 3;
-                    break;
-                }
+                // get back to the cwd
+                _wchdir ( path );
             }
             if ( *pArg == '\0' )      /* complete path? */
                 break;