[PATCH 1/3] [cmd] move issues when overwriting files
Ann and Jason Edmeades
jason at edmeades.me.uk
Wed Sep 5 18:31:35 CDT 2012
If source is the same as the destination, e.g. when a file is
supplied as the source with no parms, the file gets deleted.
Similarly even if /y is used to force it, the move does not
occur.
[BUG 28582]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20120906/08aa1bcf/attachment.html>
-------------- next part --------------
From 39514e97a3abbedd002849956d285124ff6e8a30 Mon Sep 17 00:00:00 2001
From: Jason Edmeades <jason at edmeades.me.uk>
Date: Wed, 5 Sep 2012 23:27:34 +0100
Subject: [PATCH 1/3] [cmd] move issues when overwriting files
If source is the same as the destination, e.g. when a file is
supplied as the source with no parms, the file gets deleted.
Similarly even if /y is used to force it, the move does not
occur.
[BUG 28582]
---
programs/cmd/builtins.c | 23 ++++++++++++++---------
programs/cmd/tests/test_builtins.cmd.exp | 8 ++++----
2 files changed, 18 insertions(+), 13 deletions(-)
mode change 100644 => 100755 programs/cmd/builtins.c
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
old mode 100644
new mode 100755
index b2f9aeb..abfac45
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1709,8 +1709,13 @@ void WCMD_move (void)
WINE_TRACE("Source '%s'\n", wine_dbgstr_w(src));
WINE_TRACE("Dest '%s'\n", wine_dbgstr_w(dest));
- /* If destination exists, prompt unless /Y supplied */
- if (GetFileAttributesW(dest) != INVALID_FILE_ATTRIBUTES) {
+ /* If we have src == dest, skip moving this one */
+ if (strcmpW(src,dest)==0) ok = FALSE;
+
+ /* As long as we need to do something, if destination exists
+ prompt (unless /Y supplied) */
+ if (ok &&
+ GetFileAttributesW(dest) != INVALID_FILE_ATTRIBUTES) {
BOOL force = FALSE;
WCHAR copycmd[MAXSTRING];
DWORD len;
@@ -1735,14 +1740,14 @@ void WCMD_move (void)
question = WCMD_format_string(WCMD_LoadMessage(WCMD_OVERWRITE), dest);
ok = WCMD_ask_confirm(question, FALSE, NULL);
LocalFree(question);
+ }
- /* So delete the destination prior to the move */
- if (ok) {
- if (!DeleteFileW(dest)) {
- WCMD_print_error ();
- errorlevel = 1;
- ok = FALSE;
- }
+ /* So unless we decided not to overwrite, delete the destination first */
+ if (ok) {
+ if (!DeleteFileW(dest)) {
+ WCMD_print_error ();
+ errorlevel = 1;
+ ok = FALSE;
}
}
}
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index fe4c30c..c120ae7 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -637,12 +637,12 @@ original file still present
------------ Testing move ------------
--- file move
file move succeeded
- at todo_wine@file move with overwrite succeeded at or_broken@file overwrite impossible!
- at todo_wine@bar at or_broken@baz
+file move with overwrite succeeded at or_broken@file overwrite impossible!
+bar at or_broken@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
--- directory move
simple directory move succeeded
moving a directory to itself gives error; errlevel 1
--
1.7.5.4
More information about the wine-patches
mailing list