summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Vojtovich <svoj@mariadb.org>2014-02-26 12:55:28 +0400
committerSergey Vojtovich <svoj@mariadb.org>2014-02-26 12:55:28 +0400
commit9d918f41d3910ed79bb71fd5405206b3a34c2a4b (patch)
treee63e69073fff27a9d90f3b15ef216378d34ef5a7
parent6efa5efa7dd112b6ac2efdd84235a13cca51c4d4 (diff)
downloadmariadb-git-9d918f41d3910ed79bb71fd5405206b3a34c2a4b.tar.gz
MDEV-5612 - my_rename() deletes files when it shouldn't
Ported fix for MySQL BUG#51861.
-rw-r--r--mysql-test/suite/csv/csv.result8
-rw-r--r--mysql-test/suite/csv/csv.test9
-rw-r--r--mysys/my_rename.c15
3 files changed, 24 insertions, 8 deletions
diff --git a/mysql-test/suite/csv/csv.result b/mysql-test/suite/csv/csv.result
index fc6aab530c7..8d497f52b31 100644
--- a/mysql-test/suite/csv/csv.result
+++ b/mysql-test/suite/csv/csv.result
@@ -5485,3 +5485,11 @@ SELECT * FROM t1;
ERROR HY000: Table 't1' is marked as crashed and should be repaired
DROP TABLE t1;
End of 5.1 tests
+#
+# MDEV-5612 - my_rename() deletes files when it shouldn't
+#
+CREATE TABLE t1(a INT NOT NULL) ENGINE=CSV;
+RENAME TABLE t1 TO t2;
+SELECT * FROM t2;
+a
+DROP TABLE t2;
diff --git a/mysql-test/suite/csv/csv.test b/mysql-test/suite/csv/csv.test
index 768a21912a2..90617d06599 100644
--- a/mysql-test/suite/csv/csv.test
+++ b/mysql-test/suite/csv/csv.test
@@ -1917,3 +1917,12 @@ SELECT * FROM t1;
DROP TABLE t1;
--echo End of 5.1 tests
+
+--echo #
+--echo # MDEV-5612 - my_rename() deletes files when it shouldn't
+--echo #
+CREATE TABLE t1(a INT NOT NULL) ENGINE=CSV;
+move_file $MYSQLD_DATADIR/test/t1.CSV $MYSQLD_DATADIR/test/t2.CSV;
+RENAME TABLE t1 TO t2;
+SELECT * FROM t2;
+DROP TABLE t2;
diff --git a/mysys/my_rename.c b/mysys/my_rename.c
index 8a9e6eb3dfd..09e7eafa980 100644
--- a/mysys/my_rename.c
+++ b/mysys/my_rename.c
@@ -27,19 +27,18 @@ int my_rename(const char *from, const char *to, myf MyFlags)
DBUG_ENTER("my_rename");
DBUG_PRINT("my",("from %s to %s MyFlags %lu", from, to, MyFlags));
-#if defined(HAVE_RENAME)
#if defined(__WIN__)
- /*
- On windows we can't rename over an existing file:
- Remove any conflicting files:
- */
- (void) my_delete(to, MYF(0));
-#endif
+ if (!MoveFileEx(from, to, MOVEFILE_COPY_ALLOWED |
+ MOVEFILE_REPLACE_EXISTING))
+ {
+ my_osmaperr(GetLastError());
+#elif defined(HAVE_RENAME)
if (rename(from,to))
+ {
#else
if (link(from, to) || unlink(from))
-#endif
{
+#endif
my_errno=errno;
error = -1;
if (MyFlags & (MY_FAE+MY_WME))