Commit 038df2d0 authored by unknown's avatar unknown

Add 'mtr_rmtree'


mysql-test/lib/mtr_misc.pl:
  Add function 'mtr_rmtree' it will try 'rmtree' and if that fails (most likely
  due to permission problems we will fun File::find to chmod all files and dirs
  to 0777 and then delete.
mysql-test/mysql-test-run.pl:
  Use 'mtr_rmtree' in favour of 'rmtree'
parent d2037482
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# same name. # same name.
use strict; use strict;
use File::Find;
sub mtr_full_hostname (); sub mtr_full_hostname ();
sub mtr_short_hostname (); sub mtr_short_hostname ();
...@@ -17,6 +18,7 @@ sub mtr_file_exists(@); ...@@ -17,6 +18,7 @@ sub mtr_file_exists(@);
sub mtr_exe_exists(@); sub mtr_exe_exists(@);
sub mtr_exe_maybe_exists(@); sub mtr_exe_maybe_exists(@);
sub mtr_copy_dir($$); sub mtr_copy_dir($$);
sub mtr_rmtree($$);
sub mtr_same_opts($$); sub mtr_same_opts($$);
sub mtr_cmp_opts($$); sub mtr_cmp_opts($$);
...@@ -202,6 +204,64 @@ sub mtr_copy_dir($$) { ...@@ -202,6 +204,64 @@ sub mtr_copy_dir($$) {
} }
sub mtr_rmtree($) {
my ($dir)= @_;
my $need_file_find= 0;
mtr_verbose("mtr_rmtree: $dir");
{
# Try to use File::Path::rmtree. Recent versions
# handles removal of directories and files that don't
# have full permissions, while older versions
# may have a problem with that and we use our own version
local $SIG{__WARN__}= sub {
$need_file_find= 1;
mtr_warning($_[0]);
};
rmtree($dir);
}
if ( $need_file_find ) {
mtr_warning("rmtree($dir) failed, trying with File::Find...");
my $errors= 0;
# chmod
find( {
no_chdir => 1,
wanted => sub {
chmod(0777, $_)
or mtr_warning("couldn't chmod(0777, $_): $!") and $errors++;
}
},
$dir
);
# rm
finddepth( {
no_chdir => 1,
wanted => sub {
my $file= $_;
# Use special underscore (_) filehandle, caches stat info
if (!-l $file and -d _ ) {
rmdir($file) or
mtr_warning("couldn't rmdir($file): $!") and $errors++;
} else {
unlink($file)
or mtr_warning("couldn't unlink($file): $!") and $errors++;
}
}
},
$dir
);
mtr_error("Failed to remove '$dir'") if $errors;
mtr_report("OK, that worked!");
}
}
sub mtr_same_opts ($$) { sub mtr_same_opts ($$) {
my $l1= shift; my $l1= shift;
my $l2= shift; my $l2= shift;
......
...@@ -1988,7 +1988,7 @@ sub remove_stale_vardir () { ...@@ -1988,7 +1988,7 @@ sub remove_stale_vardir () {
{ {
# Remove the directory which the link points at # Remove the directory which the link points at
mtr_verbose("Removing " . readlink($opt_vardir)); mtr_verbose("Removing " . readlink($opt_vardir));
rmtree(readlink($opt_vardir)); mtr_rmtree(readlink($opt_vardir));
# Remove the "var" symlink # Remove the "var" symlink
mtr_verbose("unlink($opt_vardir)"); mtr_verbose("unlink($opt_vardir)");
...@@ -2016,7 +2016,7 @@ sub remove_stale_vardir () { ...@@ -2016,7 +2016,7 @@ sub remove_stale_vardir () {
foreach my $bin ( glob("$opt_vardir/*") ) foreach my $bin ( glob("$opt_vardir/*") )
{ {
mtr_verbose("Removing bin $bin"); mtr_verbose("Removing bin $bin");
rmtree($bin); mtr_rmtree($bin);
} }
} }
} }
...@@ -2024,7 +2024,7 @@ sub remove_stale_vardir () { ...@@ -2024,7 +2024,7 @@ sub remove_stale_vardir () {
{ {
# Remove the entire "var" dir # Remove the entire "var" dir
mtr_verbose("Removing $opt_vardir/"); mtr_verbose("Removing $opt_vardir/");
rmtree("$opt_vardir/"); mtr_rmtree("$opt_vardir/");
} }
if ( $opt_mem ) if ( $opt_mem )
...@@ -2033,7 +2033,7 @@ sub remove_stale_vardir () { ...@@ -2033,7 +2033,7 @@ sub remove_stale_vardir () {
# remove the $opt_mem dir to assure the symlink # remove the $opt_mem dir to assure the symlink
# won't point at an old directory # won't point at an old directory
mtr_verbose("Removing $opt_mem"); mtr_verbose("Removing $opt_mem");
rmtree($opt_mem); mtr_rmtree($opt_mem);
} }
} }
...@@ -2046,11 +2046,11 @@ sub remove_stale_vardir () { ...@@ -2046,11 +2046,11 @@ sub remove_stale_vardir () {
# Remove the var/ dir in mysql-test dir if any # Remove the var/ dir in mysql-test dir if any
# this could be an old symlink that shouldn't be there # this could be an old symlink that shouldn't be there
mtr_verbose("Removing $default_vardir"); mtr_verbose("Removing $default_vardir");
rmtree($default_vardir); mtr_rmtree($default_vardir);
# Remove the "var" dir # Remove the "var" dir
mtr_verbose("Removing $opt_vardir/"); mtr_verbose("Removing $opt_vardir/");
rmtree("$opt_vardir/"); mtr_rmtree("$opt_vardir/");
} }
} }
...@@ -2963,7 +2963,7 @@ sub restore_slave_databases ($) { ...@@ -2963,7 +2963,7 @@ sub restore_slave_databases ($) {
{ {
my $data_dir= $slave->[$idx]->{'path_myddir'}; my $data_dir= $slave->[$idx]->{'path_myddir'};
my $name= basename($data_dir); my $name= basename($data_dir);
rmtree($data_dir); mtr_rmtree($data_dir);
mtr_copy_dir("$path_snapshot/$name", $data_dir); mtr_copy_dir("$path_snapshot/$name", $data_dir);
} }
} }
...@@ -3310,7 +3310,7 @@ sub run_testcase ($) { ...@@ -3310,7 +3310,7 @@ sub run_testcase ($) {
sub save_installed_db () { sub save_installed_db () {
mtr_report("Saving snapshot of installed databases"); mtr_report("Saving snapshot of installed databases");
rmtree($path_snapshot); mtr_rmtree($path_snapshot);
foreach my $data_dir (@data_dir_lst) foreach my $data_dir (@data_dir_lst)
{ {
...@@ -3357,7 +3357,7 @@ sub restore_installed_db ($) { ...@@ -3357,7 +3357,7 @@ sub restore_installed_db ($) {
{ {
my $name= basename($data_dir); my $name= basename($data_dir);
save_files_before_restore($test_name, $data_dir); save_files_before_restore($test_name, $data_dir);
rmtree("$data_dir"); mtr_rmtree("$data_dir");
mtr_copy_dir("$path_snapshot/$name", "$data_dir"); mtr_copy_dir("$path_snapshot/$name", "$data_dir");
} }
...@@ -3367,7 +3367,7 @@ sub restore_installed_db ($) { ...@@ -3367,7 +3367,7 @@ sub restore_installed_db ($) {
{ {
foreach my $ndbd (@{$cluster->{'ndbds'}}) foreach my $ndbd (@{$cluster->{'ndbds'}})
{ {
rmtree("$ndbd->{'path_fs'}" ); mtr_rmtree("$ndbd->{'path_fs'}" );
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment