chiark / gitweb /
Dgit.pm: Provide executable_on_path (avoids loading File::Which which is rather more...
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 27 Jul 2015 14:25:12 +0000 (15:25 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 27 Jul 2015 14:25:12 +0000 (15:25 +0100)
Debian/Dgit.pm

index a453f35..fce2ceb 100644 (file)
@@ -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 () {