From 9d918f41d3910ed79bb71fd5405206b3a34c2a4b Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Wed, 26 Feb 2014 12:55:28 +0400 Subject: MDEV-5612 - my_rename() deletes files when it shouldn't Ported fix for MySQL BUG#51861. --- mysys/my_rename.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'mysys') 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)) -- cgit v1.2.1