Forráskód Böngészése

Return STATUS_DIRECTORY_NOT_EMPTY when trying to delete a folder that is not empty

Tal Aloni 8 éve
szülő
commit
bb0cff643a

+ 1 - 0
SMBLibrary/Enums/NTStatus.cs

@@ -32,6 +32,7 @@ namespace SMBLibrary
         STATUS_NOT_SUPPORTED = 0xC00000BB,
         STATUS_NETWORK_NAME_DELETED = 0xC00000C9,
         STATUS_TOO_MANY_SESSIONS = 0xC00000CE,
+        STATUS_DIRECTORY_NOT_EMPTY = 0xC0000101,
         STATUS_TOO_MANY_OPENED_FILES = 0xC000011F,
         STATUS_CANNOT_DELETE = 0xC0000121,
         STATUS_FILE_CLOSED = 0xC0000128,

+ 1 - 0
SMBLibrary/Enums/Win32Error.cs

@@ -8,6 +8,7 @@ namespace SMBLibrary
         ERROR_ACCESS_DENIED = 0x0005,
         ERROR_SHARING_VIOLATION = 0x0020,
         ERROR_DISK_FULL = 0x0070,
+        ERROR_DIR_NOT_EMPTY = 0x0091,
         ERROR_ALREADY_EXISTS = 0x00B7,
         ERROR_LOGON_FAILURE = 0x052E,
         ERROR_ACCOUNT_RESTRICTION = 0x052F,

+ 6 - 0
SMBLibrary/Server/Helpers/NTFileSystemHelper.cs

@@ -382,6 +382,12 @@ namespace SMBLibrary.Server
                 {
                     return NTStatus.STATUS_DISK_FULL;
                 }
+                else if (errorCode == (ushort)Win32Error.ERROR_DIR_NOT_EMPTY)
+                {
+                    // If a user tries to rename folder1 to folder2 when folder2 already exists, Windows 7 will offer to merge folder1 into folder2.
+                    // In such case, Windows 7 will delete folder 1 and will expect STATUS_DIRECTORY_NOT_EMPTY if there are files to merge.
+                    return NTStatus.STATUS_DIRECTORY_NOT_EMPTY;
+                }
                 else if (errorCode == (ushort)Win32Error.ERROR_ALREADY_EXISTS)
                 {
                     // According to [MS-FSCC], FileRenameInformation MUST return STATUS_OBJECT_NAME_COLLISION when the specified name already exists and ReplaceIfExists is zero.

+ 1 - 1
SMBServer/DirectoryFileSystem/DirectoryFileSystem.cs

@@ -100,7 +100,7 @@ namespace SMBServer
             }
             else if (Directory.Exists(fullPath))
             {
-                Directory.Delete(fullPath, true);
+                Directory.Delete(fullPath, false);
             }
             else
             {