cache the result of --suffix to reduce testing overhead as suggested by Mr_Bones_...
authorZac Medico <zmedico@gentoo.org>
Fri, 22 Jun 2007 02:53:00 +0000 (02:53 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 22 Jun 2007 02:53:00 +0000 (02:53 -0000)
svn path=/main/branches/2.1.2/; revision=6935

bin/ecompress

index 5e4f645737689efaac89b15a3d634ea05c95603e..6eb1d5df79a9b346c9f79ca9c6102a498ee5edb5 100755 (executable)
@@ -22,20 +22,23 @@ fi
 
 case $1 in
        --suffix)
-               set -e
-               tmpdir="${T}"/.ecompress$$.${RANDOM}
-               mkdir "${tmpdir}"
-               cd "${tmpdir}"
-               # we have to fill the file enough so that there is something
-               # to compress as some programs will refuse to do compression
-               # if it cannot actually compress the file
-               echo {0..1000} > compressme
-               ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS} compressme > /dev/null
-               suffix=$(ls compressme*)
-               suffix=${suffix#compressme}
-               cd /
-               rm -rf "${tmpdir}"
-               echo "${suffix}"
+               if [[ ! -e ${T}/.ecompress.suffix ]] ; then
+                       set -e
+                       tmpdir="${T}"/.ecompress$$.${RANDOM}
+                       mkdir "${tmpdir}"
+                       cd "${tmpdir}"
+                       # we have to fill the file enough so that there is something
+                       # to compress as some programs will refuse to do compression
+                       # if it cannot actually compress the file
+                       echo {0..1000} > compressme
+                       ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS} compressme > /dev/null
+                       suffix=$(ls compressme*)
+                       suffix=${suffix#compressme}
+                       cd /
+                       rm -rf "${tmpdir}"
+                       echo "${suffix}" > "${T}/.ecompress.suffix"
+               fi
+               cat "${T}/.ecompress.suffix"
                ;;
        --bin)
                echo "${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS}"