[PATCH 1/2] cmd: Ensure mkdir returns an error for pre-existing directories (try 2)

Frédéric Delanoy frederic.delanoy at gmail.com
Mon Jun 20 11:53:36 CDT 2011


---
Failure only for the last path component and not for all of them

 programs/cmd/builtins.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 0352e59..a306740 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -482,6 +482,7 @@ void WCMD_copy (void) {
 static BOOL create_full_path(WCHAR* path)
 {
     int len;
+    int subpaths_count = 1, curr_path_level = 0;
     WCHAR *new_path;
     BOOL ret = TRUE;
 
@@ -489,14 +490,25 @@ static BOOL create_full_path(WCHAR* path)
     strcpyW(new_path,path);
 
     while ((len = strlenW(new_path)) && new_path[len - 1] == '\\')
+    {
         new_path[len - 1] = 0;
+        subpaths_count++;
+    }
 
     while (!CreateDirectoryW(new_path,NULL))
     {
         WCHAR *slash;
         DWORD last_error = GetLastError();
+        curr_path_level++;
         if (last_error == ERROR_ALREADY_EXISTS)
+        {
+            if (curr_path_level == subpaths_count)
+            {
+                errorlevel = 1;
+                ret = FALSE;
+            }
             break;
+        }
 
         if (last_error != ERROR_PATH_NOT_FOUND)
         {
-- 
1.7.5.4




More information about the wine-patches mailing list