aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ Pipkin <j@dawnrazor.net>2013-01-03 01:20:41 -0600
committerJ Pipkin <j@dawnrazor.net>2013-01-03 01:20:41 -0600
commite2a88cd9c57c16552b7c72f4eb58b9a8d93954ac (patch)
tree8add4107e668152fe6bb91a45fba9150a8f05e26
parenta8866498912614b62205866cc8f237a0c704a8d9 (diff)
downloadsbotools2-e2a88cd9c57c16552b7c72f4eb58b9a8d93954ac.tar.xz
support other archive formats besides just tar
-rw-r--r--SBO-Lib/lib/SBO/Lib.pm17
-rwxr-xr-xt/test.t26
2 files changed, 22 insertions, 21 deletions
diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm
index d7b8e32..37c3b73 100644
--- a/SBO-Lib/lib/SBO/Lib.pm
+++ b/SBO-Lib/lib/SBO/Lib.pm
@@ -455,22 +455,23 @@ sub get_dl_fns ($) {
return $return;
}
-# given a line containing 'tar ', try to return a valid filename regex
-sub get_tar_regex ($) {
+# given a line that looks like it's decompressing something, try to return a
+# valid filename regex
+sub get_dc_regex {
my $line = shift;
# get rid of initial 'tar x'whatever stuff
- $line =~ s/^.*tar\s+[^\s]+\s+//;
+ $line =~ s/^.*(?<![a-z])(tar|p7zip|unzip|ar|rpm2cpio|sh)\s+[^\s]+\s+//;
# need to know preceeding character - should be safe to assume it's either
# a slash or a space
my $initial = $line =~ qr|/| ? '/' : ' ';
# get rid of initial path info
$line =~ s|^\$[^/]+/||;
- # get rid of anything excess at the end
- $line =~ s/\s*$//;
# convert any instances of command substitution to [^-]+
$line =~ s/\$\([^)]+\)/[^-]+/g;
# convert any bash variables to [^-]+
$line =~ s/\$({|)[A-Za-z0-9_]+(}|)/[^-]+/g;
+ # get rid of anything excess at the end
+ $line =~ s/\s+.*$//;
# fix .?z* at the end
$line =~ s/\.\?z\*/\.[a-z]z.*/;
# return what's left as a regex
@@ -494,7 +495,7 @@ sub rewrite_slackbuild {
die "Unable to backup $slackbuild to $slackbuild.orig\n";
my $libdir_regex = qr/^\s*LIBDIRSUFFIX="64"\s*$/;
my $arch_regex = qr/\$VERSION-\$ARCH-\$BUILD/;
- my $tar_regex = qr/tar\s+/;
+ my $dc_regex = qr/(?<![a-z])(tar|p7zip|unzip|ar|rpm2cpio|sh)\s+/;
# tie the slackbuild, because this is the easiest way to handle this.
tie my @sb_file, 'Tie::File', $slackbuild;
# if we're dealing with a compat32, we need to change the tar line(s) so
@@ -507,8 +508,8 @@ sub rewrite_slackbuild {
);
my $fns = get_dl_fns [keys %downloads];
for my $line (@sb_file) {
- if ($line =~ $tar_regex) {
- my ($regex, $initial) = get_tar_regex $line;
+ if ($line =~ $dc_regex) {
+ my ($regex, $initial) = get_dc_regex $line;
for my $fn (@$fns) {
$fn = "$initial$fn";
$line =~ s/$regex/$fn/ if $fn =~ $regex;
diff --git a/t/test.t b/t/test.t
index 0f2b371..0bb36ce 100755
--- a/t/test.t
+++ b/t/test.t
@@ -409,24 +409,24 @@ $fns = get_dl_fns $downloads;
is($$fns[0], 'VirtualBox-4.2.0.tar.bz2', 'get_dl_fns test, multiple inputs 01');
is($$fns[2], 'UserManual.pdf', 'get_dl_fns test, multiple inputs 02');
-# test get_tar_regex - multiple tests for various types of input
+# test get_dc_regex - multiple tests for various types of input
my $line = 'tar xvf $CWD/$PRGNAM-$VERSION.tar.?z*';
-my ($regex, $initial) = get_tar_regex $line;
-is($regex, '(?^u:/[^-]+-[^-]+.tar.[a-z]z.*)', 'get_tar_regex test 01.1');
-is($initial, '/', 'get_tar_regex test 01.2');
+my ($regex, $initial) = get_dc_regex $line;
+is($regex, '(?^u:/[^-]+-[^-]+.tar.[a-z]z.*)', 'get_dc_regex test 01.1');
+is($initial, '/', 'get_dc_regex test 01.2');
$line = 'tar xvf $CWD/Oracle_VM_VirtualBox_Extension_Pack-$VERSION.vbox-extpack';
-($regex, $initial) = get_tar_regex $line;
+($regex, $initial) = get_dc_regex $line;
is($regex, '(?^u:/Oracle_VM_VirtualBox_Extension_Pack-[^-]+.vbox-extpack)',
- 'get_tar_regex test 02.1');
-is($initial, '/', 'get_tar_regex test 02.2');
+ 'get_dc_regex test 02.1');
+is($initial, '/', 'get_dc_regex test 02.2');
$line = 'tar xvf $CWD/${PRGNAM}-source-$(echo $VERSION).tar.gz';
-($regex, $initial) = get_tar_regex $line;
-is($regex, '(?^u:/[^-]+-source-[^-]+.tar.gz)', 'get_tar_regex test 03.1');
-is($initial, '/', 'get_tar_regex test 03.2');
+($regex, $initial) = get_dc_regex $line;
+is($regex, '(?^u:/[^-]+-source-[^-]+.tar.gz)', 'get_dc_regex test 03.1');
+is($initial, '/', 'get_dc_regex test 03.2');
$line = '( tar xvf xapian-bindings-$VERSION.tar.gz';
-($regex, $initial) = get_tar_regex $line;
-is($regex, '(?^u: xapian-bindings-[^-]+.tar.gz)', 'get_tar_regex test 04.1');
-is($initial, ' ', 'get_tar_regex test 04.2');
+($regex, $initial) = get_dc_regex $line;
+is($regex, '(?^u: xapian-bindings-[^-]+.tar.gz)', 'get_dc_regex test 04.1');
+is($initial, ' ', 'get_dc_regex test 04.2');
# end of tests.
done_testing();