From: Lokesh Poovaragan <lokesh.poovaragan@gmail.com> When 'move file' is called without a destination, the destination defaults to the current directory, causing source and destination paths to resolve to the same file. This led to an overwrite prompt or, in batch mode, a failed MoveFileExW call. Compare the fully-resolved source and destination case-insensitively and skip the move operation when they are identical. Signed-off-by: Lokesh Poovaragan <lokesh.poovaragan@gmail.com> --- programs/cmd/builtins.c | 4 ++++ programs/cmd/tests/test_builtins.bat.exp | 6 +++--- programs/cmd/tests/test_builtins.cmd.exp | 10 +++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index b706feb39c7..9f98b205065 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -1910,6 +1910,10 @@ RETURN_CODE WCMD_move(void) WINE_TRACE("Source '%s'\n", wine_dbgstr_w(src)); WINE_TRACE("Dest '%s'\n", wine_dbgstr_w(dest)); + /* If source and destination are the same file, skip (no-op) */ + if (!lstrcmpiW(src, dest)) + continue; + /* If destination exists, prompt unless /Y supplied */ if (GetFileAttributesW(dest) != INVALID_FILE_ATTRIBUTES) { BOOL force = FALSE; diff --git a/programs/cmd/tests/test_builtins.bat.exp b/programs/cmd/tests/test_builtins.bat.exp index d4c400fc65e..f900a5813ba 100644 --- a/programs/cmd/tests/test_builtins.bat.exp +++ b/programs/cmd/tests/test_builtins.bat.exp @@ -93,11 +93,11 @@ SUCCESS 0 a@space@ --- success/failure for MOVE command FAILURE 1 -@todo_wine@SUCCESS 0 +SUCCESS 0 ok -@todo_wine@SUCCESS 0 +SUCCESS 0 ok -@todo_wine@SUCCESS 0 +SUCCESS 0 ok SUCCESS 0 FAILURE 1 diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index 911ef0791b1..daa79804126 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -612,11 +612,11 @@ SUCCESS 0 a@space@ --- success/failure for MOVE command FAILURE 1 -@todo_wine@SUCCESS 0 +SUCCESS 0 ok -@todo_wine@SUCCESS 0 +SUCCESS 0 ok -@todo_wine@SUCCESS 0 +SUCCESS 0 ok SUCCESS 0 FAILURE 1 @@ -1826,8 +1826,8 @@ file move with overwrite succeeded@or_broken@file overwrite impossible! bar@or_broken@baz read-only files are moveable file moved in subdirectory -moving a file to itself is a no-op@or_broken@moving a file to itself should be a no-op! -ErrorLevel: 0@or_broken@ErrorLevel: 1 +moving a file to itself is a no-op +ErrorLevel: 0 --- directory move simple directory move succeeded moving a directory to itself gives error; errlevel 1 -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11529