| 1051 | |
| 1052 | |
| 1053 | static int convert_file(REPLACE *rep, char * name) |
| 1054 | { |
| 1055 | int error; |
| 1056 | FILE *in,*out; |
| 1057 | char dir_buff[FN_REFLEN], tempname[FN_REFLEN], *org_name = name; |
| 1058 | #ifdef HAVE_READLINK |
| 1059 | char link_name[FN_REFLEN]; |
| 1060 | #endif |
| 1061 | File temp_file; |
| 1062 | size_t dir_buff_length; |
| 1063 | DBUG_ENTER("convert_file"); |
| 1064 | |
| 1065 | /* check if name is a symlink */ |
| 1066 | #ifdef HAVE_READLINK |
| 1067 | org_name= (!my_disable_symlinks && |
| 1068 | !my_readlink(link_name, name, MYF(0))) ? link_name : name; |
| 1069 | #endif |
| 1070 | if (!(in= my_fopen(org_name,O_RDONLY,MYF(MY_WME)))) |
| 1071 | DBUG_RETURN(1); |
| 1072 | dirname_part(dir_buff, org_name, &dir_buff_length); |
| 1073 | if ((temp_file= create_temp_file(tempname, dir_buff, "PR", O_WRONLY, |
| 1074 | MYF(MY_WME))) < 0) |
| 1075 | { |
| 1076 | my_fclose(in,MYF(0)); |
| 1077 | DBUG_RETURN(1); |
| 1078 | } |
| 1079 | if (!(out= my_fdopen(temp_file, tempname, O_WRONLY, MYF(MY_WME)))) |
| 1080 | { |
| 1081 | my_fclose(in,MYF(0)); |
| 1082 | DBUG_RETURN(1); |
| 1083 | } |
| 1084 | |
| 1085 | error=convert_pipe(rep,in,out); |
| 1086 | my_fclose(in,MYF(0)); my_fclose(out,MYF(0)); |
| 1087 | |
| 1088 | if (updated && ! error) |
| 1089 | my_redel(org_name,tempname,MYF(MY_WME | MY_LINK_WARNING)); |
| 1090 | else |
| 1091 | my_delete(tempname,MYF(MY_WME)); |
| 1092 | if (!silent && ! error) |
| 1093 | { |
| 1094 | if (updated) |
| 1095 | printf("%s converted\n",name); |
| 1096 | else if (verbose) |
| 1097 | printf("%s left unchanged\n",name); |
| 1098 | } |
| 1099 | DBUG_RETURN(error); |
| 1100 | } |
no test coverage detected