[csw-devel] SF.net SVN: gar:[12072] csw/mgar/gar/v2
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Wed Dec 22 17:08:43 CET 2010
Revision: 12072
http://gar.svn.sourceforge.net/gar/?rev=12072&view=rev
Author: wahwah
Date: 2010-12-22 16:08:42 +0000 (Wed, 22 Dec 2010)
Log Message:
-----------
checkpkg: a bugfix for custom-pkgtrans
The 'set -e' option caused the script to fail when cpio returned a non-zero
exit code. Armoring the code to use cpio ... || true to keep the script
running if that happens.
Also trying more block offsets, which is not really necessary, but doesn't
hurt either.
This function can be still improved by determining the right offset instead of
trial and error.
Modified Paths:
--------------
csw/mgar/gar/v2/bin/custom-pkgtrans
csw/mgar/gar/v2/lib/sh/libcheckpkg.sh
Modified: csw/mgar/gar/v2/bin/custom-pkgtrans
===================================================================
--- csw/mgar/gar/v2/bin/custom-pkgtrans 2010-12-22 14:47:44 UTC (rev 12071)
+++ csw/mgar/gar/v2/bin/custom-pkgtrans 2010-12-22 16:08:42 UTC (rev 12072)
@@ -4,6 +4,8 @@
#
# This file exists in order to avoid implementing pipelines in Python. It
# could be integrated into the package stats collection program.
+#
+# It has to use the same interpreter as lib/sh/libcheckpkg.sh, currently bash.
set -u
set -e
Modified: csw/mgar/gar/v2/lib/sh/libcheckpkg.sh
===================================================================
--- csw/mgar/gar/v2/lib/sh/libcheckpkg.sh 2010-12-22 14:47:44 UTC (rev 12071)
+++ csw/mgar/gar/v2/lib/sh/libcheckpkg.sh 2010-12-22 16:08:42 UTC (rev 12072)
@@ -1,30 +1,43 @@
-#!/bin/ksh -p
-#
+#!/bin/bash
+#
# $Id$
# pkgtrans leaves a directory in /var/tmp/aaXXXXXXX even after clean quit.
# Emulating pkgtrans behaviour, for "pkgtrans src destdir pkgname". Except
# that the pkgname arg is ignored, and only the first pkg is processed.
-custom_pkgtrans(){
- if [[ ! -d $2 ]] ; then
- print ERROR: $2 is not a directory >/dev/fd/2
- return 1
- fi
- hdrblks=`(dd if=$1 skip=1 2>/dev/null| cpio -i -t >/dev/null) 2>&1 |
- nawk '{print $1; exit;}'`
+get_header_blocks() {
+ dd if="$1" skip=1 \
+ | cpio -i -t 2>&1 >/dev/null \
+ | nawk '{print $1; exit;}'
+}
- ## print initial hdrblks=$hdrblks
+custom_pkgtrans() {
+ local hdrblks
+ if [[ ! -d "$2" ]] ; then
+ echo ERROR: "$2" is not a directory >/dev/fd/2
+ return 1
+ fi
+ hdrblks=$(get_header_blocks "$1")
- hdrblks=$(($hdrblks + 1))
- mkdir $2/$3 || return 1
+ echo "initial hdrblks=$hdrblks"
- dd if=$1 skip=$hdrblks 2>/dev/null | (cd $2/$3 ; cpio -ivdm)
- # on fail, SOMETIMES cpio returns 1, but sometimes it returns 0!!
- if [[ ! -d $2/$3/install ]] ; then
- print retrying extract with different archive offset...
- # no, I can't tell in advance why/when the prev fails
- hdrblks=$(($hdrblks + 1))
- dd if=$1 skip=$hdrblks 2>/dev/null| (cd $2/$3 ; cpio -ivdm)
- fi
+ hdrblks=$(( $hdrblks + 1 ))
+ mkdir $2/$3
+
+ while :; do
+ # cpio sometimes returns 1, and we don't want to bail out when it happens.
+ dd if="$1" skip="$hdrblks" | (cd $2/$3 ; cpio -ivdm) || true
+ if [[ -d "$2/$3/install" ]]; then
+ echo "Unpack successful."
+ break
+ fi
+ hdrblks=$(( $hdrblks + 1 ))
+ # To prevent us from going on forever.
+ if [[ "${hdrblks}" -gt 100 ]]; then
+ echo "Unpack keeps on being unsuccessful. Bailing out."
+ return 1
+ fi
+ echo "Unpack unsuccessful, trying offset ${hdrblks}"
+ done
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list