~drizzle-trunk/drizzle/development

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