~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_rename.c

MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
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
 
 
22
 
namespace drizzled
23
 
{
24
 
namespace internal
25
 
{
 
16
#include "mysys_priv.h"
 
17
#include <my_dir.h>
 
18
#include "mysys_err.h"
 
19
#include "m_string.h"
 
20
#undef my_rename
26
21
 
27
22
        /* On unix rename deletes to file if it exists */
28
23
 
29
24
int my_rename(const char *from, const char *to, myf MyFlags)
30
25
{
31
26
  int error = 0;
 
27
  DBUG_ENTER("my_rename");
 
28
  DBUG_PRINT("my",("from %s to %s MyFlags %d", from, to, MyFlags));
32
29
 
33
30
#if defined(HAVE_FILE_VERSIONS)
34
31
  {                             /* Check that there isn't a old file */
35
32
    int save_errno;
36
33
    MY_STAT my_stat_result;
37
 
    save_errno=errno;
 
34
    save_errno=my_errno;
38
35
    if (my_stat(to,&my_stat_result,MYF(0)))
39
36
    {
40
 
      errno=EEXIST;
 
37
      my_errno=EEXIST;
41
38
      error= -1;
42
39
      if (MyFlags & MY_FAE+MY_WME)
43
 
        my_error(EE_LINK, MYF(ME_BELL+ME_WAITTANG),from,to,errno);
44
 
      return(error);
 
40
        my_error(EE_LINK, MYF(ME_BELL+ME_WAITTANG),from,to,my_errno);
 
41
      DBUG_RETURN(error);
45
42
    }
46
 
    errno=save_errno;
 
43
    my_errno=save_errno;
47
44
  }
48
45
#endif
 
46
#if defined(HAVE_RENAME)
49
47
  if (rename(from,to))
 
48
#else
 
49
  if (link(from, to) || unlink(from))
 
50
#endif
50
51
  {
51
 
    errno=errno;
 
52
    my_errno=errno;
52
53
    error = -1;
53
54
    if (MyFlags & (MY_FAE+MY_WME))
54
 
      my_error(EE_LINK, MYF(ME_BELL+ME_WAITTANG),from,to,errno);
 
55
      my_error(EE_LINK, MYF(ME_BELL+ME_WAITTANG),from,to,my_errno);
55
56
  }
56
57
  else if (MyFlags & MY_SYNC_DIR)
57
58
  {
67
68
      error= -1;
68
69
#endif
69
70
  }
70
 
  return(error);
 
71
  DBUG_RETURN(error);
71
72
} /* my_rename */
72
 
 
73
 
} /* namespace internal */
74
 
} /* namespace drizzled */