1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "mysys_priv.h"
18
#include "mysys_err.h"
22
/* On unix rename deletes to file if it exists */
24
int my_rename(const char *from, const char *to, myf MyFlags)
27
DBUG_ENTER("my_rename");
28
DBUG_PRINT("my",("from %s to %s MyFlags %d", from, to, MyFlags));
30
#if defined(HAVE_FILE_VERSIONS)
31
{ /* Check that there isn't a old file */
33
MY_STAT my_stat_result;
35
if (my_stat(to,&my_stat_result,MYF(0)))
39
if (MyFlags & MY_FAE+MY_WME)
40
my_error(EE_LINK, MYF(ME_BELL+ME_WAITTANG),from,to,my_errno);
46
#if defined(HAVE_RENAME)
49
if (link(from, to) || unlink(from))
54
if (MyFlags & (MY_FAE+MY_WME))
55
my_error(EE_LINK, MYF(ME_BELL+ME_WAITTANG),from,to,my_errno);
57
else if (MyFlags & MY_SYNC_DIR)
59
#ifdef NEED_EXPLICIT_SYNC_DIR
60
/* do only the needed amount of syncs: */
61
char dir_from[FN_REFLEN], dir_to[FN_REFLEN];
62
size_t dir_from_length, dir_to_length;
63
dirname_part(dir_from, from, &dir_from_length);
64
dirname_part(dir_to, to, &dir_to_length);
65
if (my_sync_dir(dir_from, MyFlags) ||
66
(strcmp(dir_from, dir_to) &&
67
my_sync_dir(dir_to, MyFlags)))