diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2024-04-26 12:01:07 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-04-26 08:12:22 +0200 |
commit | b9020cdbae0a05b4e9139e2d761d7c74aa653bb9 (patch) | |
tree | 008c6bde099f3b34dfe930f2b9fda39bebc38bda | |
parent | ed330eb79b75914b741f28679e724267ad2523df (diff) | |
download | mbuto-b9020cdbae0a05b4e9139e2d761d7c74aa653bb9.tar mbuto-b9020cdbae0a05b4e9139e2d761d7c74aa653bb9.tar.gz mbuto-b9020cdbae0a05b4e9139e2d761d7c74aa653bb9.tar.bz2 mbuto-b9020cdbae0a05b4e9139e2d761d7c74aa653bb9.tar.lz mbuto-b9020cdbae0a05b4e9139e2d761d7c74aa653bb9.tar.xz mbuto-b9020cdbae0a05b4e9139e2d761d7c74aa653bb9.tar.zst mbuto-b9020cdbae0a05b4e9139e2d761d7c74aa653bb9.zip |
Split "auto" compression mode into its own path
mbuto supports "auto" compression mode where we detect the fastest to
decompress and use it. This is structured a bit oddly - cpio_compress()
first handles the case of an explicitly selected compressor, then handles
the auto-detected case, redundantly implementing the compression once it
has picked one.
Make this a bit clearer: first handle the "auto" case by calling out to
the testing code, and using that to set the parameter for the specific
compression path.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rwxr-xr-x | mbuto | 53 |
1 files changed, 24 insertions, 29 deletions
@@ -566,31 +566,11 @@ cpio_init() { fi } -# cpio_compress() - Compress archive, test available methods if none is selected +# compress_select() - Try compressors and pick the fastest to decompress image # $1: Existing CPIO archive -cpio_compress() { - { [ -z "${COMPRESS}" ] || [ "${COMPRESS}" = "none" ]; } && return - - info "Compressing CPIO archive ${1}" - - if [ "${COMPRESS}" != "auto" ]; then - [ "${COMPRESS}" = "lzo" ] && __cmd="lzop" || __cmd="${COMPRESS}" - - cmd_check "${__cmd}" - if [ "${__cmd}" = "lz4" ]; then - "${__cmd}" -l -f -q -9 "${1}" "${1}.lz4" - else - "${__cmd}" -f -q -9 -S .lz4 "${1}" - fi - - mv "${1}.lz4" "${1}" - - return - fi - +compress_select() { if [ ! -f "/boot/config-${KERNEL}" ]; then - "${GZIP}" -9 "${1}" - "${MV}" "${1}.gz" "${1}" + echo "gzip" return fi @@ -639,14 +619,29 @@ cpio_compress() { "${__a}:" "${__size} bytes" "${__time}s" done - [ "${__pick}" = "lzo" ] && __cmd="lzop" || __cmd="${__pick}" - [ "${__cmd}" = "lz4" ] && __opt="-l" || __opt="" - - "${__cmd}" ${__opt} -q -9 -c "${1}" > "${compress_test1}" notice "Picked ${__pick} compression for CPIO" + rm ${compress_test1} ${compress_test2} + echo "${__pick}" +} + +# cpio_compress() - Compress archive, test available methods if none is selected +# $1: Existing CPIO archive +cpio_compress() { + { [ -z "${COMPRESS}" ] || [ "${COMPRESS}" = "none" ]; } && return + [ "${COMPRESS}" = "auto" ] && COMPRESS=$(compress_select "$1") + + info "Compressing CPIO archive ${1}" + + [ "${COMPRESS}" = "lzo" ] && __cmd="lzop" || __cmd="${COMPRESS}" + + cmd_check "${__cmd}" + if [ "${__cmd}" = "lz4" ]; then + "${__cmd}" -l -f -q -9 "${1}" "${1}.lz4" + else + "${__cmd}" -f -q -9 -S .lz4 "${1}" + fi - mv "${compress_test1}" "${OUT}" - rm "${compress_test2}" + mv "${1}.lz4" "${1}" } ################################################################################ |