Skip to content

Commit f09d061

Browse files
author
georg@lmy002.wdf.sap.corp
committed
fix for bug#5650 ('replace' does not follow symlinks)
fix now checks if the original (from) file is a symlink and uses the link name. This prevents creation of a new file (and loss of symlink) when renaming the tempfile.
1 parent 35b66a4 commit f09d061

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

extra/replace.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -1053,12 +1053,18 @@ static int convert_file(REPLACE *rep, my_string name)
10531053
int error;
10541054
FILE *in,*out;
10551055
char dir_buff[FN_REFLEN], tempname[FN_REFLEN];
1056+
char link_name[FN_REFLEN], *org_name = name;
10561057
File temp_file;
10571058
DBUG_ENTER("convert_file");
10581059

1059-
if (!(in=my_fopen(name,O_RDONLY,MYF(MY_WME))))
1060+
/* check if name is a symlink */
1061+
#ifdef HAVE_READLINK
1062+
org_name= (!my_disable_symlinks &&
1063+
!my_readlink(link_name, name, MYF(0))) ? link_name : name;
1064+
#endif
1065+
if (!(in= my_fopen(org_name,O_RDONLY,MYF(MY_WME))))
10601066
DBUG_RETURN(1);
1061-
dirname_part(dir_buff,name);
1067+
dirname_part(dir_buff,org_name);
10621068
if ((temp_file= create_temp_file(tempname, dir_buff, "PR", O_WRONLY,
10631069
MYF(MY_WME))) < 0)
10641070
{
@@ -1075,7 +1081,7 @@ static int convert_file(REPLACE *rep, my_string name)
10751081
my_fclose(in,MYF(0)); my_fclose(out,MYF(0));
10761082

10771083
if (updated && ! error)
1078-
my_redel(name,tempname,MYF(MY_WME | MY_LINK_WARNING));
1084+
my_redel(org_name,tempname,MYF(MY_WME | MY_LINK_WARNING));
10791085
else
10801086
my_delete(tempname,MYF(MY_WME));
10811087
if (!silent && ! error)

0 commit comments

Comments
 (0)