- Fix move for readonly folder and file. for now it is a small hack for readonly...
authorMagnus Olsen <magnus@greatlord.com>
Tue, 27 Sep 2005 21:49:18 +0000 (21:49 +0000)
committerMagnus Olsen <magnus@greatlord.com>
Tue, 27 Sep 2005 21:49:18 +0000 (21:49 +0000)
svn path=/trunk/; revision=18130

reactos/lib/kernel32/file/move.c

index 4b9d70c..d7f0136 100644 (file)
 /* GLOBALS *****************************************************************/
 
 /* FUNCTIONS ****************************************************************/
+static BOOL
+RemoveReadOnlyAttributeW(IN LPCWSTR lpFileName)
+{
+    DWORD Attributes;
+    Attributes = GetFileAttributesW(lpFileName);
+    if (Attributes != INVALID_FILE_ATTRIBUTES)
+    {  
+        return SetFileAttributesW(lpFileName,Attributes - 
+                                             (Attributes & ~FILE_ATTRIBUTE_READONLY));
+    }
+    return FALSE;
+}
 
 static BOOL
 AdjustFileAttributes (
@@ -478,26 +491,15 @@ MoveFileWithProgressW (
                         {  
                           FindClose(hFile);                         
 
-                                  /* delete folder */  
-
-                                  size = GetFullPathNameW(lpExistingFileName2, MAX_PATH,(LPWSTR) lpDeleteFile, NULL);
-                                  if (size>MAX_PATH)
-                                  {                  
-                                    lpDeleteFile = (LPCWSTR) HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY, 
-                                                   (VOID *) lpDeleteFile,size);
+                                  /* delete folder */                                                                   
+                                  DPRINT("MoveFileWithProgressW : folder : %s\n",lpDeleteFile);
 
-                                        if (lpDeleteFile == NULL)
-                                        {
-                                                Result = FALSE;
-                                    goto FreeMemAndExit;
-                                        }
 
-                                    GetFullPathNameW(lpExistingFileName2, size,(LPWSTR) lpDeleteFile, NULL);
-                                  }
-                                
-                                  DPRINT("MoveFileWithProgressW : folder : %s\n",lpDeleteFile);
+                                  Result = RemoveReadOnlyAttributeW(lpExistingFileName2);
+                                  if (Result == FALSE)
+                                      break;
 
-                                  Result = RemoveDirectoryW(lpDeleteFile);
+                                  Result = RemoveDirectoryW(lpExistingFileName2);
                                   if (Result == FALSE)
                                       break;
                                                                 
@@ -547,7 +549,18 @@ MoveFileWithProgressW (
                                 }
                   }
 
-                  wcscpy( (WCHAR *)&lpExistingFileName2[size2-3],findBuffer.cFileName);
+                   wcscpy( (WCHAR *)&lpExistingFileName2[size2-3],findBuffer.cFileName);
+
+                          
+                          /* FIXME 
+                           * RemoveReadOnlyAttributeW(lpExistingFileName2); is a hack 
+                               * for to move readonly folders 
+                               */
+                wcscpy( (WCHAR *)&lpExistingFileName2[size2+size-3],L"\0");
+                           RemoveReadOnlyAttributeW(lpExistingFileName2);
+
+
+                          /* Continue */
                   wcscpy( (WCHAR *)&lpExistingFileName2[size2+size-3],L"\\*.*\0");
           
                  
@@ -651,6 +664,10 @@ MoveFileWithProgressW (
                DPRINT("MoveFileWithProgressW : Delete file : %S : %S\n",lpDeleteFile, lpNewFileName2);
                  
            
+                          Result = RemoveReadOnlyAttributeW(lpDeleteFile);
+                          if (Result == FALSE)
+                              break;
+
                Result = DeleteFileW(lpDeleteFile);
                if (Result == FALSE)
                {