cmd: MOVEing a file to itself is a no-op (try 2)
Frédéric Delanoy
frederic.delanoy at gmail.com
Thu Oct 20 03:32:50 CDT 2011
For directory files, this still gives errors (as windows does)
try 2: Add tests with different cases
---
programs/cmd/builtins.c | 7 +++++++
programs/cmd/tests/test_builtins.cmd | 8 ++++++++
programs/cmd/tests/test_builtins.cmd.exp | 6 ++++--
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 79e1ced..3f19fba 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1590,6 +1590,13 @@ void WCMD_move (void)
if (hff == INVALID_HANDLE_VALUE)
return;
+ /* Moving a file to itself is a no-op */
+ if (!lstrcmpiW(input, output)) {
+ DWORD attribs = GetFileAttributesW(input);
+ if (attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY))
+ return;
+ }
+
do {
WCHAR dest[MAX_PATH];
WCHAR src[MAX_PATH];
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index 02e264d..68a5493 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -986,6 +986,14 @@ if errorlevel 1 (
)
echo ErrorLevel: %ErrorLevel%
call :setError 0
+move /Y bAz baZ > nul 2>&1
+if errorlevel 1 (
+ echo moving a file to itself should be a no-op!
+) else (
+ echo moving a file to itself is a no-op
+)
+echo ErrorLevel: %ErrorLevel%
+call :setError 0
del baz
echo ... directory move ...
mkdir foo\bar
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 20e5d12..bcbfc68 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -616,8 +616,10 @@ file move succeeded
@todo_wine at bar@or_broken at baz
read-only files are moveable
file moved in subdirectory
- at todo_wine@moving a file to itself is a no-op at or_broken@moving a file to itself should be a no-op!
- at todo_wine@ErrorLevel: 0 at or_broken@ErrorLevel: 1
+moving a file to itself is a no-op at or_broken@moving a file to itself should be a no-op!
+ErrorLevel: 0 at or_broken@ErrorLevel: 1
+moving a file to itself is a no-op at or_broken@moving a file to itself should be a no-op!
+ErrorLevel: 0 at or_broken@ErrorLevel: 1
... directory move ...
simple directory move succeeded
moving a directory to itself gives error; errlevel 1
--
1.7.7
More information about the wine-patches
mailing list