Changeset 204


Ignore:
Timestamp:
08/16/15 19:37:38 (9 years ago)
Author:
kdeugau
Message:

/trunk

Factor out the if() tree for extracting source files, and extend to
support bare .tar archives. Patch mostly by Andreas Scherer (aside from
a minor variable rename for local clarity by Kris Deugau):

Use the DRY principle by replacing redundant code sections with a single
function. This fixed at least one bug and prepares for future extensions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/debbuild

    r203 r204  
    4747
    4848sub expandmacros;
     49sub unpackcmd;
    4950
    5051# User's prefs for dirs, environment, etc,etc,etc.
     
    927928        if ($deftarball) {
    928929          $prepscript .= "cd '$tarballdir'\n" if $changedir;
    929           if ($pkgdata{main}{source} =~ /\.zip$/) {
    930             # .zip files are not really tarballs
    931             $prepscript .= "/usr/bin/unzip".
    932                 ( $quietunpack ? ' -qq ' : ' ' ).
    933                 "'$topdir/SOURCES/$pkgdata{main}{source}'";
    934           } else {
    935             $prepscript .=
    936                 ( $pkgdata{main}{source} =~ /\.(?:tgz|tar\.(?:gz|Z))$/   ? "/bin/gzip"   : "" ).
    937                 ( $pkgdata{main}{source} =~ /\.tar\.bz2$/                ? "/bin/bzip2"  : "" ).
    938                 ( $pkgdata{main}{source} =~ /\.tar\.xz$/                 ? "/usr/bin/xz" : "" ).
    939                 " -dc '$topdir/SOURCES/$pkgdata{main}{source}' | /bin/tar -x".
    940                 ( $quietunpack ? '' : 'vv' )."f - ";
    941           }
    942           $prepscript .= qq(\nSTATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n  exit \$STATUS\nfi\n);
     930          $prepscript .= unpackcmd($pkgdata{main}{source},$quietunpack);
    943931        }
    944932
     
    946934          if ($altsource == 1) { # -a
    947935            $prepscript .= "cd '$tarballdir'\n";
    948             if ($pkgdata{sources}{$snum} =~ /\.zip$/) {
    949               # .zip files are not really tarballs
    950               $prepscript .= "/usr/bin/unzip".
    951                 ( $quietunpack ? ' -qq ' : ' ' ).
    952                 "'$topdir/SOURCES/$pkgdata{sources}{$snum}'";
    953             } else {
    954               $prepscript .=
    955                 ( $pkgdata{sources}{$snum} =~ /\.(?:tgz|tar\.(?:gz|Z))$/ ? "/bin/gzip"   : "" ).
    956                 ( $pkgdata{sources}{$snum} =~ /\.tar\.bz2$/              ? "/bin/bzip2"  : "" ).
    957                 ( $pkgdata{sources}{$snum} =~ /\.tar\.xz$/               ? "/usr/bin/xz" : "" ).
    958                 " -dc '$topdir/SOURCES/$pkgdata{sources}{$snum}' | /bin/tar -x".
    959                 ( $quietunpack ? '' : 'vv' )."f -";
    960             }
    961             $prepscript .= qq(\nSTATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n  exit \$STATUS\nfi\n);
     936            $prepscript .= unpackcmd($pkgdata{sources}{$snum},$quietunpack);
    962937          } # $altsource == 1
    963938
    964939          if ($altsource == 2) { # -b
    965             if ($pkgdata{sources}{$snum} =~ /\.zip$/) {
    966               # .zip files are not really tarballs
    967               $prepscript .= "/usr/bin/unzip".
    968                 ( $quietunpack ? ' -qq ' : ' ' ).
    969                 "'$topdir/SOURCES/$pkgdata{main}{source}'";
    970             } else {
    971               $prepscript .=
    972                 ( $pkgdata{sources}{$snum} =~ /\.(?:tgz|tar\.(?:gz|Z))$/  ? "/bin/gzip"   : "" ).
    973                 ( $pkgdata{sources}{$snum} =~ /\.tar\.bz2$/               ? "/bin/bzip2"  : "" ).
    974                 ( $pkgdata{sources}{$snum} =~ /\.tar\.xz$/                ? "/usr/bin/xz" : "" ).
    975                 " -dc '$topdir/SOURCES/$pkgdata{sources}{$snum}' | /bin/tar -x".
    976                 ( $quietunpack ? '' : 'vv' )."f -";
    977             }
    978             $prepscript .= qq(\nSTATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n  exit \$STATUS\nfi\n);
     940            $prepscript .= unpackcmd($pkgdata{sources}{$snum},$quietunpack);
    979941            $prepscript .= "cd '$tarballdir'\n";
    980942          } # $altsource == 2
     
    20742036
    20752037
     2038## unpackcmd()
     2039# Prepare the necessary commands for uncompressing and extracting the content
     2040# of the source drop according to the file extension.
     2041sub unpackcmd {
     2042   my ($sourcedrop,$quietunpack) = @_;
     2043   my $cmdstring;
     2044
     2045   if ($sourcedrop =~ /\.zip$/) {
     2046      # .zip files are not really tarballs
     2047      $cmdstring .= "/usr/bin/unzip".
     2048         ( $quietunpack ? ' -qq ' : ' ' ).
     2049         "'$topdir/SOURCES/$sourcedrop'";
     2050   } elsif ($sourcedrop =~ /\.tar$/) {
     2051      # plain .tar files don't need to be uncompressed
     2052      $cmdstring .= "/bin/tar -x".
     2053         ( $quietunpack ? '' : 'vv' )."f ".
     2054         "'$topdir/SOURCES/$sourcedrop'";
     2055   } else {
     2056      # select the decompressor according to the file extension
     2057      $cmdstring .=
     2058         ( $sourcedrop =~ /\.(?:tgz|tar\.(?:gz|Z))$/ ? "/bin/gzip"   :
     2059           $sourcedrop =~ /\.tar\.bz2$/              ? "/bin/bzip2"  :
     2060           $sourcedrop =~ /\.tar\.xz$/               ? "/usr/bin/xz" :
     2061           die("Can't handle unknown file type '$sourcedrop'.") ).
     2062         " -dc '$topdir/SOURCES/$sourcedrop' | /bin/tar -x".
     2063         ( $quietunpack ? '' : 'vv' )."f - ";
     2064   }
     2065   $cmdstring .= qq(\nSTATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n  exit \$STATUS\nfi\n);
     2066
     2067   return $cmdstring;
     2068} # end unpackcmd()
     2069
    20762070
    20772071__END__
Note: See TracChangeset for help on using the changeset viewer.