23 #include "mysys_priv.h"
24 #include "mysys_err.h"
27 File my_create_with_symlink(
const char *linkname,
const char *filename,
28 int createflags,
int access_flags, myf MyFlags)
34 char abs_linkname[FN_REFLEN];
35 DBUG_ENTER(
"my_create_with_symlink");
36 DBUG_PRINT(
"enter", (
"linkname: %s filename: %s",
37 linkname ? linkname :
"(null)",
38 filename ? filename :
"(null)"));
40 if (my_disable_symlinks)
42 DBUG_PRINT(
"info", (
"Symlinks disabled"));
51 my_realpath(abs_linkname, linkname, MYF(0));
52 create_link= (linkname && strcmp(abs_linkname,filename));
55 if (!(MyFlags & MY_DELETE_OLD))
57 if (!access(filename,F_OK))
59 char errbuf[MYSYS_STRERROR_SIZE];
60 my_errno= errno= EEXIST;
61 my_error(EE_CANTCREATEFILE, MYF(0), filename,
62 EEXIST, my_strerror(errbuf,
sizeof(errbuf), EEXIST));
65 if (create_link && !access(linkname,F_OK))
67 char errbuf[MYSYS_STRERROR_SIZE];
68 my_errno= errno= EEXIST;
69 my_error(EE_CANTCREATEFILE, MYF(0), linkname,
70 EEXIST, my_strerror(errbuf,
sizeof(errbuf), EEXIST));
75 if ((file=my_create(filename, createflags, access_flags, MyFlags)) >= 0)
80 if (MyFlags & MY_DELETE_OLD)
81 my_delete(linkname, MYF(0));
83 if (my_symlink(filename, linkname, MyFlags))
87 my_close(file,MYF(0));
88 my_delete(filename, MYF(0));
102 int my_delete_with_symlink(
const char *
name, myf MyFlags)
104 char link_name[FN_REFLEN];
105 int was_symlink= (!my_disable_symlinks &&
106 !my_readlink(link_name, name, MYF(0)));
108 DBUG_ENTER(
"my_delete_with_symlink");
110 if (!(result=my_delete(name, MyFlags)))
113 result=my_delete(link_name, MyFlags);
128 int my_rename_with_symlink(
const char *from,
const char *
to, myf MyFlags)
130 #ifndef HAVE_READLINK
131 return my_rename(from, to, MyFlags);
133 char link_name[FN_REFLEN], tmp_name[FN_REFLEN];
134 int was_symlink= (!my_disable_symlinks &&
135 !my_readlink(link_name, from, MYF(0)));
137 int name_is_different;
138 DBUG_ENTER(
"my_rename_with_symlink");
141 DBUG_RETURN(my_rename(from, to, MyFlags));
144 strmov(tmp_name, to);
145 fn_same(tmp_name,link_name,1);
146 name_is_different= strcmp(link_name, tmp_name);
147 if (name_is_different && !access(tmp_name, F_OK))
150 if (MyFlags & MY_WME)
152 char errbuf[MYSYS_STRERROR_SIZE];
153 my_error(EE_CANTCREATEFILE, MYF(0), tmp_name,
154 EEXIST, my_strerror(errbuf,
sizeof(errbuf), EEXIST));
160 if (my_symlink(tmp_name, to, MyFlags))
169 if (name_is_different && my_rename(link_name, tmp_name, MyFlags))
171 int save_errno=my_errno;
172 my_delete(to, MyFlags);
178 if (my_delete(from, MyFlags))
180 int save_errno=my_errno;
182 my_delete(to, MyFlags);
184 if (strcmp(link_name, tmp_name))
185 (void) my_rename(tmp_name, link_name, MyFlags);