fedora-rpmdevtools fedora-extract, 1.1, 1.2 fedora-rpmdevtools.spec, 1.88, 1.89

Ville Skytta (scop) fedora-extras-commits at redhat.com
Thu Feb 9 19:29:18 UTC 2006


Author: scop

Update of /cvs/fedora/fedora-rpmdevtools
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv23778

Modified Files:
	fedora-extract fedora-rpmdevtools.spec 
Log Message:
* Thu Feb  9 2006 Ville Skyttä <ville.skytta at iki.fi>
- Add file(1) based archive type detection to fedora-extract.



Index: fedora-extract
===================================================================
RCS file: /cvs/fedora/fedora-rpmdevtools/fedora-extract,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- fedora-extract	7 Oct 2004 19:05:03 -0000	1.1
+++ fedora-extract	9 Feb 2006 19:29:10 -0000	1.2
@@ -8,11 +8,12 @@
 # License: GPL
 # $Id$
 
-# TODO: *.arc
-# TODO: file(1) archive type detection
+# TODO: more archive types
 
 set -e
 unset CDPATH
+ftype=
+decomp=
 quiet=
 force=
 dir=
@@ -25,80 +26,109 @@
     echo "  -C dir    Change to directory 'dir' before extracting."
 }
 
+fmime()
+{
+    case "$1" in
+        application/x-zip|application/zip)                  ftype=zip  ;;
+        application/x-tar*)                                 ftype=tar  ;;
+        application/x-rpm)                                  ftype=rpm  ;;
+        application/x-archive|application/x-debian-package) ftype=ar   ;;
+        application/x-arj)                                  ftype=arj  ;;
+        application/x-zoo)                                  ftype=zoo  ;;
+        application/x-lha*)                                 ftype=lha  ;;
+        application/x-rar)                                  ftype=rar  ;;
+    esac
+}
+
+ftype()
+{
+    t=`file -ibL "$1" 2>/dev/null`
+    fmime "$t"
+    [ -n "$ftype" ] && return
+
+    case "$t" in
+        application/x-compress|application/x-gzip)  decomp="gzip -dc"  ;;
+        application/x-bzip2)                        decomp="bzip2 -dc" ;;
+    esac
+
+    if [ -n "$decomp" ] ; then
+        t=`file -zibL "$1" 2>/dev/null`
+        fmime "$t"
+        [ -n "$ftype" ] && return
+    fi
+
+    t=`file -${decomp:+z}bL "$1" 2>/dev/null`
+    case "$t" in
+        *Z[iI][pP]\ *archive*)                              ftype=zip  ;;
+        *tar\ archive*)                                     ftype=tar  ;;
+        *ar\ archive*|*Debian\ *package*)                   ftype=ar   ;;
+        *ARJ\ *archive*)                                    ftype=arj  ;;
+        *Zoo\ *archive*)                                    ftype=zoo  ;;
+        *cpio\ archive*)                                    ftype=cpio ;;
+        *C[aA][bB]*archive*)                                ftype=cab  ;;
+        RPM\ *)                                             ftype=rpm  ;;
+        *ACE\ *archive*)                                    ftype=ace  ;;
+        *LHa\ *archive*)                                    ftype=lha  ;;
+        *RAR\ *archive*)                                    ftype=rar  ;;
+    esac
+}
+
 unarch()
 {
     case "$1" in
         /*) f="$1" ;;
-        *) f="$PWD/$1" ;;
+        *)  f="$PWD/$1" ;;
     esac
+    ftype "$1"
     cd "$2"
-    case "$f" in
-        *.tar.bz2|*.tbz)
-            [ -n "$force" ] && o= || o=k
-            tar jxv${o}f "$f"
-            ;;
-        *.tar.gz|*.tgz|*.tar.Z)
+    case "$ftype" in
+        tar)
             [ -n "$force" ] && o= || o=k
-            tar zxv${o}f "$f"
+            ${decomp:-cat} "$f" | tar xv$o
             ;;
-        *.tar)
-            [ -n "$force" ] && o= || o=k
-            tar xv${o}f "$f"
-            ;;
-        *.zip|*.jar|*.ear|*.war)
+        zip)
             [ -n "$force" ] && o=-o || o=-n
             unzip $o "$f"
             ;;
-        *.rar)
-            [ -n "$force" ] && o=-o+ || o=-o-
-            unrar x $o -y "$f"
+        rar)
+            [ -n "$force" ] && o=+ || o=-
+            unrar x -o$o -y "$f"
             ;;
-        *.cab)
-            # force not supported, it's always on (as of cabextract 1.0)
+        cab)
+            # force not supported, it's always on (as of cabextract 1.[01])
             cabextract -f "$f"
             ;;
-        *.rpm)
-            [ -n "$force" ] && o=u || o=
+        rpm)
             name=`rpm -qp --qf "%{NAME}-%{VERSION}-%{RELEASE}" "$f"`
             mkdir -p "$name"
             cd "$name"
             rpm2cpio "$f" \
-            | cpio --quiet --no-absolute-filenames -id${o}mv 2>&1 \
+            | cpio --quiet --no-absolute-filenames -id${force:+u}mv 2>&1 \
             | sed "s|^\(\./\)\?|$name/|"
             cd ..
             ;;
-        *.cpio)
-            [ -n "$force" ] && o=u || o=
-            cpio --quiet --no-absolute-filenames -id${o}mv < "$f"
-            ;;
-        *.cpio.gz|*.cpio.Z|*.cgz)
-            [ -n "$force" ] && o=u || o=
-            gzip -dc "$f" | cpio --quiet --no-absolute-filenames -id${o}mv
-            ;;
-        *.cpio.bz2|*.cbz)
-            [ -n "$force" ] && o=u || o=
-            bzip2 -dc "$f" | cpio --quiet --no-absolute-filenames -id${o}mv
+        cpio)
+            ${decomp:-cat} "$f" | \
+                cpio --quiet --no-absolute-filenames -id${force:+u}mv
             ;;
-        *.a|*.deb)
+        ar)
             # force not supported, it's always on
             ar xvo "$f"
             ;;
-        *.ace)
+        ace)
             [ -n "$force" ] && o=+ || o=-
             unace x -o$o -y "$f"
             ;;
-        *.arj)
+        arj)
             # force not supported, it's always off (as of unarj 2.6[35])
             # it will also return an error if some files already exist :(
             unarj x "$f"
             ;;
-        *.zoo)
-            [ -n "$force" ] && o=OOS || o=
-            zoo x$o "$f"
-            ;;
-        *.lhz)
-            [ -n "$force" ] && o=f || o=
-            lha x$o "$f" </dev/null
+        zoo)
+            zoo x${force:+OOS} "$f"
+            ;;
+        lha)
+            lha x${force:+f} "$f" < /dev/null
             ;;
         *)
             echo "Error: unrecognized archive: '$f'" >&2


Index: fedora-rpmdevtools.spec
===================================================================
RCS file: /cvs/fedora/fedora-rpmdevtools/fedora-rpmdevtools.spec,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -r1.88 -r1.89
--- fedora-rpmdevtools.spec	8 Feb 2006 18:57:53 -0000	1.88
+++ fedora-rpmdevtools.spec	9 Feb 2006 19:29:10 -0000	1.89
@@ -21,7 +21,7 @@
 Provides:       spectool = %{spectool_version}
 Obsoletes:      %{name}-emacs < 0.1.9
 # Required for tool operations
-Requires:       rpm-python, python, cpio, sed, perl, wget
+Requires:       rpm-python, python, cpio, sed, perl, wget, file
 # Minimal RPM build requirements
 Requires:       rpm-build, gcc, gcc-c++, redhat-rpm-config, make, tar, patch
 Requires:       diffutils, gzip, bzip2, unzip
@@ -129,6 +129,9 @@
 
 
 %changelog
+* Thu Feb  9 2006 Ville Skyttä <ville.skytta at iki.fi>
+- Add file(1) based archive type detection to fedora-extract.
+
 * Wed Feb  8 2006 Ville Skyttä <ville.skytta at iki.fi>
 - Add "diff file lists only" option to diffarchive.
 




More information about the scm-commits mailing list