From f60837cbbdb1009dd5b388eb2cebc5a4ddb46e5e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 29 Aug 2007 11:51:34 +0200 Subject: 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' --- mysql-test/lib/mtr_misc.pl | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'mysql-test/lib') diff --git a/mysql-test/lib/mtr_misc.pl b/mysql-test/lib/mtr_misc.pl index ef7dda358f2..3da598faebc 100644 --- a/mysql-test/lib/mtr_misc.pl +++ b/mysql-test/lib/mtr_misc.pl @@ -5,6 +5,7 @@ # same name. use strict; +use File::Find; sub mtr_full_hostname (); sub mtr_short_hostname (); @@ -17,6 +18,7 @@ sub mtr_file_exists(@); sub mtr_exe_exists(@); sub mtr_exe_maybe_exists(@); sub mtr_copy_dir($$); +sub mtr_rmtree($$); sub mtr_same_opts($$); sub mtr_cmp_opts($$); @@ -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 ($$) { my $l1= shift; my $l2= shift; -- cgit v1.2.1