mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
upmerge 39774
This commit is contained in:
@ -294,7 +294,7 @@ enum enum_commands {
|
|||||||
Q_LIST_FILES, Q_LIST_FILES_WRITE_FILE, Q_LIST_FILES_APPEND_FILE,
|
Q_LIST_FILES, Q_LIST_FILES_WRITE_FILE, Q_LIST_FILES_APPEND_FILE,
|
||||||
Q_SEND_SHUTDOWN, Q_SHUTDOWN_SERVER,
|
Q_SEND_SHUTDOWN, Q_SHUTDOWN_SERVER,
|
||||||
Q_RESULT_FORMAT_VERSION,
|
Q_RESULT_FORMAT_VERSION,
|
||||||
Q_MOVE_FILE, Q_SEND_EVAL,
|
Q_MOVE_FILE, Q_REMOVE_FILES_WILDCARD, Q_SEND_EVAL,
|
||||||
Q_UNKNOWN, /* Unknown command. */
|
Q_UNKNOWN, /* Unknown command. */
|
||||||
Q_COMMENT, /* Comments, ignored. */
|
Q_COMMENT, /* Comments, ignored. */
|
||||||
Q_COMMENT_WITH_COMMAND,
|
Q_COMMENT_WITH_COMMAND,
|
||||||
@ -391,6 +391,7 @@ const char *command_names[]=
|
|||||||
"shutdown_server",
|
"shutdown_server",
|
||||||
"result_format",
|
"result_format",
|
||||||
"move_file",
|
"move_file",
|
||||||
|
"remove_files_wildcard",
|
||||||
"send_eval",
|
"send_eval",
|
||||||
|
|
||||||
0
|
0
|
||||||
@ -2939,6 +2940,81 @@ void do_remove_file(struct st_command *command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
SYNOPSIS
|
||||||
|
do_remove_files_wildcard
|
||||||
|
command called command
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
remove_files_wildcard <directory> [<file_name_pattern>]
|
||||||
|
Remove the files in <directory> optionally matching <file_name_pattern>
|
||||||
|
*/
|
||||||
|
|
||||||
|
void do_remove_files_wildcard(struct st_command *command)
|
||||||
|
{
|
||||||
|
int error= 0;
|
||||||
|
uint i;
|
||||||
|
MY_DIR *dir_info;
|
||||||
|
FILEINFO *file;
|
||||||
|
char dir_separator[2];
|
||||||
|
static DYNAMIC_STRING ds_directory;
|
||||||
|
static DYNAMIC_STRING ds_wild;
|
||||||
|
static DYNAMIC_STRING ds_file_to_remove;
|
||||||
|
char dirname[FN_REFLEN];
|
||||||
|
|
||||||
|
const struct command_arg rm_args[] = {
|
||||||
|
{ "directory", ARG_STRING, TRUE, &ds_directory,
|
||||||
|
"Directory containing files to delete" },
|
||||||
|
{ "filename", ARG_STRING, FALSE, &ds_wild, "File pattern to delete" }
|
||||||
|
};
|
||||||
|
DBUG_ENTER("do_remove_files_wildcard");
|
||||||
|
|
||||||
|
check_command_args(command, command->first_argument,
|
||||||
|
rm_args, sizeof(rm_args)/sizeof(struct command_arg),
|
||||||
|
' ');
|
||||||
|
fn_format(dirname, ds_directory.str, "", "", MY_UNPACK_FILENAME);
|
||||||
|
|
||||||
|
DBUG_PRINT("info", ("listing directory: %s", dirname));
|
||||||
|
/* Note that my_dir sorts the list if not given any flags */
|
||||||
|
if (!(dir_info= my_dir(dirname, MYF(MY_DONT_SORT | MY_WANT_STAT))))
|
||||||
|
{
|
||||||
|
error= 1;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
init_dynamic_string(&ds_file_to_remove, dirname, 1024, 1024);
|
||||||
|
dir_separator[0]= FN_LIBCHAR;
|
||||||
|
dir_separator[1]= 0;
|
||||||
|
dynstr_append(&ds_file_to_remove, dir_separator);
|
||||||
|
for (i= 0; i < (uint) dir_info->number_off_files; i++)
|
||||||
|
{
|
||||||
|
file= dir_info->dir_entry + i;
|
||||||
|
/* Remove only regular files, i.e. no directories etc. */
|
||||||
|
/* if (!MY_S_ISREG(file->mystat->st_mode)) */
|
||||||
|
/* MY_S_ISREG does not work here on Windows, just skip directories */
|
||||||
|
if (MY_S_ISDIR(file->mystat->st_mode))
|
||||||
|
continue;
|
||||||
|
if (ds_wild.length &&
|
||||||
|
wild_compare(file->name, ds_wild.str, 0))
|
||||||
|
continue;
|
||||||
|
ds_file_to_remove.length= ds_directory.length + 1;
|
||||||
|
ds_file_to_remove.str[ds_directory.length + 1]= 0;
|
||||||
|
dynstr_append(&ds_file_to_remove, file->name);
|
||||||
|
DBUG_PRINT("info", ("removing file: %s", ds_file_to_remove.str));
|
||||||
|
error= my_delete(ds_file_to_remove.str, MYF(0)) != 0;
|
||||||
|
if (error)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
my_dirend(dir_info);
|
||||||
|
|
||||||
|
end:
|
||||||
|
handle_command_error(command, error);
|
||||||
|
dynstr_free(&ds_directory);
|
||||||
|
dynstr_free(&ds_wild);
|
||||||
|
dynstr_free(&ds_file_to_remove);
|
||||||
|
DBUG_VOID_RETURN;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
do_copy_file
|
do_copy_file
|
||||||
@ -7937,6 +8013,7 @@ int main(int argc, char **argv)
|
|||||||
case Q_ECHO: do_echo(command); command_executed++; break;
|
case Q_ECHO: do_echo(command); command_executed++; break;
|
||||||
case Q_SYSTEM: do_system(command); break;
|
case Q_SYSTEM: do_system(command); break;
|
||||||
case Q_REMOVE_FILE: do_remove_file(command); break;
|
case Q_REMOVE_FILE: do_remove_file(command); break;
|
||||||
|
case Q_REMOVE_FILES_WILDCARD: do_remove_files_wildcard(command); break;
|
||||||
case Q_MKDIR: do_mkdir(command); break;
|
case Q_MKDIR: do_mkdir(command); break;
|
||||||
case Q_RMDIR: do_rmdir(command); break;
|
case Q_RMDIR: do_rmdir(command); break;
|
||||||
case Q_LIST_FILES: do_list_files(command); break;
|
case Q_LIST_FILES: do_list_files(command); break;
|
||||||
|
@ -557,6 +557,7 @@ mysqltest: At line 2: Cannot run query on connection between send and reap
|
|||||||
select * from t1;;
|
select * from t1;;
|
||||||
drop table t1;
|
drop table t1;
|
||||||
mysqltest: At line 1: Missing required argument 'filename' to command 'remove_file'
|
mysqltest: At line 1: Missing required argument 'filename' to command 'remove_file'
|
||||||
|
mysqltest: At line 1: Missing required argument 'directory' to command 'remove_files_wildcard'
|
||||||
mysqltest: At line 1: Missing required argument 'filename' to command 'write_file'
|
mysqltest: At line 1: Missing required argument 'filename' to command 'write_file'
|
||||||
mysqltest: At line 1: End of file encountered before 'EOF' delimiter was found
|
mysqltest: At line 1: End of file encountered before 'EOF' delimiter was found
|
||||||
Content for test_file1
|
Content for test_file1
|
||||||
@ -784,6 +785,8 @@ mysqltest: At line 1: change user failed: Access denied for user 'root'@'localho
|
|||||||
file1.txt
|
file1.txt
|
||||||
file1.txt
|
file1.txt
|
||||||
file2.txt
|
file2.txt
|
||||||
|
file11.txt
|
||||||
|
dir-list.txt
|
||||||
SELECT 'c:\\a.txt' AS col;
|
SELECT 'c:\\a.txt' AS col;
|
||||||
col
|
col
|
||||||
z
|
z
|
||||||
|
@ -1717,6 +1717,19 @@ drop table t1;
|
|||||||
--error 1
|
--error 1
|
||||||
remove_file non_existing_file;
|
remove_file non_existing_file;
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# test for remove_files_wildcard
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
--error 1
|
||||||
|
--exec echo "remove_files_wildcard ;" | $MYSQL_TEST 2>&1
|
||||||
|
|
||||||
|
--error 1
|
||||||
|
remove_files_wildcard non_existing_dir;
|
||||||
|
|
||||||
|
--error 1
|
||||||
|
remove_files_wildcard non_existing_dir non_existing_file;
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# test for write_file
|
# test for write_file
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
@ -2384,9 +2397,14 @@ rmdir $MYSQLTEST_VARDIR/tmp/testdir;
|
|||||||
|
|
||||||
cat_file $MYSQLTEST_VARDIR/tmp/testdir/file3.txt;
|
cat_file $MYSQLTEST_VARDIR/tmp/testdir/file3.txt;
|
||||||
|
|
||||||
remove_file $MYSQLTEST_VARDIR/tmp/testdir/file1.txt;
|
list_files_write_file $MYSQLTEST_VARDIR/tmp/testdir/file11.txt $MYSQLTEST_VARDIR/tmp/testdir file?.txt;
|
||||||
remove_file $MYSQLTEST_VARDIR/tmp/testdir/file2.txt;
|
remove_files_wildcard $MYSQLTEST_VARDIR/tmp/testdir file?.txt;
|
||||||
remove_file $MYSQLTEST_VARDIR/tmp/testdir/file3.txt;
|
list_files_write_file $MYSQLTEST_VARDIR/tmp/testdir/dir-list.txt $MYSQLTEST_VARDIR/tmp/testdir file*.txt;
|
||||||
|
cat_file $MYSQLTEST_VARDIR/tmp/testdir/dir-list.txt;
|
||||||
|
remove_files_wildcard $MYSQLTEST_VARDIR/tmp/testdir file*.txt;
|
||||||
|
list_files $MYSQLTEST_VARDIR/tmp/testdir;
|
||||||
|
remove_files_wildcard $MYSQLTEST_VARDIR/tmp/testdir;
|
||||||
|
list_files $MYSQLTEST_VARDIR/tmp/testdir;
|
||||||
rmdir $MYSQLTEST_VARDIR/tmp/testdir;
|
rmdir $MYSQLTEST_VARDIR/tmp/testdir;
|
||||||
|
|
||||||
#
|
#
|
||||||
|
Reference in New Issue
Block a user