1
0
mirror of synced 2026-01-13 15:17:30 +00:00

Use File::Which instead of findBinary or which

This commit is contained in:
Axel Beckert 2013-07-11 00:39:05 +02:00
parent b271bf6a63
commit 9c47e5da4f
5 changed files with 15 additions and 49 deletions

View File

@ -174,9 +174,6 @@ Bugs to fix and features to add for 5.0
distributions the same. Currently Debian is a special case and
Ubuntu half a special case.
* Replace findBinary() and backticked calls to `which` (e.g. in
xt-guess-suite-and-mirror) with File::Which)
* Remove from the (unused) Xen::Tools what's already in the used
Xen::Tools::Common.

View File

@ -1151,7 +1151,7 @@ E_O_ERROR
foreach my $bin (@required)
{
if ( !defined( findBinary($bin) ) )
if ( !defined( which($bin) ) )
{
logprint( "The script '$bin' was not found.\nAborting\n\n" );
$CONFIG{'FAIL'} = 1;
@ -2274,7 +2274,7 @@ sub checkBinariesPresent
foreach my $file (@required)
{
if ( !defined( findBinary($file) ) )
if ( !defined( which($file) ) )
{
logprint("The following binary is required to run this tool\n");
logprint("\t$file\n");
@ -2290,7 +2290,7 @@ sub checkBinariesPresent
{
# loopback image
if ( !defined( findBinary("dd") ) )
if ( !defined( which("dd") ) )
{
logprint("The following binary is required to run this tool\n");
logprint("\tdd\n");
@ -2311,7 +2311,7 @@ sub checkBinariesPresent
foreach my $file (@evms)
{
if ( !defined( findBinary($file) ) )
if ( !defined( which($file) ) )
{
logprint("The following binary is required to run this tool\n");
logprint("\t$file\n");
@ -2331,7 +2331,7 @@ sub checkBinariesPresent
foreach my $file (@lvm)
{
if ( !defined( findBinary($file) ) )
if ( !defined( which($file) ) )
{
logprint("The following binary is required to run this tool\n");
logprint("\t$file\n");
@ -3305,7 +3305,7 @@ sub createFilesystem
#
my ($binary, $args) = split(/ /, $command, 2);
if ( !defined( findBinary($binary) ) )
if ( !defined( which($binary) ) )
{
logprint(
"The binary '$binary' required to create the filesystem $fs is missing\n"

View File

@ -69,6 +69,7 @@ my @sources_list_files = ( '/etc/apt/sources.list',
use File::Slurp;
use Getopt::Long;
use Pod::Usage;
use File::Which;
use strict;
@ -148,10 +149,8 @@ all_sources_list_files: foreach my $sources_list_file (@sources_list_files) {
die "Couldn't find a useful entry in the sources.list files of the Dom0. Tried:\n ".
join("\n ", @sources_list_files)."\n" unless $found;
my $lsb_release = `which lsb_release`;
chomp($lsb_release);
if (!$found and $lsb_release and -x $lsb_release) {
my $lsb_release = which('lsb_release');
if (!$found and defined($lsb_release) and -x $lsb_release) {
my $vendor = `$lsb_release -s -i`;
if ($vendor eq 'Debian' or $vendor eq 'Ubuntu') {

3
debian/changelog vendored
View File

@ -27,7 +27,8 @@ xen-tools (4.4~dev-1) UNRELEASED; urgency=low
but not debootstrap (Thanks Elmar Heeb!)
- Makefile accepts DESTDIR=…
- Move examples from debian/examples to examples.
- Uses File::Which, added (build-) dependency on libfile-which-perl
- Uses File::Which exclusively (no more findBinary, no more `which`),
added (build-) dependency on libfile-which-perl
- Knows about module-init-tools → kmod transition in wheezy/raring.
- Adds default mount options for ext4, identical to ext2/ext3.
- Ships /etc/initramfs-tools/conf.d/xen-tools for generating Dom0

View File

@ -20,9 +20,10 @@ use Exporter 'import';
use vars qw(@EXPORT_OK @EXPORT);
use English;
use File::Which;
@EXPORT = qw(readConfigurationFile xenRunning runCommand setupAdminUsers
findXenToolstack findBinary
findXenToolstack
logprint_with_config logonly_with_config fail_with_config);
=head1 FUNCTIONS
@ -139,38 +140,6 @@ 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
@ -192,12 +161,12 @@ sub findXenToolstack
return $toolstack if $toolstack;
}
my $xm = findBinary('xm');
my $xm = which('xm');
if ($xm and system("$xm list >/dev/null 2>/dev/null") == 0) {
return $xm;
}
my $xl = findBinary('xl');
my $xl = which('xl');
if ($xl and system("$xl list >/dev/null 2>/dev/null") == 0) {
return $xl;
}