2004-12-30 16:34:01 +01:00
|
|
|
# -*- cperl -*-
|
|
|
|
|
|
|
|
# This is a library file used by the Perl version of mysql-test-run,
|
|
|
|
# and is part of the translation of the Bourne shell script with the
|
|
|
|
# same name.
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
sub mtr_full_hostname ();
|
2005-08-17 14:40:23 +02:00
|
|
|
sub mtr_short_hostname ();
|
2004-12-30 16:34:01 +01:00
|
|
|
sub mtr_init_args ($);
|
|
|
|
sub mtr_add_arg ($$);
|
2005-06-21 02:21:52 +02:00
|
|
|
sub mtr_path_exists(@);
|
|
|
|
sub mtr_script_exists(@);
|
|
|
|
sub mtr_exe_exists(@);
|
2006-03-08 19:15:56 +01:00
|
|
|
sub mtr_copy_dir($$);
|
|
|
|
sub mtr_same_opts($$);
|
|
|
|
sub mtr_cmp_opts($$);
|
2004-12-30 16:34:01 +01:00
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Misc
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
# We want the fully qualified host name and hostname() may have returned
|
|
|
|
# only the short name. So we use the resolver to find out.
|
2005-08-17 14:40:23 +02:00
|
|
|
# Note that this might fail on some platforms
|
2004-12-30 16:34:01 +01:00
|
|
|
|
|
|
|
sub mtr_full_hostname () {
|
|
|
|
|
|
|
|
my $hostname= hostname();
|
|
|
|
if ( $hostname !~ /\./ )
|
|
|
|
{
|
|
|
|
my $address= gethostbyname($hostname)
|
2005-06-05 20:10:47 +02:00
|
|
|
or mtr_error("Couldn't resolve $hostname : $!");
|
2004-12-30 16:34:01 +01:00
|
|
|
my $fullname= gethostbyaddr($address, AF_INET);
|
|
|
|
$hostname= $fullname if $fullname;
|
|
|
|
}
|
|
|
|
return $hostname;
|
|
|
|
}
|
|
|
|
|
2005-08-17 14:40:23 +02:00
|
|
|
sub mtr_short_hostname () {
|
|
|
|
|
|
|
|
my $hostname= hostname();
|
|
|
|
$hostname =~ s/\..+$//;
|
|
|
|
return $hostname;
|
|
|
|
}
|
|
|
|
|
2004-12-30 16:34:01 +01:00
|
|
|
# FIXME move to own lib
|
|
|
|
|
|
|
|
sub mtr_init_args ($) {
|
|
|
|
my $args = shift;
|
|
|
|
$$args = []; # Empty list
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mtr_add_arg ($$) {
|
|
|
|
my $args= shift;
|
|
|
|
my $format= shift;
|
|
|
|
my @fargs = @_;
|
|
|
|
|
|
|
|
push(@$args, sprintf($format, @fargs));
|
|
|
|
}
|
|
|
|
|
2005-06-21 02:21:52 +02:00
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
sub mtr_path_exists (@) {
|
|
|
|
foreach my $path ( @_ )
|
|
|
|
{
|
|
|
|
return $path if -e $path;
|
|
|
|
}
|
|
|
|
if ( @_ == 1 )
|
|
|
|
{
|
|
|
|
mtr_error("Could not find $_[0]");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mtr_error("Could not find any of " . join(" ", @_));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mtr_script_exists (@) {
|
|
|
|
foreach my $path ( @_ )
|
|
|
|
{
|
2006-08-25 10:11:15 +02:00
|
|
|
if($::glob_win32)
|
|
|
|
{
|
|
|
|
return $path if -f $path;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $path if -x $path;
|
|
|
|
}
|
2005-06-21 02:21:52 +02:00
|
|
|
}
|
|
|
|
if ( @_ == 1 )
|
|
|
|
{
|
|
|
|
mtr_error("Could not find $_[0]");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mtr_error("Could not find any of " . join(" ", @_));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mtr_exe_exists (@) {
|
2005-07-06 22:21:35 +02:00
|
|
|
my @path= @_;
|
|
|
|
map {$_.= ".exe"} @path if $::glob_win32;
|
|
|
|
foreach my $path ( @path )
|
2005-06-21 02:21:52 +02:00
|
|
|
{
|
2006-08-25 10:11:15 +02:00
|
|
|
if($::glob_win32)
|
|
|
|
{
|
|
|
|
return $path if -f $path;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $path if -x $path;
|
|
|
|
}
|
2005-06-21 02:21:52 +02:00
|
|
|
}
|
2005-07-06 22:21:35 +02:00
|
|
|
if ( @path == 1 )
|
2005-06-21 02:21:52 +02:00
|
|
|
{
|
2005-07-06 22:21:35 +02:00
|
|
|
mtr_error("Could not find $path[0]");
|
2005-06-21 02:21:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-06 22:21:35 +02:00
|
|
|
mtr_error("Could not find any of " . join(" ", @path));
|
2005-06-21 02:21:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-08 19:15:56 +01:00
|
|
|
sub mtr_copy_dir($$) {
|
|
|
|
my $srcdir= shift;
|
|
|
|
my $dstdir= shift;
|
|
|
|
|
|
|
|
# Create destination directory
|
|
|
|
mkpath($dstdir);
|
|
|
|
find(\&mtr_copy_one_file, $dstdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mtr_copy_one_file {
|
|
|
|
print $File::Find::name, "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mtr_same_opts ($$) {
|
|
|
|
my $l1= shift;
|
|
|
|
my $l2= shift;
|
|
|
|
return mtr_cmp_opts($l1,$l2) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mtr_cmp_opts ($$) {
|
|
|
|
my $l1= shift;
|
|
|
|
my $l2= shift;
|
|
|
|
|
|
|
|
my @l1= @$l1;
|
|
|
|
my @l2= @$l2;
|
|
|
|
|
|
|
|
return -1 if @l1 < @l2;
|
|
|
|
return 1 if @l1 > @l2;
|
|
|
|
|
|
|
|
while ( @l1 ) # Same length
|
|
|
|
{
|
|
|
|
my $e1= shift @l1;
|
|
|
|
my $e2= shift @l2;
|
|
|
|
my $cmp= ($e1 cmp $e2);
|
|
|
|
return $cmp if $cmp != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; # They are the same
|
|
|
|
}
|
2005-06-21 02:21:52 +02:00
|
|
|
|
2004-12-30 16:34:01 +01:00
|
|
|
1;
|