summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
Diffstat (limited to 'mysys')
-rw-r--r--mysys/Makefile.am1
-rw-r--r--mysys/errors.c8
-rw-r--r--mysys/getvar.c2
-rw-r--r--mysys/mf_brkhant.c6
-rw-r--r--mysys/mf_cache.c3
-rw-r--r--mysys/mf_format.c30
-rw-r--r--mysys/mf_pack.c7
-rw-r--r--mysys/mf_same.c15
-rw-r--r--mysys/my_alloc.c69
-rw-r--r--mysys/my_compress.c2
-rw-r--r--mysys/my_copy.c4
-rw-r--r--mysys/my_delete.c1
-rw-r--r--mysys/my_pread.c6
-rw-r--r--mysys/my_static.c1
-rw-r--r--mysys/my_symlink.c138
-rw-r--r--mysys/my_symlink2.c155
-rw-r--r--mysys/tree.c2
17 files changed, 367 insertions, 83 deletions
diff --git a/mysys/Makefile.am b/mysys/Makefile.am
index 5a7293bc680..6dd9bb06fe9 100644
--- a/mysys/Makefile.am
+++ b/mysys/Makefile.am
@@ -33,6 +33,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c\
my_alloc.c safemalloc.c my_fopen.c my_fstream.c \
my_error.c errors.c my_div.c my_messnc.c \
mf_format.c mf_same.c mf_dirname.c mf_fn_ext.c \
+ my_symlink.c my_symlink2.c \
mf_pack.c mf_pack2.c mf_unixpath.c mf_stripp.c \
mf_casecnv.c mf_soundex.c mf_wcomp.c mf_wfile.c \
mf_qsort.c mf_qsort2.c mf_sort.c \
diff --git a/mysys/errors.c b/mysys/errors.c
index 6e9f1fabab0..77e52c2f0b3 100644
--- a/mysys/errors.c
+++ b/mysys/errors.c
@@ -46,6 +46,9 @@ const char * NEAR globerrs[GLOBERRS]=
"Can't create directory '%s' (Errcode: %d)",
"Character set '%s' is not a compiled character set and is not specified in the '%s' file",
"Out of resources when opening file '%s' (Errcode: %d)",
+ "Can't read value for symlink '%s' (Error %d)",
+ "Can't create symlink '%s' pointing at '%s' (Error %d)",
+ "Error on realpath() on '%s' (Error %d)",
};
void init_glob_errs(void)
@@ -81,6 +84,9 @@ void init_glob_errs()
EE(EE_DISK_FULL) = "Disk is full writing '%s'. Waiting for someone to free space...";
EE(EE_CANT_MKDIR) ="Can't create directory '%s' (Errcode: %d)";
EE(EE_UNKNOWN_CHARSET)= "Character set is not a compiled character set and is not specified in the %s file";
- EE(EE_OUT_OF_FILERESOURCES)="Out of resources when opening file '%s' (Errcode: %d)",
+ EE(EE_OUT_OF_FILERESOURCES)="Out of resources when opening file '%s' (Errcode: %d)";
+ EE(EE_CANT_READLINK)="Can't read value for symlink '%s' (Error %d)";
+ EE(EE_CANT_SYMLINK)="Can't create symlink '%s' pointing at '%s' (Error %d)";
+ EE(EE_REALPATH)="Error on realpath() on '%s' (Error %d)";
}
#endif
diff --git a/mysys/getvar.c b/mysys/getvar.c
index e0f60b207b7..90ab599244d 100644
--- a/mysys/getvar.c
+++ b/mysys/getvar.c
@@ -101,7 +101,7 @@ my_bool set_changeable_var(my_string str,CHANGEABLE_VAR *vars)
}
if (num < (longlong) found->min_value)
num=(longlong) found->min_value;
- else if (num > (longlong) (ulong) found->max_value)
+ else if (num > 0 && (ulonglong) num > (ulonglong) (ulong) found->max_value)
num=(longlong) (ulong) found->max_value;
num=((num- (longlong) found->sub_size) / (ulonglong) found->block_size);
(*found->varptr)= (long) (num*(ulonglong) found->block_size);
diff --git a/mysys/mf_brkhant.c b/mysys/mf_brkhant.c
index 4e4bc2410f9..debf5d9a712 100644
--- a/mysys/mf_brkhant.c
+++ b/mysys/mf_brkhant.c
@@ -24,17 +24,15 @@
/* Set variable that we can't break */
+#if !defined(THREAD)
void dont_break(void)
{
-#if !defined(THREAD)
my_dont_interrupt=1;
-#endif
return;
} /* dont_break */
void allow_break(void)
{
-#if !defined(THREAD)
{
reg1 int index;
@@ -54,8 +52,8 @@ void allow_break(void)
_my_signals=0;
}
}
-#endif
} /* dont_break */
+#endif
/* Set old status */
diff --git a/mysys/mf_cache.c b/mysys/mf_cache.c
index ff29926ac50..4b8fc6fed17 100644
--- a/mysys/mf_cache.c
+++ b/mysys/mf_cache.c
@@ -28,7 +28,8 @@
this, just remember the file name for later removal
*/
-static my_bool cache_remove_open_tmp(IO_CACHE *cache, const char *name)
+static my_bool cache_remove_open_tmp(IO_CACHE *cache __attribute__((unused)),
+ const char *name)
{
#if O_TEMPORARY == 0
#if !defined(CANT_DELETE_OPEN_FILES)
diff --git a/mysys/mf_format.c b/mysys/mf_format.c
index c4425806e01..f90e646289f 100644
--- a/mysys/mf_format.c
+++ b/mysys/mf_format.c
@@ -17,10 +17,6 @@
#include "mysys_priv.h"
#include <m_string.h>
-#ifdef HAVE_REALPATH
-#include <sys/param.h>
-#include <sys/stat.h>
-#endif
/* format a filename with replace of library and extension */
/* params to and name may be identicall */
@@ -33,21 +29,12 @@
/* 32 Resolve filename to full path */
/* 64 Return NULL if too long path */
-#ifdef SCO
-#define BUFF_LEN 4097
-#else
-#ifdef MAXPATHLEN
-#define BUFF_LEN MAXPATHLEN
-#else
-#define BUFF_LEN FN_LEN
-#endif
-#endif
my_string fn_format(my_string to, const char *name, const char *dsk,
const char *form, int flag)
{
reg1 uint length;
- char dev[FN_REFLEN], buff[BUFF_LEN], *pos, *startpos;
+ char dev[FN_REFLEN], buff[FN_REFLEN], *pos, *startpos;
const char *ext;
DBUG_ENTER("fn_format");
DBUG_PRINT("enter",("name: %s dsk: %s form: %s flag: %d",
@@ -109,18 +96,13 @@ my_string fn_format(my_string to, const char *name, const char *dsk,
#endif
(void) strmov(pos,ext); /* Don't convert extension */
}
- /* Purify gives a lot of UMR errors when using realpath */
-#if defined(HAVE_REALPATH) && !defined(HAVE_purify) && !defined(HAVE_BROKEN_REALPATH)
- if (flag & 16)
+ if (flag & 32)
+ (void) my_realpath(to, to, MYF(flag & 32 ? 0 : MY_RESOLVE_LINK));
+ else if (flag & 16)
{
- struct stat stat_buff;
- if (flag & 32 || (!lstat(to,&stat_buff) && S_ISLNK(stat_buff.st_mode)))
- {
- if (realpath(to,buff))
- strmake(to,buff,FN_REFLEN-1);
- }
+ strmov(buff,to);
+ (void) my_readlink(to, buff, MYF(0));
}
-#endif
DBUG_RETURN (to);
} /* fn_format */
diff --git a/mysys/mf_pack.c b/mysys/mf_pack.c
index c18d37888b8..b442af7e9e5 100644
--- a/mysys/mf_pack.c
+++ b/mysys/mf_pack.c
@@ -236,11 +236,16 @@ void symdirget(char *dir)
*pos++=temp; *pos=0; /* Restore old filename */
if (fp)
{
- if (fgets(buff, sizeof(buff), fp))
+ if (fgets(buff, sizeof(buff)-1, fp))
{
for (pos=strend(buff);
pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ;
pos --);
+
+ /* Ensure that the symlink ends with the directory symbol */
+ if (pos == buff || pos[-1] != FN_LIBCHAR)
+ *pos++=FN_LIBCHAR;
+
strmake(dir,buff, (uint) (pos-buff));
}
my_fclose(fp,MYF(0));
diff --git a/mysys/mf_same.c b/mysys/mf_same.c
index 5b8c5ecf970..c1a5cae11cb 100644
--- a/mysys/mf_same.c
+++ b/mysys/mf_same.c
@@ -20,19 +20,22 @@
#include "mysys_priv.h"
#include <m_string.h>
- /* Formaterar ett filnamn i avsende p} ett annat namn */
- /* Klarar {ven to = name */
- /* Denna funktion r|r inte p} utg}ngsnamnet */
+ /*
+ Copy directory and/or extension between filenames.
+ (For the meaning of 'flag', check mf_format.c)
+ 'to' may be equal to 'name'.
+ Returns 'to'.
+ */
-my_string fn_same(my_string toname, const char *name, int flag)
+my_string fn_same(char *to, const char *name, int flag)
{
char dev[FN_REFLEN];
const char *ext;
DBUG_ENTER("fn_same");
- DBUG_PRINT("mfunkt",("to: %s name: %s flag: %d",toname,name,flag));
+ DBUG_PRINT("enter",("to: %s name: %s flag: %d",to,name,flag));
if ((ext=strrchr(name+dirname_part(dev,name),FN_EXTCHAR)) == 0)
ext="";
- DBUG_RETURN(fn_format(toname,toname,dev,ext,flag));
+ DBUG_RETURN(fn_format(to,to,dev,ext,flag));
} /* fn_same */
diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c
index b82ff965dfb..ffbed381226 100644
--- a/mysys/my_alloc.c
+++ b/mysys/my_alloc.c
@@ -100,41 +100,34 @@ gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size)
#endif
}
+/* Mark all data in blocks free for reusage */
+
static inline void mark_blocks_free(MEM_ROOT* root)
{
- reg1 USED_MEM *next,*last = 0;
+ reg1 USED_MEM *next;
+ reg2 USED_MEM **last;
- /* iterate through (partially) free blocks, mark them fully free */
- for(next = root->free; next; next = next->next )
- {
- last = next;
- next->left = next->size - ALIGN_SIZE(sizeof(USED_MEM));
- }
- /* if free block list was not empty, point the next of the
- last free block to the beginning of the used list */
- next = root->used; /* a little optimization to avoid dereferencing root
- twice - we will shortly start iterating through used
- list */
- if(last)
- last->next = next;
- else /* if free list is empty, just point it to the current used*/
- root->free = next;
-
- /* now go through the current used list, and mark each block
- as fully free. Note that because of our optimization, we do not
- need to initialize next here - see above
- */
- for(;next; next = next->next)
- next->left = next->size - ALIGN_SIZE(sizeof(USED_MEM));
-
- /* Now everything is set - we just need to indicate that nothing is used
- anymore
- */
- root->used = 0;
+ /* iterate through (partially) free blocks, mark them free */
+ last= &root->free;
+ for (next= root->free; next; next= *(last= &next->next))
+ next->left= next->size - ALIGN_SIZE(sizeof(USED_MEM));
+
+ /* Combine the free and the used list */
+ *last= next=root->used;
+
+ /* now go through the used blocks and mark them free */
+ for (; next; next= next->next)
+ next->left= next->size - ALIGN_SIZE(sizeof(USED_MEM));
+
+ /* Now everything is set; Indicate that nothing is used anymore */
+ root->used= 0;
}
- /* deallocate everything used by alloc_root or just move
- used blocks to free list if called with MY_USED_TO_FREE */
+
+/*
+ Deallocate everything used by alloc_root or just move
+ used blocks to free list if called with MY_USED_TO_FREE
+*/
void free_root(MEM_ROOT *root, myf MyFlags)
{
@@ -143,23 +136,23 @@ void free_root(MEM_ROOT *root, myf MyFlags)
if (!root)
DBUG_VOID_RETURN; /* purecov: inspected */
- if(MyFlags & MY_MARK_BLOCKS_FREE)
- {
- mark_blocks_free(root);
- DBUG_VOID_RETURN;
- }
+ if (MyFlags & MY_MARK_BLOCKS_FREE)
+ {
+ mark_blocks_free(root);
+ DBUG_VOID_RETURN;
+ }
if (!(MyFlags & MY_KEEP_PREALLOC))
root->pre_alloc=0;
- for ( next=root->used; next ;)
+ for (next=root->used; next ;)
{
old=next; next= next->next ;
if (old != root->pre_alloc)
my_free((gptr) old,MYF(0));
}
- for (next= root->free ; next ; )
+ for (next=root->free ; next ;)
{
- old=next; next= next->next ;
+ old=next; next= next->next;
if (old != root->pre_alloc)
my_free((gptr) old,MYF(0));
}
diff --git a/mysys/my_compress.c b/mysys/my_compress.c
index d1e32234135..9d94a400f48 100644
--- a/mysys/my_compress.c
+++ b/mysys/my_compress.c
@@ -15,7 +15,7 @@
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA */
-/* Written by Sinisa Milivojevic <sinisa@coresinc.com> */
+/* Written by Sinisa Milivojevic <sinisa@mysql.com> */
#include <global.h>
#ifdef HAVE_COMPRESS
diff --git a/mysys/my_copy.c b/mysys/my_copy.c
index bfd7e957585..be131873118 100644
--- a/mysys/my_copy.c
+++ b/mysys/my_copy.c
@@ -54,7 +54,7 @@ int my_copy(const char *from, const char *to, myf MyFlags)
if (MyFlags & MY_HOLD_ORIGINAL_MODES) /* Copy stat if possible */
new_file_stat=stat((char*) to, &new_stat_buff);
- if ((from_file=my_open(from,O_RDONLY,MyFlags)) >= 0)
+ if ((from_file=my_open(from,O_RDONLY | O_SHARE,MyFlags)) >= 0)
{
if (stat(from,&stat_buff))
{
@@ -64,7 +64,7 @@ int my_copy(const char *from, const char *to, myf MyFlags)
if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat)
stat_buff=new_stat_buff;
if ((to_file= my_create(to,(int) stat_buff.st_mode,
- O_WRONLY | O_TRUNC | O_BINARY,
+ O_WRONLY | O_TRUNC | O_BINARY | O_SHARE,
MyFlags)) < 0)
goto err;
diff --git a/mysys/my_delete.c b/mysys/my_delete.c
index 77d5f311418..dc1e292a893 100644
--- a/mysys/my_delete.c
+++ b/mysys/my_delete.c
@@ -16,7 +16,6 @@
MA 02111-1307, USA */
#include "mysys_priv.h"
-
#include "mysys_err.h"
int my_delete(const char *name, myf MyFlags)
diff --git a/mysys/my_pread.c b/mysys/my_pread.c
index 4e0de71bcf5..5c7d0be5854 100644
--- a/mysys/my_pread.c
+++ b/mysys/my_pread.c
@@ -66,11 +66,11 @@ uint my_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset,
my_filename(Filedes),my_errno);
}
if ((int) readbytes == -1 || (MyFlags & (MY_FNABP | MY_NABP)))
- DBUG_RETURN(MY_FILE_ERROR); /* Return with error */
+ DBUG_RETURN(MY_FILE_ERROR); /* Return with error */
}
if (MyFlags & (MY_NABP | MY_FNABP))
- DBUG_RETURN(0); /* Ok vid l{sning */
- DBUG_RETURN(readbytes); /* purecov: inspected */
+ DBUG_RETURN(0); /* Read went ok; Return 0 */
+ DBUG_RETURN(readbytes); /* purecov: inspected */
}
} /* my_pread */
diff --git a/mysys/my_static.c b/mysys/my_static.c
index f1339877273..3fc68455841 100644
--- a/mysys/my_static.c
+++ b/mysys/my_static.c
@@ -97,4 +97,5 @@ int (*fatal_error_handler_hook)(uint error,const char *str,myf MyFlags)=
my_bool NEAR my_disable_locking=0;
my_bool NEAR my_disable_async_io=0;
my_bool NEAR my_disable_flush_key_blocks=0;
+my_bool NEAR my_disable_symlinks=0;
my_bool NEAR mysys_uses_curses=0;
diff --git a/mysys/my_symlink.c b/mysys/my_symlink.c
new file mode 100644
index 00000000000..65d165fc026
--- /dev/null
+++ b/mysys/my_symlink.c
@@ -0,0 +1,138 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA */
+
+#include "mysys_priv.h"
+#include "mysys_err.h"
+#include <m_string.h>
+#include <errno.h>
+#ifdef HAVE_REALPATH
+#include <sys/param.h>
+#include <sys/stat.h>
+#endif
+
+/*
+ Reads the content of a symbolic link
+ If the file is not a symbolic link, return the original file name in to.
+ Returns: 0 if table was a symlink,
+ 1 if table was a normal file
+ -1 on error.
+*/
+
+int my_readlink(char *to, const char *filename, myf MyFlags)
+{
+#ifndef HAVE_READLINK
+ strmov(to,filename);
+ return 1;
+#else
+ int result=0;
+ int length;
+ DBUG_ENTER("my_readlink");
+
+ if ((length=readlink(filename, to, FN_REFLEN-1)) < 0)
+ {
+ /* Don't give an error if this wasn't a symlink */
+ if ((my_errno=errno) == EINVAL)
+ {
+ result= 1;
+ strmov(to,filename);
+ }
+ else
+ {
+ if (MyFlags & MY_WME)
+ my_error(EE_CANT_READLINK, MYF(0), filename, errno);
+ result= -1;
+ }
+ }
+ else
+ to[length]=0;
+ DBUG_RETURN(result);
+#endif /* HAVE_READLINK */
+}
+
+
+/* Create a symbolic link */
+
+int my_symlink(const char *content, const char *linkname, myf MyFlags)
+{
+#ifndef HAVE_READLINK
+ return 0;
+#else
+ int result;
+ DBUG_ENTER("my_symlink");
+
+ result= 0;
+ if (symlink(content, linkname))
+ {
+ result= -1;
+ my_errno=errno;
+ if (MyFlags & MY_WME)
+ my_error(EE_CANT_SYMLINK, MYF(0), linkname, content, errno);
+ }
+ DBUG_RETURN(result);
+#endif /* HAVE_READLINK */
+}
+
+/*
+ Resolve all symbolic links in path
+ 'to' may be equal to 'filename'
+
+ Because purify gives a lot of UMR errors when using realpath(),
+ this code is disabled when using purify.
+
+ If MY_RESOLVE_LINK is given, only do realpath if the file is a link.
+*/
+
+#if defined(SCO)
+#define BUFF_LEN 4097
+#elif defined(MAXPATHLEN)
+#define BUFF_LEN MAXPATHLEN
+#else
+#define BUFF_LEN FN_LEN
+#endif
+
+int my_realpath(char *to, const char *filename, myf MyFlags)
+{
+#if defined(HAVE_REALPATH) && !defined(HAVE_purify) && !defined(HAVE_BROKEN_REALPATH)
+ int result=0;
+ char buff[BUFF_LEN];
+ struct stat stat_buff;
+ DBUG_ENTER("my_realpath");
+
+ if (!(MyFlags & MY_RESOLVE_LINK) ||
+ (!lstat(filename,&stat_buff) && S_ISLNK(stat_buff.st_mode)))
+ {
+ char *ptr;
+ if ((ptr=realpath(filename,buff)))
+ strmake(to,ptr,FN_REFLEN-1);
+ else
+ {
+ /* Realpath didn't work; Use original name */
+ my_errno=errno;
+ if (MyFlags & MY_WME)
+ my_error(EE_REALPATH, MYF(0), filename, my_errno);
+ if (to != filename)
+ strmov(to,filename);
+ result= -1;
+ }
+ }
+ DBUG_RETURN(result);
+#else
+ if (to != filename)
+ strmov(to,filename);
+ return 0;
+#endif
+}
diff --git a/mysys/my_symlink2.c b/mysys/my_symlink2.c
new file mode 100644
index 00000000000..e77815df12a
--- /dev/null
+++ b/mysys/my_symlink2.c
@@ -0,0 +1,155 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA */
+
+/*
+ Advanced symlink handling.
+ This is used in MyISAM to let users symlinks tables to different disk.
+ The main idea with these functions is to automaticly create, delete and
+ rename files and symlinks like they would be one unit.
+*/
+
+#include "mysys_priv.h"
+#include "mysys_err.h"
+#include <m_string.h>
+
+File my_create_with_symlink(const char *linkname, const char *filename,
+ int createflags, int access_flags, myf MyFlags)
+{
+ File file;
+ int tmp_errno;
+ /* Test if we should create a link */
+ int create_link=(linkname && strcmp(linkname,filename));
+ DBUG_ENTER("my_create_with_symlink");
+
+ if (!(MyFlags & MY_DELETE_OLD))
+ {
+ if (!access(filename,F_OK))
+ {
+ my_error(EE_CANTCREATEFILE, MYF(0), filename, EEXIST);
+ DBUG_RETURN(-1);
+ }
+ if (create_link && !access(linkname,F_OK))
+ {
+ my_error(EE_CANTCREATEFILE, MYF(0), linkname, EEXIST);
+ DBUG_RETURN(-1);
+ }
+ }
+
+ if ((file=my_create(filename, createflags, access_flags, MyFlags)) >= 0)
+ {
+ if (create_link)
+ {
+ /* Delete old link/file */
+ if (MyFlags & MY_DELETE_OLD)
+ my_delete(linkname, MYF(0));
+ /* Create link */
+ if (my_symlink(filename, linkname, MyFlags))
+ {
+ /* Fail, remove everything we have done */
+ tmp_errno=my_errno;
+ my_close(file,MYF(0));
+ my_delete(filename, MYF(0));
+ file= -1;
+ my_errno=tmp_errno;
+ }
+ }
+ }
+ DBUG_RETURN(file);
+}
+
+/*
+ If the file was a symlink, delete both symlink and the file which the
+ symlink pointed to.
+*/
+
+int my_delete_with_symlink(const char *name, myf MyFlags)
+{
+ char link_name[FN_REFLEN];
+ int was_symlink= (!my_disable_symlinks &&
+ !my_readlink(link_name, name, MYF(0)));
+ int result;
+ DBUG_ENTER("my_delete_with_symlink");
+
+ if (!(result=my_delete(name, MyFlags)))
+ {
+ if (was_symlink)
+ result=my_delete(link_name, MyFlags);
+ }
+ DBUG_RETURN(result);
+}
+
+/*
+ If the file is a normal file, just rename it.
+ If the file is a symlink:
+ - Create a new file with the name 'to' that points at
+ symlink_dir/basename(to)
+ - Rename the symlinked file to symlink_dir/basename(to)
+ - Delete 'from'
+ If something goes wrong, restore everything.
+*/
+
+int my_rename_with_symlink(const char *from, const char *to, myf MyFlags)
+{
+#ifndef HAVE_READLINK
+ return my_rename(from, to, MyFlags);
+#else
+ char link_name[FN_REFLEN], tmp_name[FN_REFLEN];
+ int was_symlink= (!my_disable_symlinks &&
+ !my_readlink(link_name, from, MYF(0)));
+ int result=0;
+ DBUG_ENTER("my_rename_with_symlink");
+
+ if (!was_symlink)
+ DBUG_RETURN(my_rename(from, to, MyFlags));
+
+ /* Change filename that symlink pointed to */
+ strmov(tmp_name, to);
+ fn_same(tmp_name,link_name,1); /* Copy dir */
+
+ /* Create new symlink */
+ if (my_symlink(tmp_name, to, MyFlags))
+ DBUG_RETURN(1);
+
+ /*
+ Rename symlinked file if the base name didn't change.
+ This can happen if you use this function where 'from' and 'to' has
+ the same basename and different directories.
+ */
+
+ if (strcmp(link_name, tmp_name) && my_rename(link_name, tmp_name, MyFlags))
+ {
+ int save_errno=my_errno;
+ my_delete(to, MyFlags); /* Remove created symlink */
+ my_errno=save_errno;
+ DBUG_RETURN(1);
+ }
+
+ /* Remove original symlink */
+ if (my_delete(from, MyFlags))
+ {
+ int save_errno=my_errno;
+ /* Remove created link */
+ my_delete(to, MyFlags);
+ /* Rename file back */
+ if (strcmp(link_name, tmp_name))
+ (void) my_rename(tmp_name, link_name, MyFlags);
+ my_errno=save_errno;
+ result= 1;
+ }
+ DBUG_RETURN(result);
+#endif /* HAVE_READLINK */
+}
diff --git a/mysys/tree.c b/mysys/tree.c
index 1ea7e48a790..7100b72345c 100644
--- a/mysys/tree.c
+++ b/mysys/tree.c
@@ -312,6 +312,8 @@ int tree_delete(TREE *tree, void *key)
}
if (remove_colour == BLACK)
rb_delete_fixup(tree,parent);
+ if (tree->free)
+ (*tree->free)(ELEMENT_KEY(tree,element));
my_free((gptr) element,MYF(0));
tree->elements_in_tree--;
return 0;