bug 463411 - nsinstall.exe can race creating directories. r=timeless (sync js/src copy of nsinstall_win.c)
authorTed Mielczarek <ted.mielczarek@gmail.com>
Wed, 11 Nov 2009 08:24:30 -0500
changeset 34772 b00b441c641f8df8a5b50aa3f4b83a4348cf9b5a
parent 34771 dcfa9c3a23885c2db53b93686fcf08edab865a9c
child 34773 1ba9b887563a9196ae1f64da79155b0145186a57
child 36071 4badd9a1932fd39a7d56d16e7db0b8d4aec52fdb
push idunknown
push userunknown
push dateunknown
reviewerstimeless
bugs463411
milestone1.9.3a1pre
bug 463411 - nsinstall.exe can race creating directories. r=timeless (sync js/src copy of nsinstall_win.c)
js/src/config/nsinstall_win.c
--- a/js/src/config/nsinstall_win.c
+++ b/js/src/config/nsinstall_win.c
@@ -145,25 +145,28 @@ shellMkdir (wchar_t **pArgv)
                 *pTmpPath++ = *pArg++;
                 if ( *pArg == '\\' )
                     break;
             }
             *pTmpPath = '\0';
 
             /* 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;
             /* loop for next directory */
         }
 
         pArgv++;
     }