[PATCH v3 6/7] scrrun: Move source dir into destination dir if destination ends with separator in MoveFolder().

Robert Wilhelm wine at gitlab.winehq.org
Thu Jul 7 07:27:41 CDT 2022


From: Robert Wilhelm <robert.wilhelm at gmx.net>

Signed-off-by: Robert Wilhelm <robert.wilhelm at gmx.net>
---
 dlls/scrrun/filesystem.c       | 17 +++++++++++++++
 dlls/scrrun/tests/filesystem.c | 38 +++++++++++++++++++++++++++++++++-
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c
index 6ffebc0af12..44ead49714e 100644
--- a/dlls/scrrun/filesystem.c
+++ b/dlls/scrrun/filesystem.c
@@ -29,6 +29,7 @@
 #include "olectl.h"
 #include "dispex.h"
 #include "ntsecapi.h"
+#include "shlwapi.h"
 #include "scrrun.h"
 #include "scrrun_private.h"
 
@@ -3767,6 +3768,9 @@ static HRESULT WINAPI filesys_MoveFile(IFileSystem3 *iface, BSTR source, BSTR de
 static HRESULT WINAPI filesys_MoveFolder(IFileSystem3 *iface, BSTR source, BSTR destination)
 {
     DWORD attrs;
+    int len;
+    WCHAR src_drive[MAX_PATH],src_dir[MAX_PATH],dst_path[MAX_PATH],
+          file_name[MAX_PATH],file_ext[MAX_PATH];
 
     TRACE("%p %s %s\n", iface, debugstr_w(source), debugstr_w(destination));
 
@@ -3777,6 +3781,19 @@ static HRESULT WINAPI filesys_MoveFolder(IFileSystem3 *iface, BSTR source, BSTR
     if((attrs == INVALID_FILE_ATTRIBUTES) || !(attrs & FILE_ATTRIBUTE_DIRECTORY))
         return CTL_E_PATHNOTFOUND;
 
+    _wsplitpath(source, src_drive, src_dir, file_name, file_ext);
+    len = lstrlenW(destination);
+
+    if (destination[len-1] == '\\' || destination[len-1] == '/') {
+        lstrcpyW(dst_path, destination);
+        lstrcatW(dst_path, file_name);
+        if (*file_ext) {
+            lstrcatW(dst_path, L".");
+            lstrcatW(dst_path, file_ext);
+        }
+        TRACE("move %s to %s\n",  debugstr_w(source), debugstr_w(dst_path));
+        return MoveFileW(source, dst_path) ? S_OK : create_error(GetLastError());
+    }
     return MoveFileW(source, destination) ? S_OK : create_error(GetLastError());
 }
 
diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c
index 4d144937840..3876598518a 100644
--- a/dlls/scrrun/tests/filesystem.c
+++ b/dlls/scrrun/tests/filesystem.c
@@ -2603,7 +2603,7 @@ static void test_MoveFile(void)
 static void test_MoveFolder(void)
 {
     BSTR src, dst, str;
-    WCHAR buffW1[MAX_PATH],buffW2[MAX_PATH];
+    WCHAR buffW1[MAX_PATH],buffW2[MAX_PATH],pathW[MAX_PATH];
     HRESULT hr;
     File *file;
 
@@ -2656,6 +2656,42 @@ static void test_MoveFolder(void)
     SysFreeString(src);
     SysFreeString(dst);
     DeleteFileW(buffW1);
+
+    GetTempPathW(MAX_PATH, buffW1);
+    lstrcatW(buffW1,L"foo");
+    GetTempPathW(MAX_PATH, buffW2);
+    lstrcatW(buffW2,L"bar");
+    ok(CreateDirectoryW(buffW1, NULL), "CreateDirectory(%s) failed\n", wine_dbgstr_w(buffW1));
+    ok(CreateDirectoryW(buffW2, NULL), "CreateDirectory(%s) failed\n", wine_dbgstr_w(buffW2));
+    lstrcpyW(pathW,buffW2);
+    lstrcatW(pathW,L"\\");
+    src = SysAllocString(buffW1);
+    dst = SysAllocString(pathW);
+    hr = IFileSystem3_MoveFolder(fs3, src, dst);
+    ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
+    SysFreeString(src);
+    SysFreeString(dst);
+    lstrcatW(pathW,L"foo");
+    ok(RemoveDirectoryW(pathW), "can't remove %s directory\n", wine_dbgstr_w(pathW));
+    ok(RemoveDirectoryW(buffW2), "can't remove %s directory\n", wine_dbgstr_w(buffW2));
+
+    GetTempPathW(MAX_PATH, buffW1);
+    lstrcatW(buffW1,L"foo");
+    GetTempPathW(MAX_PATH, buffW2);
+    lstrcatW(buffW2,L"bar");
+    ok(CreateDirectoryW(buffW1, NULL), "CreateDirectory(%s) failed\n", wine_dbgstr_w(buffW1));
+    ok(CreateDirectoryW(buffW2, NULL), "CreateDirectory(%s) failed\n", wine_dbgstr_w(buffW2));
+    lstrcpyW(pathW,buffW2);
+    lstrcatW(pathW,L"/");
+    src = SysAllocString(buffW1);
+    dst = SysAllocString(pathW);
+    hr = IFileSystem3_MoveFolder(fs3, src, dst);
+    ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
+    SysFreeString(src);
+    SysFreeString(dst);
+    lstrcatW(pathW,L"foo");
+    ok(RemoveDirectoryW(pathW), "can't remove %s directory\n", wine_dbgstr_w(pathW));
+    ok(RemoveDirectoryW(buffW2), "can't remove %s directory\n", wine_dbgstr_w(buffW2));
 }
 
 static void test_DoOpenPipeStream(void)
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/391



More information about the wine-devel mailing list