From: Ian Jackson Date: Mon, 27 Jul 2015 14:25:12 +0000 (+0100) Subject: Dgit.pm: Provide executable_on_path (avoids loading File::Which which is rather more... X-Git-Tag: debian/1.1~6 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=commitdiff_plain;h=9c93adb7d24891e392a1a0c3ad13ccd5fb57b6f1;hp=b05ac03be1310a28f0e236b907f96103f5537f0c Dgit.pm: Provide executable_on_path (avoids loading File::Which which is rather more heavyweight) (no callers yet) --- diff --git a/Debian/Dgit.pm b/Debian/Dgit.pm index a453f352..fce2ceb6 100644 --- a/Debian/Dgit.pm +++ b/Debian/Dgit.pm @@ -17,7 +17,8 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw(setup_sigwarn debiantag server_branch server_ref - stat_exists fail ensuredir waitstatusmsg failedcmd + stat_exists fail ensuredir executable_on_path + waitstatusmsg failedcmd cmdoutput cmdoutput_errok git_rev_parse git_get_ref git_for_each_ref git_for_each_tag_referring is_fast_fwd @@ -153,6 +154,17 @@ sub ensuredir ($) { die "mkdir $dir: $!"; } +sub executable_on_path ($) { + my ($program) = @_; + return 1 if $program =~ m{/}; + my @path = split /:/, ($ENV{PATH} // "/usr/local/bin:/bin:/usr/bin"); + foreach my $pe (@path) { + my $here = "$pe/$program"; + return $here if stat_exists $here && -x _; + } + return undef; +} + our @signames = split / /, $Config{sig_name}; sub waitstatusmsg () {