2
# Copyright (C) 2004-2006 MySQL AB
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
# This is a library file used by the Perl version of mysql-test-run,
18
# and is part of the translation of the Bourne shell script with the
24
sub mtr_native_path($);
25
sub mtr_init_args ($);
26
sub mtr_add_arg ($$@);
27
sub mtr_path_exists(@);
28
sub mtr_script_exists(@);
29
sub mtr_file_exists(@);
30
sub mtr_exe_exists(@);
31
sub mtr_exe_maybe_exists(@);
34
sub mtr_same_opts($$);
37
##############################################################################
41
##############################################################################
43
# Convert path to OS native format
44
sub mtr_native_path($)
48
# MySQL version before 5.0 still use cygwin, no need
51
if ($::mysql_version_id < 50000);
59
# FIXME move to own lib
61
sub mtr_init_args ($) {
63
$$args = []; # Empty list
66
sub mtr_add_arg ($$@) {
71
push(@$args, sprintf($format, @fargs));
74
##############################################################################
77
# NOTE! More specific paths should be given before less specific.
78
# For example /client/debug should be listed before /client
80
sub mtr_path_exists (@) {
81
foreach my $path ( @_ )
83
return $path if -e $path;
87
mtr_error("Could not find $_[0]");
91
mtr_error("Could not find any of " . join(" ", @_));
97
# NOTE! More specific paths should be given before less specific.
98
# For example /client/debug should be listed before /client
100
sub mtr_script_exists (@) {
101
foreach my $path ( @_ )
105
return $path if -f $path;
109
return $path if -x $path;
114
mtr_error("Could not find $_[0]");
118
mtr_error("Could not find any of " . join(" ", @_));
124
# NOTE! More specific paths should be given before less specific.
125
# For example /client/debug should be listed before /client
127
sub mtr_file_exists (@) {
128
foreach my $path ( @_ )
130
return $path if -e $path;
137
# NOTE! More specific paths should be given before less specific.
138
# For example /client/debug should be listed before /client
140
sub mtr_exe_maybe_exists (@) {
143
map {$_.= ".exe"} @path if $::glob_win32;
144
map {$_.= ".nlm"} @path if $::glob_netware;
145
foreach my $path ( @path )
149
return $path if -f $path;
153
return $path if -x $path;
161
# NOTE! More specific paths should be given before less specific.
162
# For example /client/debug should be listed before /client
164
sub mtr_exe_exists (@) {
166
if (my $path= mtr_exe_maybe_exists(@path))
170
# Could not find exe, show error
173
mtr_error("Could not find $path[0]");
177
mtr_error("Could not find any of " . join(" ", @path));
182
sub mtr_copy_dir($$) {
186
# mtr_verbose("Copying from $from_dir to $to_dir");
189
opendir(DIR, "$from_dir")
190
or mtr_error("Can't find $from_dir$!");
192
next if "$_" eq "." or "$_" eq "..";
193
if ( -d "$from_dir/$_" )
195
mtr_copy_dir("$from_dir/$_", "$to_dir/$_");
198
copy("$from_dir/$_", "$to_dir/$_");
207
mtr_verbose("mtr_rmtree: $dir");
209
# Try to use File::Path::rmtree. Recent versions
210
# handles removal of directories and files that don't
211
# have full permissions, while older versions
212
# may have a problem with that and we use our own version
214
eval { rmtree($dir); };
216
mtr_warning("rmtree($dir) failed, trying with File::Find...");
225
or mtr_warning("couldn't chmod(0777, $_): $!") and $errors++;
236
# Use special underscore (_) filehandle, caches stat info
237
if (!-l $file and -d _ ) {
239
mtr_warning("couldn't rmdir($file): $!") and $errors++;
242
or mtr_warning("couldn't unlink($file): $!") and $errors++;
249
mtr_error("Failed to remove '$dir'") if $errors;
251
mtr_report("OK, that worked!");
256
sub mtr_same_opts ($$) {
259
return mtr_cmp_opts($l1,$l2) == 0;
262
sub mtr_cmp_opts ($$) {
269
return -1 if @l1 < @l2;
270
return 1 if @l1 > @l2;
272
while ( @l1 ) # Same length
276
my $cmp= ($e1 cmp $e2);
277
return $cmp if $cmp != 0;
280
return 0; # They are the same
284
# Compare two arrays and put all unequal elements into a new one
286
sub mtr_diff_opts ($$) {
291
foreach my $e1 (@$l1)
294
foreach my $e2 (@$l2)
296
$f= 1 unless ($e1 ne $e2);
298
push(@$l, $e1) unless (defined $f);
300
foreach my $e2 (@$l2)
303
foreach my $e1 (@$l1)
305
$f= 1 unless ($e1 ne $e2);
307
push(@$l, $e2) unless (defined $f);