1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
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.
|
|
6 |
||
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.
|
|
11 |
||
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 */
|
|
15 |
||
994.2.4
by Monty Taylor
Blast. Fixed some make distcheck issues. |
16 |
#include "mysys/mysys_priv.h" |
17 |
#include "mysys/mysys_err.h" |
|
212.5.18
by Monty Taylor
Moved m_ctype, m_string and my_bitmap. Removed t_ctype. |
18 |
#include <mystrings/m_string.h> |
1
by brian
clean slate |
19 |
#undef my_rename
|
20 |
||
21 |
/* On unix rename deletes to file if it exists */
|
|
22 |
||
23 |
int my_rename(const char *from, const char *to, myf MyFlags) |
|
24 |
{
|
|
25 |
int error = 0; |
|
26 |
||
27 |
#if defined(HAVE_FILE_VERSIONS)
|
|
28 |
{ /* Check that there isn't a old file */ |
|
29 |
int save_errno; |
|
30 |
MY_STAT my_stat_result; |
|
31 |
save_errno=my_errno; |
|
32 |
if (my_stat(to,&my_stat_result,MYF(0))) |
|
33 |
{
|
|
34 |
my_errno=EEXIST; |
|
35 |
error= -1; |
|
36 |
if (MyFlags & MY_FAE+MY_WME) |
|
37 |
my_error(EE_LINK, MYF(ME_BELL+ME_WAITTANG),from,to,my_errno); |
|
51.3.18
by Jay Pipes
Phase 5 - Remove DBUG from mysys |
38 |
return(error); |
1
by brian
clean slate |
39 |
}
|
40 |
my_errno=save_errno; |
|
41 |
}
|
|
42 |
#endif
|
|
43 |
#if defined(HAVE_RENAME)
|
|
44 |
if (rename(from,to)) |
|
45 |
#else
|
|
46 |
if (link(from, to) || unlink(from)) |
|
47 |
#endif
|
|
48 |
{
|
|
49 |
my_errno=errno; |
|
50 |
error = -1; |
|
51 |
if (MyFlags & (MY_FAE+MY_WME)) |
|
52 |
my_error(EE_LINK, MYF(ME_BELL+ME_WAITTANG),from,to,my_errno); |
|
53 |
}
|
|
54 |
else if (MyFlags & MY_SYNC_DIR) |
|
55 |
{
|
|
56 |
#ifdef NEED_EXPLICIT_SYNC_DIR
|
|
57 |
/* do only the needed amount of syncs: */
|
|
58 |
char dir_from[FN_REFLEN], dir_to[FN_REFLEN]; |
|
59 |
size_t dir_from_length, dir_to_length; |
|
60 |
dirname_part(dir_from, from, &dir_from_length); |
|
61 |
dirname_part(dir_to, to, &dir_to_length); |
|
62 |
if (my_sync_dir(dir_from, MyFlags) || |
|
63 |
(strcmp(dir_from, dir_to) && |
|
64 |
my_sync_dir(dir_to, MyFlags))) |
|
65 |
error= -1; |
|
66 |
#endif
|
|
67 |
}
|
|
51.3.18
by Jay Pipes
Phase 5 - Remove DBUG from mysys |
68 |
return(error); |
1
by brian
clean slate |
69 |
} /* my_rename */ |