drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
my_rename.cc
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
16#include <config.h>
17
18#include <drizzled/internal/my_sys.h>
19#include <drizzled/error.h>
20#include <drizzled/internal/m_string.h>
21
22namespace drizzled
23{
24namespace internal
25{
26
27 /* On unix rename deletes to file if it exists */
28
29int my_rename(const char *from, const char *to, myf MyFlags)
30{
31 int error = 0;
32
33#if defined(HAVE_FILE_VERSIONS)
34 { /* Check that there isn't a old file */
35 int save_errno;
36 MY_STAT my_stat_result;
37 save_errno=errno;
38 if (my_stat(to,&my_stat_result,MYF(0)))
39 {
40 errno=EEXIST;
41 error= -1;
42 if (MyFlags & MY_FAE+MY_WME)
43 my_error(EE_LINK, MYF(ME_BELL+ME_WAITTANG),from,to,errno);
44 return(error);
45 }
46 errno=save_errno;
47 }
48#endif
49 if (rename(from,to))
50 {
51 errno=errno;
52 error = -1;
53 if (MyFlags & (MY_FAE+MY_WME))
54 my_error(EE_LINK, MYF(ME_BELL+ME_WAITTANG),from,to,errno);
55 }
56 else if (MyFlags & MY_SYNC_DIR)
57 {
58#ifdef NEED_EXPLICIT_SYNC_DIR
59 /* do only the needed amount of syncs: */
60 char dir_from[FN_REFLEN], dir_to[FN_REFLEN];
61 size_t dir_from_length, dir_to_length;
62 dirname_part(dir_from, from, &dir_from_length);
63 dirname_part(dir_to, to, &dir_to_length);
64 if (my_sync_dir(dir_from, MyFlags) ||
65 (strcmp(dir_from, dir_to) &&
66 my_sync_dir(dir_to, MyFlags)))
67 error= -1;
68#endif
69 }
70 return(error);
71} /* my_rename */
72
73} /* namespace internal */
74} /* namespace drizzled */
TODO: Rename this file - func.h is stupid.