Author: glen
Date: Tue Dec 21 20:02:50 2010
New Revision: 12018

Modified:
   geninitrd/trunk/geninitrd
Log:
- if image compress failed (for whatever reason), retry with gzip

Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd   (original)
+++ geninitrd/trunk/geninitrd   Tue Dec 21 20:02:50 2010
@@ -870,6 +870,31 @@
        echo gzip
 }
 
+# compresses kernel image image
+# in function so we could retry with other compressor on failure
+compress_image() {
+       local compressor="$1" IMAGE="$2" target="$3" tmp
+       tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
+
+       case "$compressor" in
+       xz)
+               # don't use -9 here since kernel won't understand it
+               xz --format=xz --check=crc32 --lzma2=preset=6e,dict=1MiB < 
"$IMAGE" > "$tmp" || return $?
+               ;;
+       lzma)
+               xz --format=lzma -9 < "$IMAGE" > "$tmp" || return $?
+               ;;
+       bzip2)
+               bzip2 -9 < "$IMAGE" > "$tmp" || return $?
+               ;;
+       gzip)
+               gzip -9 < "$IMAGE" > "$tmp" || return $?
+               ;;
+       esac
+
+       mv -f "$tmp" "$target"
+}
+
 if [ -r /etc/sysconfig/geninitrd ]; then
        . /etc/sysconfig/geninitrd
 fi
@@ -1367,28 +1392,19 @@
 fi
 
 if ! is_no "$COMPRESS"; then
-       tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
        compressor=$(find_compressor "$COMPRESS")
        debug "Compressing $target with $compressor"
 
        # TODO: the image name (specified from kernel.spec) already contains
        # extension, which is .gz most of the time.
-       case "$compressor" in
-       xz)
-               # don't use -9 here since kernel won't understand it
-               xz --format=xz --check=crc32 --lzma2=preset=6e,dict=1MiB < 
"$IMAGE" > "$tmp" || die "Compress failed, out of memory?" $?
-               ;;
-       lzma)
-               xz --format=lzma -9 < "$IMAGE" > "$tmp" || die "Compress 
failed, out of memory?" $?
-               ;;
-       bzip2)
-               bzip2 -9 < "$IMAGE" > "$tmp" || die "Compress failed" $?
-               ;;
-       gzip)
-               gzip -9 < "$IMAGE" > "$tmp" || die "Compress failed" $?
-               ;;
-       esac
-       mv -f "$tmp" "$target"
+       compress_image "$compressor" "$IMAGE" "$target" || {
+               if [ $compressor != gzip ]; then
+                       warn "Could not compress with $compressor, retrying 
with gzip"
+                       compress_image gzip "$IMAGE" "$target" || die "compress 
failed with gzip" $?
+               else
+                       die "Could not compress image with $compressor"
+               fi
+       }
 else
        cp -a "$IMAGE" "$target"
 fi
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to