Skip to content

Commit

Permalink
for .src.rpm files properly identify missing utils #869
Browse files Browse the repository at this point in the history
Also fix latent bug in external_utility_exists() for
the secondary case of using 'which' -- need to strip
args from supplied exe first.
  • Loading branch information
AlDanial committed Nov 18, 2024
1 parent fd8d789 commit 0fea167
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Unix/cloc
Original file line number Diff line number Diff line change
Expand Up @@ -13857,7 +13857,7 @@ sub uncompress_archive_cmd { # {{{1
$missing = "rpm2cpio";
}
} else {
$missing = "bzip2";
$missing = "cpio";
}
} elsif ($archive_file =~ /\.(whl|zip)$/i and !$ON_WINDOWS) {
if (external_utility_exists("unzip")) {
Expand Down Expand Up @@ -13930,13 +13930,17 @@ sub read_list_file { # {{{1
sub external_utility_exists { # {{{1
my $exe = shift @_;

# remove args, if any
my $leading_exe = $exe;
$leading_exe =~ s/^(\S+)\s*.*?$/$1/;

my $success = 0;
if ($ON_WINDOWS) {
$success = 1 unless system $exe . ' > nul';
} else {
$success = 1 unless system $exe . ' >/dev/null 2>&1';
if (!$success) {
$success = 1 unless system "which" . " $exe" . ' >/dev/null 2>&1';
$success = 1 unless system "which" . " $leading_exe" . ' >/dev/null 2>&1';
}
}

Expand Down
8 changes: 6 additions & 2 deletions cloc
Original file line number Diff line number Diff line change
Expand Up @@ -13847,7 +13847,7 @@ sub uncompress_archive_cmd { # {{{1
$missing = "rpm2cpio";
}
} else {
$missing = "bzip2";
$missing = "cpio";
}
} elsif ($archive_file =~ /\.(whl|zip)$/i and !$ON_WINDOWS) {
if (external_utility_exists("unzip")) {
Expand Down Expand Up @@ -13920,13 +13920,17 @@ sub read_list_file { # {{{1
sub external_utility_exists { # {{{1
my $exe = shift @_;

# remove args, if any
my $leading_exe = $exe;
$leading_exe =~ s/^(\S+)\s*.*?$/$1/;

my $success = 0;
if ($ON_WINDOWS) {
$success = 1 unless system $exe . ' > nul';
} else {
$success = 1 unless system $exe . ' >/dev/null 2>&1';
if (!$success) {
$success = 1 unless system "which" . " $exe" . ' >/dev/null 2>&1';
$success = 1 unless system "which" . " $leading_exe" . ' >/dev/null 2>&1';
}
}

Expand Down

0 comments on commit 0fea167

Please sign in to comment.