prepman: do not compress files <=128 bytes
authorMike Frysinger <vapier@gentoo.org>
Wed, 20 Mar 2013 08:29:44 +0000 (04:29 -0400)
committerMike Frysinger <vapier@gentoo.org>
Wed, 20 Mar 2013 08:29:44 +0000 (04:29 -0400)
The vast majority of these small files do not compress better than
their inputs, and they're just .so redirection.  Omit compression
on them to save disk and cpu and speed things up.

URL: http://bugs.gentoo.org/169260
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
bin/ebuild-helpers/ecompressdir
bin/ebuild-helpers/prepman

index 75f3e3a2516679b06fb0a86aa4a9f5f271df0b2f..0f05c274399fa122eb3ecbde535d98aef0503cc2 100755 (executable)
@@ -13,7 +13,9 @@ if ! ___eapi_has_prefix_variables; then
        ED=${D} EPREFIX=
 fi
 
-case $1 in
+SIZE_LIMIT=''
+while [[ $# -gt 0 ]] ; do
+       case $1 in
        --ignore)
                shift
                for skip in "$@" ; do
@@ -28,7 +30,8 @@ case $1 in
                set -- "${@/#/${ED}}"
                ret=0
                for x in "$@" ; do
-                       >> "$x"
+                       # Stash the limit in the .dir file so we can reload it later.
+                       printf "${SIZE_LIMIT}" > "${x}"
                        ((ret|=$?))
                done
                [[ $ret -ne 0 ]] && __helpers_die "${0##*/} failed"
@@ -42,29 +45,44 @@ case $1 in
                find "${ED}" -name '*.ecompress.skip' -print0 | ${XARGS} -0 rm -f
                exit 0
                ;;
+       --limit)
+               SIZE_LIMIT=$2
+               shift
+               ;;
        --*)
                __helpers_die "${0##*/}: unknown arguments '$*'"
                exit 1
                ;;
-esac
+       *)
+               break
+               ;;
+       esac
+       shift
+done
 
 # figure out the new suffix
 suffix=$(ecompress --suffix)
 
-# funk_up_dir(action, suffix, binary)
+# funk_up_dir(action, suffix, binary, [size_limit])
 #      - action: compress or decompress
 #      - suffix: the compression suffix to work with
 #      - binary: the program to execute that'll compress/decompress
+#   - size_limit: if compressing, skip files smaller than this
 # The directory we act on is implied in the ${dir} variable
 funk_up_dir() {
-       local act=$1 suffix=$2 binary=$3
+       local act=$1 suffix=$2 binary=$3 size_limit=$4
 
        local negate=""
        [[ ${act} == "compress" ]] && negate="!"
 
        local ret=0
        # first we act on all the files
-       find "${dir}" -type f ${negate} -iname '*'${suffix} -print0 | ${XARGS} -0 ${binary}
+       local args=(
+               -type f
+               ${negate} -iname "*${suffix}"
+       )
+       [[ -n ${size_limit} ]] && args+=( -size "+${size_limit}c" )
+       find "${dir}" "${args[@]}" -print0 | ${XARGS} -0 ${binary}
        ((ret|=$?))
 
        while read -r -d $'\0' brokenlink ; do
@@ -152,6 +170,7 @@ for dir in "$@" ; do
 
        # since we've been requested to compress the whole dir,
        # delete any individual queued requests
+       size_limit=${SIZE_LIMIT:-$(<"${actual_dir}.ecompress.dir")}
        rm -f "${actual_dir}.ecompress.dir"
        find "${dir}" -type f -name '*.ecompress.file' -print0 | ${XARGS} -0 rm -f
 
@@ -179,7 +198,7 @@ for dir in "$@" ; do
        # now lets do our work
        if [[ -n ${suffix} ]] ; then
                __vecho "${0##*/}: $(ecompress --bin) /${actual_dir#${ED}}"
-               funk_up_dir "compress" "${suffix}" "ecompress"
+               funk_up_dir "compress" "${suffix}" "ecompress" "${size_limit}"
                : $(( ret |= $? ))
        fi
 
index 55a9483e3ff2890aced252990cf220357d250c1b..fb5dcb4a553a4205677db756d404282f501b98b5 100755 (executable)
@@ -2,6 +2,9 @@
 # Copyright 1999-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+# Do not compress man pages which are smaller than this (in bytes). #169260
+SIZE_LIMIT='128'
+
 source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh
 
 if ! ___eapi_has_prefix_variables; then
@@ -31,6 +34,6 @@ for subdir in "${mandir}"/man* "${mandir}"/*/man* ; do
        [[ -d ${subdir} ]] && really_is_mandir=1 && break
 done
 
-[[ ${really_is_mandir} == 1 ]] && exec ecompressdir --queue "${mandir#${ED}}"
+[[ ${really_is_mandir} == 1 ]] && exec ecompressdir --limit ${SIZE_LIMIT} --queue "${mandir#${ED}}"
 
 exit 0