@@ -280,6 +280,7 @@ static STATUS status;
280280static ulong select_limit,max_join_size,opt_connect_timeout=0 ;
281281static char mysql_charsets_dir[FN_REFLEN+1 ];
282282static char *opt_plugin_dir= 0 , *opt_default_auth= 0 ;
283+ static char *script_dir = NULL ;
283284static const char *xmlmeta[] = {
284285 " &" , " &" ,
285286 " <" , " <" ,
@@ -1838,6 +1839,8 @@ static struct my_option my_long_options[] =
18381839 &safe_updates, &safe_updates, 0 , GET_BOOL, NO_ARG, 0 , 0 , 0 , 0 , 0 , 0 },
18391840 {" sandbox" , 0 , " Disallow commands that access the file system (except \\ P without an argument and \\ e)." ,
18401841 &status.sandbox , &status.sandbox , 0 , GET_BOOL, NO_ARG, 0 , 0 , 0 , 0 , 0 , 0 },
1842+ {" script-dir" , 0 , " Set an alternative directory path for searching scripts invoked via the source command." ,
1843+ &script_dir, &script_dir, 0 , GET_STR, REQUIRED_ARG, 0 , 0 , 0 , 0 , 0 , 0 },
18411844 {" secure-auth" , 0 , " Refuse client connecting to server if it"
18421845 " uses old (pre-4.1.1) protocol." , &opt_secure_auth,
18431846 &opt_secure_auth, 0 , GET_BOOL, NO_ARG, 0 , 0 , 0 , 0 , 0 , 0 },
@@ -4692,6 +4695,7 @@ static int com_connect(String *buffer, char *line)
46924695static int com_source (String *, char *line)
46934696{
46944697 char source_name[FN_REFLEN], *end, *param;
4698+ char full_path[FN_REFLEN];
46954699 LINE_BUFFER *line_buff;
46964700 int error;
46974701 STATUS old_status;
@@ -4718,8 +4722,17 @@ static int com_source(String *, char *line)
47184722 /* open file name */
47194723 if (!(sql_file = my_fopen (source_name, O_RDONLY | O_BINARY,MYF (0 ))))
47204724 {
4721- char buff[FN_REFLEN+60 ];
4722- sprintf (buff," Failed to open file '%s', error: %d" , source_name,errno);
4725+ if (script_dir)
4726+ {
4727+ snprintf (full_path, sizeof (full_path), " %s/%s" , script_dir, source_name);
4728+ sql_file = my_fopen (full_path, O_RDONLY | O_BINARY, MYF (0 ));
4729+ }
4730+ }
4731+
4732+ if (!sql_file)
4733+ {
4734+ char buff[FN_REFLEN + 60 ];
4735+ sprintf (buff, " Failed to open file '%s', error: %d" , source_name, errno);
47234736 return put_info (buff, INFO_ERROR, 0 );
47244737 }
47254738
0 commit comments