diff --git a/TODO.markdown b/TODO.markdown index 131c3ed..6c9d7e2 100644 --- a/TODO.markdown +++ b/TODO.markdown @@ -218,3 +218,5 @@ Axel's Break-Backwards-Compatibility Wishlist * Uncouple generating auto start symlinks from `--boot`. Maybe add some `--autostart` or such. + +* Maybe replace findBinary with File::Which diff --git a/bin/xen-create-image b/bin/xen-create-image index 12f7922..2df0070 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -4006,38 +4006,6 @@ sub generatePassword { } -=begin doc - - Find the location of the specified binary on the curent user's PATH. - - Return undef if the named binary isn't found. - -=end doc - -=cut - -sub findBinary -{ - my ($bin) = (@_); - - # strip any path which might be present. - $bin = $2 if ( $bin =~ /(.*)[\/\\](.*)/ ); - - foreach my $entry ( split( /:/, $ENV{ 'PATH' } ) ) - { - - # guess of location. - my $guess = $entry . "/" . $bin; - - # return it if it exists and is executable - return $guess if ( -e $guess && -x $guess ); - } - - return undef; -} - - - =begin doc Unmount any mount-points which are below the given path. diff --git a/lib/Xen/Tools/Common.pm b/lib/Xen/Tools/Common.pm index 7f3d0b3..5d5eeda 100644 --- a/lib/Xen/Tools/Common.pm +++ b/lib/Xen/Tools/Common.pm @@ -21,7 +21,8 @@ use vars qw(@EXPORT_OK @EXPORT); use English; @EXPORT = qw(readConfigurationFile xenRunning runCommand setupAdminUsers - findXenToolstack logprint_with_config logonly_with_config fail_with_config); + findXenToolstack findBinary + logprint_with_config logonly_with_config fail_with_config); =head1 FUNCTIONS @@ -137,6 +138,38 @@ sub xenRunning ($$) return ($running); } +=head2 findBinary + +=begin doc + + Find the location of the specified binary on the curent user's PATH. + + Return undef if the named binary isn't found. + +=end doc + +=cut + +sub findBinary +{ + my ($bin) = (@_); + + # strip any path which might be present. + $bin = $2 if ( $bin =~ /(.*)[\/\\](.*)/ ); + + foreach my $entry ( split( /:/, $ENV{ 'PATH' } ) ) + { + + # guess of location. + my $guess = $entry . "/" . $bin; + + # return it if it exists and is executable + return $guess if ( -e $guess && -x $guess ); + } + + return undef; +} + =head2 findXenToolstack =begin doc