Patchwork rpm2cpio: Update to match rpm4 specs for decompression

login
register
mail settings
Submitter Saul Wold
Date Jan. 19, 2013, 4:48 a.m.
Message ID <1358570913-10128-1-git-send-email-sgw@linux.intel.com>
Download mbox | patch
Permalink /patch/42909/
State Accepted
Commit 1377278187d20853304fe2689105f2848d796d86
Headers show

Comments

Saul Wold - Jan. 19, 2013, 4:48 a.m.
[YOCTO #3753]

Signed-off-by: Saul Wold <sgw@linux.intel.com>
---
 meta/recipes-devtools/rpm/rpm/rpm2cpio | 40 ++++++++++++----------------------
 1 file changed, 14 insertions(+), 26 deletions(-)

Patch

diff --git a/meta/recipes-devtools/rpm/rpm/rpm2cpio b/meta/recipes-devtools/rpm/rpm/rpm2cpio
index 00c4ec5..6bcef6a 100755
--- a/meta/recipes-devtools/rpm/rpm/rpm2cpio
+++ b/meta/recipes-devtools/rpm/rpm/rpm2cpio
@@ -1,5 +1,8 @@ 
 #!/bin/sh
 
+# Prevent gawk >= 4.0.x from getting funny ideas wrt UTF in printf()
+LANG=C
+
 pkg=$1
 if [ "$pkg" = "" -o ! -e "$pkg" ]; then
     echo "no package supplied" 1>&2
@@ -22,30 +25,15 @@  dl=`expr 256 \* \( 256 \* \( 256 \* $6 + $7 \) + $8 \) + $9`
 
 hdrsize=`expr 8 + 16 \* $il + $dl`
 o=`expr $o + $hdrsize`
-EXTRACTOR="dd if=$pkg ibs=$o skip=1"
-
-COMPRESSION=`($EXTRACTOR |file -) 2>/dev/null`
-if echo $COMPRESSION |grep -q gzip; then
-	DECOMPRESSOR=gunzip
-elif echo $COMPRESSION |grep -q bzip2; then
-	DECOMPRESSOR=bunzip2
-elif echo $COMPRESSION |grep -q xz; then
-	DECOMPRESSOR=unxz
-elif echo $COMPRESSION |grep -q cpio; then
-	DECOMPRESSOR=cat
-else
-	# Most versions of file don't support LZMA, therefore we assume
-	# anything not detected is LZMA
-	DECOMPRESSOR=`which unlzma 2>/dev/null`
-	case "$DECOMPRESSOR" in
-	    /* ) ;;
-	    *  ) DECOMPRESSOR=`which lzmash 2>/dev/null`
-	         case "$DECOMPRESSOR" in
-	             /* ) DECOMPRESSOR="lzmash -d -c" ;;
-	             *  ) DECOMPRESSOR=cat ;;
-	         esac
-	         ;;
-	esac
-fi
+comp=`dd if=$pkg ibs=$o skip=1 count=1 2>/dev/null | dd bs=3 count=1 2> /dev/null`
 
-$EXTRACTOR 2>/dev/null | $DECOMPRESSOR
+gz="`echo . | awk '{ printf("%c%c", 0x1f, 0x8b); }'`"
+lzma="`echo . | awk '{ printf("%cLZ", 0xff); }'`"
+xz="`echo . | awk '{ printf("%c7z", 0xfd); }'`"
+case "$comp" in
+    BZh)      dd if="$pkg" ibs=$o skip=1 2>/dev/null | bunzip2 ;;
+    "$gz"*)   dd if="$pkg" ibs=$o skip=1 2>/dev/null | gunzip ;;
+    "$xz"*)   dd if="$pkg" ibs=$o skip=1 2>/dev/null | xzcat ;;
+    "$lzma"*) dd if="$pkg" ibs=$o skip=1 2>/dev/null | unlzma ;;
+    *)        echo "Unrecognized rpm file: $pkg"; exit 1 ;;
+esac