Skip to content

Commit 7181ef5

Browse files
Upgraded Archive::Extract to 0.80
Closes https://github.com/elastic/infra/issues/1913
1 parent b48e5cb commit 7181ef5

File tree

1 file changed

+44
-7
lines changed
  • dev-tools/src/main/resources/license-check/lib/Archive

1 file changed

+44
-7
lines changed

dev-tools/src/main/resources/license-check/lib/Archive/Extract.pm

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use vars qw[$VERSION $PREFER_BIN $PROGRAMS $WARN $DEBUG
4848
$_ALLOW_BIN $_ALLOW_PURE_PERL $_ALLOW_TAR_ITER
4949
];
5050

51-
$VERSION = '0.76';
51+
$VERSION = '0.80';
5252
$PREFER_BIN = 0;
5353
$WARN = 1;
5454
$DEBUG = 0;
@@ -60,6 +60,7 @@ $_ALLOW_TAR_ITER = 1; # try to use Archive::Tar->iter if available
6060
my @Types = ( TGZ, TAR, GZ, ZIP, BZ2, TBZ, Z, LZMA, XZ, TXZ );
6161

6262
local $Params::Check::VERBOSE = $Params::Check::VERBOSE = 1;
63+
local $Module::Load::Conditional::FORCE_SAFE_INC = 1;
6364

6465
=pod
6566
@@ -134,16 +135,14 @@ CMD: for my $pgm (qw[tar unzip gzip bunzip2 uncompress unlzma unxz]) {
134135
$PROGRAMS->{$pgm} = $unzip;
135136
next CMD;
136137
}
137-
if ( $pgm eq 'unzip' and ( ON_NETBSD or ON_FREEBSD ) ) {
138+
if ( $pgm eq 'unzip' and ( ON_FREEBSD || ON_LINUX ) ) {
138139
local $IPC::Cmd::INSTANCES = 1;
139-
($PROGRAMS->{$pgm}) = grep { ON_NETBSD ? m!/usr/pkg/! : m!/usr/local! } can_run($pgm);
140+
($PROGRAMS->{$pgm}) = grep { _is_infozip_esque($_) } can_run($pgm);
140141
next CMD;
141142
}
142-
if ( $pgm eq 'unzip' and ON_LINUX ) {
143-
# Check if 'unzip' is busybox masquerading
143+
if ( $pgm eq 'unzip' and ON_NETBSD ) {
144144
local $IPC::Cmd::INSTANCES = 1;
145-
my $opt = ON_VMS ? '"-Z"' : '-Z';
146-
($PROGRAMS->{$pgm}) = grep { scalar run(command=> [ $_, $opt, '-1' ]) } can_run($pgm);
145+
($PROGRAMS->{$pgm}) = grep { m!/usr/pkg/! } can_run($pgm);
147146
next CMD;
148147
}
149148
if ( $pgm eq 'tar' and ( ON_OPENBSD || ON_SOLARIS || ON_NETBSD ) ) {
@@ -1503,6 +1502,44 @@ sub _unlzma_cz {
15031502
return 1;
15041503
}
15051504

1505+
#####################################
1506+
#
1507+
# unzip heuristics for FreeBSD-alikes
1508+
#
1509+
#####################################
1510+
1511+
sub _is_infozip_esque {
1512+
my $unzip = shift;
1513+
1514+
my @strings;
1515+
my $buf = '';
1516+
1517+
{
1518+
open my $file, '<', $unzip or die "$!\n";
1519+
binmode $file;
1520+
local $/ = \1;
1521+
local $_;
1522+
while(<$file>) {
1523+
if ( m![[:print:]]! ) {
1524+
$buf .= $_;
1525+
next;
1526+
}
1527+
if ( $buf and m![^[:print:]]! ) {
1528+
push @strings, $buf if length $buf >= 4;
1529+
$buf = '';
1530+
next;
1531+
}
1532+
}
1533+
}
1534+
push @strings, $buf if $buf;
1535+
foreach my $part ( @strings ) {
1536+
if ( $part =~ m!ZIPINFO! or $part =~ m!usage:.+?Z1! ) {
1537+
return $unzip;
1538+
}
1539+
}
1540+
return;
1541+
}
1542+
15061543
#################################
15071544
#
15081545
# Error code

0 commit comments

Comments
 (0)