Merge lp:~elambert/drizzle/rm_my_symlink into lp:~drizzle-trunk/drizzle/7.2-staging
- rm_my_symlink
- Merge into 7.2-staging
Proposed by
Eric Lambert
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~elambert/drizzle/rm_my_symlink |
Merge into: | lp:~drizzle-trunk/drizzle/7.2-staging |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~elambert/drizzle/rm_my_symlink |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Drizzle Developers | Pending | ||
Review via email: mp+7479@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Eric Lambert (elambert) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'client/drizzle.cc' |
2 | --- client/drizzle.cc 2009-05-22 17:13:38 +0000 |
3 | +++ client/drizzle.cc 2009-06-12 23:11:27 +0000 |
4 | @@ -1292,12 +1292,16 @@ |
5 | if (histfile) |
6 | sprintf(histfile,"%s/.drizzle_history",getenv("HOME")); |
7 | char link_name[FN_REFLEN]; |
8 | - if (my_readlink(link_name, histfile, 0) == 0 && |
9 | - strncmp(link_name, "/dev/null", 10) == 0) |
10 | + ssize_t sym_link_size= readlink(histfile,link_name,FN_REFLEN-1); |
11 | + if (sym_link_size >= 0) |
12 | { |
13 | - /* The .drizzle_history file is a symlink to /dev/null, don't use it */ |
14 | - free(histfile); |
15 | - histfile= 0; |
16 | + link_name[sym_link_size]= '\0'; |
17 | + if (strncmp(link_name, "/dev/null", 10) == 0) |
18 | + { |
19 | + /* The .drizzle_history file is a symlink to /dev/null, don't use it */ |
20 | + free(histfile); |
21 | + histfile= 0; |
22 | + } |
23 | } |
24 | } |
25 | if (histfile) |
26 | |
27 | === modified file 'drizzled/drizzled.cc' |
28 | --- drizzled/drizzled.cc 2009-06-05 23:29:08 +0000 |
29 | +++ drizzled/drizzled.cc 2009-06-16 01:36:01 +0000 |
30 | @@ -3128,12 +3128,19 @@ |
31 | |
32 | static void fix_paths(void) |
33 | { |
34 | - char buff[FN_REFLEN],*pos; |
35 | + char buff[FN_REFLEN],*pos,rp_buff[PATH_MAX]; |
36 | convert_dirname(drizzle_home,drizzle_home,NULL); |
37 | /* Resolve symlinks to allow 'drizzle_home' to be a relative symlink */ |
38 | - my_realpath(drizzle_home,drizzle_home,MYF(0)); |
39 | +#if defined(HAVE_BROKEN_REALPATH) |
40 | + my_load_path(drizzle_home, drizzle_home, NULL); |
41 | +#else |
42 | + if (!realpath(drizzle_home,rp_buff)) |
43 | + my_load_path(rp_buff, drizzle_home, NULL); |
44 | + rp_buff[FN_REFLEN-1]= '\0'; |
45 | + strcpy(drizzle_home,rp_buff); |
46 | /* Ensure that drizzle_home ends in FN_LIBCHAR */ |
47 | pos= strchr(drizzle_home, '\0'); |
48 | +#endif |
49 | if (pos[-1] != FN_LIBCHAR) |
50 | { |
51 | pos[0]= FN_LIBCHAR; |
52 | |
53 | === modified file 'mysys/mf_format.cc' |
54 | --- mysys/mf_format.cc 2009-04-17 21:01:47 +0000 |
55 | +++ mysys/mf_format.cc 2009-06-16 01:36:01 +0000 |
56 | @@ -96,12 +96,24 @@ |
57 | realpath if the file is a symbolic link |
58 | */ |
59 | if (flag & MY_RETURN_REAL_PATH) |
60 | - (void) my_realpath(to, to, MYF(flag & MY_RESOLVE_SYMLINKS ? |
61 | - MY_RESOLVE_LINK: 0)); |
62 | + { |
63 | + struct stat stat_buff; |
64 | + char rp_buff[PATH_MAX]; |
65 | + if ((!flag & MY_RESOLVE_SYMLINKS) || |
66 | + (!lstat(to,&stat_buff)) && S_ISLNK(stat_buff.st_mode)) |
67 | + { |
68 | + if (!realpath(to,rp_buff)) |
69 | + my_load_path(rp_buff, to, NULL); |
70 | + rp_buff[FN_REFLEN-1]= '\0'; |
71 | + strcpy(to,rp_buff); |
72 | + } |
73 | + } |
74 | else if (flag & MY_RESOLVE_SYMLINKS) |
75 | { |
76 | strcpy(buff,to); |
77 | - (void) my_readlink(to, buff, MYF(0)); |
78 | + ssize_t sym_link_size= readlink(buff,to,FN_REFLEN-1); |
79 | + if (sym_link_size >= 0) |
80 | + to[sym_link_size]= '\0'; |
81 | } |
82 | return(to); |
83 | } /* fn_format */ |
84 | |
85 | === modified file 'mysys/my_symlink.cc' |
86 | --- mysys/my_symlink.cc 2009-05-24 18:17:38 +0000 |
87 | +++ mysys/my_symlink.cc 2009-06-16 01:36:01 +0000 |
88 | @@ -17,128 +17,6 @@ |
89 | #include "mysys/mysys_err.h" |
90 | #include <mystrings/m_string.h> |
91 | #include <errno.h> |
92 | -#ifdef HAVE_REALPATH |
93 | -#include <sys/param.h> |
94 | -#include <sys/stat.h> |
95 | -#endif |
96 | - |
97 | -/* |
98 | - Reads the content of a symbolic link |
99 | - If the file is not a symbolic link, return the original file name in to. |
100 | - |
101 | - RETURN |
102 | - 0 If filename was a symlink, (to will be set to value of symlink) |
103 | - 1 If filename was a normal file (to will be set to filename) |
104 | - -1 on error. |
105 | -*/ |
106 | - |
107 | -int my_readlink(char *to, const char *filename, myf MyFlags) |
108 | -{ |
109 | -#ifndef HAVE_READLINK |
110 | - strcpy(to,filename); |
111 | - return 1; |
112 | -#else |
113 | - int result=0; |
114 | - int length; |
115 | - |
116 | - if ((length=readlink(filename, to, FN_REFLEN-1)) < 0) |
117 | - { |
118 | - /* Don't give an error if this wasn't a symlink */ |
119 | - if ((my_errno=errno) == EINVAL) |
120 | - { |
121 | - result= 1; |
122 | - strcpy(to,filename); |
123 | - } |
124 | - else |
125 | - { |
126 | - if (MyFlags & MY_WME) |
127 | - my_error(EE_CANT_READLINK, MYF(0), filename, errno); |
128 | - result= -1; |
129 | - } |
130 | - } |
131 | - else |
132 | - to[length]=0; |
133 | - return(result); |
134 | -#endif /* HAVE_READLINK */ |
135 | -} |
136 | - |
137 | - |
138 | -/* Create a symbolic link */ |
139 | - |
140 | -int my_symlink(const char *content, const char *linkname, myf MyFlags) |
141 | -{ |
142 | -#ifndef HAVE_READLINK |
143 | - return 0; |
144 | -#else |
145 | - int result; |
146 | - |
147 | - result= 0; |
148 | - if (symlink(content, linkname)) |
149 | - { |
150 | - result= -1; |
151 | - my_errno=errno; |
152 | - if (MyFlags & MY_WME) |
153 | - my_error(EE_CANT_SYMLINK, MYF(0), linkname, content, errno); |
154 | - } |
155 | - else if ((MyFlags & MY_SYNC_DIR) && my_sync_dir_by_file(linkname, MyFlags)) |
156 | - result= -1; |
157 | - return(result); |
158 | -#endif /* HAVE_READLINK */ |
159 | -} |
160 | - |
161 | -/* |
162 | - Resolve all symbolic links in path |
163 | - 'to' may be equal to 'filename' |
164 | - |
165 | - Because purify gives a lot of UMR errors when using realpath(), |
166 | - this code is disabled when using purify. |
167 | - |
168 | - If MY_RESOLVE_LINK is given, only do realpath if the file is a link. |
169 | -*/ |
170 | - |
171 | -#if defined(SCO) |
172 | -#define BUFF_LEN 4097 |
173 | -#elif defined(MAXPATHLEN) |
174 | -#define BUFF_LEN MAXPATHLEN |
175 | -#else |
176 | -#define BUFF_LEN FN_LEN |
177 | -#endif |
178 | - |
179 | -int my_realpath(char *to, const char *filename, myf MyFlags) |
180 | -{ |
181 | -#if defined(HAVE_REALPATH) && !defined(HAVE_BROKEN_REALPATH) |
182 | - int result=0; |
183 | - char buff[BUFF_LEN]; |
184 | - struct stat stat_buff; |
185 | - |
186 | - if (!(MyFlags & MY_RESOLVE_LINK) || |
187 | - (!lstat(filename,&stat_buff) && S_ISLNK(stat_buff.st_mode))) |
188 | - { |
189 | - char *ptr; |
190 | - if ((ptr=realpath(filename,buff))) |
191 | - { |
192 | - strncpy(to,ptr,FN_REFLEN-1); |
193 | - } |
194 | - else |
195 | - { |
196 | - /* |
197 | - Realpath didn't work; Use my_load_path() which is a poor substitute |
198 | - original name but will at least be able to resolve paths that starts |
199 | - with '.'. |
200 | - */ |
201 | - my_errno=errno; |
202 | - if (MyFlags & MY_WME) |
203 | - my_error(EE_REALPATH, MYF(0), filename, my_errno); |
204 | - my_load_path(to, filename, NULL); |
205 | - result= -1; |
206 | - } |
207 | - } |
208 | - return(result); |
209 | -#else |
210 | - my_load_path(to, filename, NULL); |
211 | - return 0; |
212 | -#endif |
213 | -} |
214 | |
215 | bool test_if_hard_path(const char *dir_name) |
216 | { |
217 | |
218 | === modified file 'mysys/my_symlink2.cc' |
219 | --- mysys/my_symlink2.cc 2009-04-17 21:01:47 +0000 |
220 | +++ mysys/my_symlink2.cc 2009-06-16 01:36:01 +0000 |
221 | @@ -32,6 +32,7 @@ |
222 | /* Test if we should create a link */ |
223 | int create_link; |
224 | char abs_linkname[FN_REFLEN]; |
225 | + char rp_buff[PATH_MAX]; |
226 | |
227 | if (my_disable_symlinks) |
228 | { |
229 | @@ -43,7 +44,12 @@ |
230 | else |
231 | { |
232 | if (linkname) |
233 | - my_realpath(abs_linkname, linkname, MYF(0)); |
234 | + { |
235 | + if (!realpath(linkname,rp_buff)) |
236 | + my_load_path(rp_buff, linkname, NULL); |
237 | + rp_buff[FN_REFLEN-1]= '\0'; |
238 | + strcpy(abs_linkname,rp_buff); |
239 | + } |
240 | create_link= (linkname && strcmp(abs_linkname,filename)); |
241 | } |
242 | |
243 | @@ -71,7 +77,7 @@ |
244 | if (MyFlags & MY_DELETE_OLD) |
245 | my_delete(linkname, MYF(0)); |
246 | /* Create link */ |
247 | - if (my_symlink(filename, linkname, MyFlags)) |
248 | + if (symlink(filename,linkname)) |
249 | { |
250 | /* Fail, remove everything we have done */ |
251 | tmp_errno=my_errno; |
252 | @@ -80,6 +86,8 @@ |
253 | file= -1; |
254 | my_errno=tmp_errno; |
255 | } |
256 | + else if (MyFlags & MY_SYNC_DIR) |
257 | + my_sync_dir_by_file(linkname, MyFlags); |
258 | } |
259 | } |
260 | return(file); |
261 | @@ -93,14 +101,17 @@ |
262 | int my_delete_with_symlink(const char *name, myf MyFlags) |
263 | { |
264 | char link_name[FN_REFLEN]; |
265 | - int was_symlink= (!my_disable_symlinks && |
266 | - !my_readlink(link_name, name, MYF(0))); |
267 | + ssize_t sym_link_size= readlink(name,link_name,FN_REFLEN-1); |
268 | + int was_symlink= (!my_disable_symlinks && sym_link_size != -1); |
269 | int result; |
270 | |
271 | if (!(result=my_delete(name, MyFlags))) |
272 | { |
273 | if (was_symlink) |
274 | - result=my_delete(link_name, MyFlags); |
275 | + { |
276 | + link_name[sym_link_size]= '\0'; |
277 | + result= my_delete(link_name, MyFlags); |
278 | + } |
279 | } |
280 | return(result); |
281 | } |
282 | @@ -121,13 +132,16 @@ |
283 | return my_rename(from, to, MyFlags); |
284 | #else |
285 | char link_name[FN_REFLEN], tmp_name[FN_REFLEN]; |
286 | + int sym_link_size= -1; |
287 | int was_symlink= (!my_disable_symlinks && |
288 | - !my_readlink(link_name, from, MYF(0))); |
289 | + (sym_link_size= readlink(from,link_name,FN_REFLEN-1)) != -1); |
290 | int result=0; |
291 | int name_is_different; |
292 | |
293 | if (!was_symlink) |
294 | return(my_rename(from, to, MyFlags)); |
295 | + else |
296 | + link_name[sym_link_size]= '\0'; |
297 | |
298 | /* Change filename that symlink pointed to */ |
299 | strcpy(tmp_name, to); |
300 | @@ -142,8 +156,10 @@ |
301 | } |
302 | |
303 | /* Create new symlink */ |
304 | - if (my_symlink(tmp_name, to, MyFlags)) |
305 | + if (symlink(tmp_name, to)) |
306 | return(1); |
307 | + else if (MyFlags & MY_SYNC_DIR) |
308 | + my_sync_dir_by_file(to, MyFlags); |
309 | |
310 | /* |
311 | Rename symlinked file if the base name didn't change. |
312 | |
313 | === modified file 'mysys/my_sys.h' |
314 | --- mysys/my_sys.h 2009-05-26 20:45:27 +0000 |
315 | +++ mysys/my_sys.h 2009-06-15 16:15:04 +0000 |
316 | @@ -300,14 +300,12 @@ |
317 | extern int my_close(File Filedes,myf MyFlags); |
318 | extern File my_dup(File file, myf MyFlags); |
319 | extern int my_mkdir(const char *dir, int Flags, myf MyFlags); |
320 | -extern int my_readlink(char *to, const char *filename, myf MyFlags); |
321 | extern int my_realpath(char *to, const char *filename, myf MyFlags); |
322 | extern File my_create_with_symlink(const char *linkname, const char *filename, |
323 | int createflags, int access_flags, |
324 | myf MyFlags); |
325 | extern int my_delete_with_symlink(const char *name, myf MyFlags); |
326 | extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags); |
327 | -extern int my_symlink(const char *content, const char *linkname, myf MyFlags); |
328 | extern size_t my_read(File Filedes,unsigned char *Buffer,size_t Count,myf MyFlags); |
329 | extern int my_rename(const char *from,const char *to,myf MyFlags); |
330 | extern size_t my_write(File Filedes,const unsigned char *Buffer,size_t Count, |
331 | |
332 | === modified file 'plugin/archive/ha_archive.cc' |
333 | --- plugin/archive/ha_archive.cc 2009-06-08 01:32:13 +0000 |
334 | +++ plugin/archive/ha_archive.cc 2009-06-15 16:15:04 +0000 |
335 | @@ -578,7 +578,7 @@ |
336 | } |
337 | |
338 | if (linkname[0]) |
339 | - my_symlink(name_buff, linkname, MYF(0)); |
340 | + symlink(name_buff, linkname); |
341 | fn_format(name_buff, table_name, "", ".frm", |
342 | MY_REPLACE_EXT | MY_UNPACK_FILENAME); |
343 | |
344 | @@ -1183,8 +1183,11 @@ |
345 | create_info->auto_increment_value= stats.auto_increment_value; |
346 | } |
347 | |
348 | - if (!(my_readlink(share->real_path, share->data_file_name, MYF(0)))) |
349 | + ssize_t sym_link_size= readlink(share->data_file_name,share->real_path,FN_REFLEN-1); |
350 | + if (sym_link_size >= 0) { |
351 | + share->real_path[sym_link_size]= '\0'; |
352 | create_info->data_file_name= share->real_path; |
353 | + } |
354 | |
355 | return; |
356 | } |
357 | |
358 | === modified file 'plugin/myisam/mi_open.cc' |
359 | --- plugin/myisam/mi_open.cc 2009-03-28 06:09:15 +0000 |
360 | +++ plugin/myisam/mi_open.cc 2009-06-16 01:36:01 +0000 |
361 | @@ -68,7 +68,7 @@ |
362 | uint32_t i,j,len,errpos,head_length,base_pos,offset,info_length,keys, |
363 | key_parts,unique_key_parts,fulltext_keys,uniques; |
364 | char name_buff[FN_REFLEN], org_name[FN_REFLEN], index_name[FN_REFLEN], |
365 | - data_name[FN_REFLEN]; |
366 | + data_name[FN_REFLEN], rp_buff[PATH_MAX]; |
367 | unsigned char *disk_cache= NULL; |
368 | unsigned char *disk_pos, *end_pos; |
369 | MI_INFO info,*m_info,*old_info; |
370 | @@ -83,8 +83,11 @@ |
371 | head_length=sizeof(share_buff.state.header); |
372 | memset(&info, 0, sizeof(info)); |
373 | |
374 | - my_realpath(name_buff, fn_format(org_name,name,"",MI_NAME_IEXT, |
375 | - MY_UNPACK_FILENAME),MYF(0)); |
376 | + (void)fn_format(org_name,name,"",MI_NAME_IEXT, MY_UNPACK_FILENAME); |
377 | + if (!realpath(org_name,rp_buff)) |
378 | + my_load_path(rp_buff,org_name, NULL); |
379 | + rp_buff[FN_REFLEN-1]= '\0'; |
380 | + strcpy(name_buff,rp_buff); |
381 | pthread_mutex_lock(&THR_LOCK_myisam); |
382 | if (!(old_info=test_if_reopen(name_buff))) |
383 | { |
384 | @@ -134,8 +137,10 @@ |
385 | goto err; |
386 | } |
387 | /* Don't call realpath() if the name can't be a link */ |
388 | - if (!strcmp(name_buff, org_name) || |
389 | - my_readlink(index_name, org_name, MYF(0)) == -1) |
390 | + ssize_t sym_link_size= readlink(org_name,index_name,FN_REFLEN-1); |
391 | + if (sym_link_size >= 0 ) |
392 | + index_name[sym_link_size]= '\0'; |
393 | + if (!strcmp(name_buff, org_name) || sym_link_size == -1) |
394 | (void) strcpy(index_name, org_name); |
395 | *strrchr(org_name, '.')= '\0'; |
396 | (void) fn_format(data_name,org_name,"",MI_NAME_DEXT, |
removed calls to functions defined within mysys/my_symlink and replaced the calls with the corresponding posix functions.