summaryrefslogtreecommitdiffstats
path: root/bin/ebuild-helpers/ecompress
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-03-12 00:28:45 +0000
committerZac Medico <zmedico@gentoo.org>2009-03-12 00:28:45 +0000
commitc9cf1a3a0bb3dc6ca5f801e6886fb4f0be90c767 (patch)
tree5e55a40e4c13d8c9ddd779ea6c4d395117d1fa99 /bin/ebuild-helpers/ecompress
parentbc188208fd239d4f9f2be6ad5ab1ebdac3706572 (diff)
downloadportage-c9cf1a3a0bb3dc6ca5f801e6886fb4f0be90c767.tar.gz
portage-c9cf1a3a0bb3dc6ca5f801e6886fb4f0be90c767.tar.bz2
portage-c9cf1a3a0bb3dc6ca5f801e6886fb4f0be90c767.zip
Move ebuild helpers into an ebuild-helpers subdirectory.
svn path=/main/trunk/; revision=13063
Diffstat (limited to 'bin/ebuild-helpers/ecompress')
-rwxr-xr-xbin/ebuild-helpers/ecompress92
1 files changed, 92 insertions, 0 deletions
diff --git a/bin/ebuild-helpers/ecompress b/bin/ebuild-helpers/ecompress
new file mode 100755
index 000000000..6fdde5719
--- /dev/null
+++ b/bin/ebuild-helpers/ecompress
@@ -0,0 +1,92 @@
+#!/bin/bash
+# Copyright 1999-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh
+
+if [[ -z $1 ]] ; then
+ vecho "${0##*/}: at least one argument needed" 1>&2
+ exit 1
+fi
+
+# setup compression stuff
+PORTAGE_COMPRESS=${PORTAGE_COMPRESS-bzip2}
+[[ -z ${PORTAGE_COMPRESS} ]] && exit 0
+
+if [[ ${PORTAGE_COMPRESS_FLAGS+set} != "set" ]] ; then
+ case ${PORTAGE_COMPRESS} in
+ bzip2|gzip) PORTAGE_COMPRESS_FLAGS="-9";;
+ esac
+fi
+
+case $1 in
+ --suffix)
+ [[ -n $2 ]] && vecho "${0##*/}: --suffix takes no additional arguments" 1>&2
+
+ 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)
+ [[ -n $2 ]] && vecho "${0##*/}: --bin takes no additional arguments" 1>&2
+
+ echo "${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS}"
+ ;;
+ --queue)
+ shift
+ exec touch "${@/%/.ecompress.file}"
+ ;;
+ --dequeue)
+ [[ -n $2 ]] && vecho "${0##*/}: --dequeue takes no additional arguments" 1>&2
+ find "${D}" -name '*.ecompress.file' -print0 \
+ | sed -e 's:\.ecompress\.file::g' \
+ | ${XARGS} -0 ecompress
+ find "${D}" -name '*.ecompress.file' -print0 | ${XARGS} -0 rm -f
+ ;;
+ --*)
+ vecho "${0##*/}: unknown arguments '$*'" 1>&2
+ exit 1
+ ;;
+ *)
+ mask_ext_re=""
+ set -f
+ for x in $PORTAGE_COMPRESS_EXCLUDE_SUFFIXES ; do
+ mask_ext_re+="|$x"
+ done
+ set +f
+ mask_ext_re="^(${mask_ext_re:1})\$"
+ declare -a filtered_args=()
+ i=0
+ for x in "$@" ; do
+ [[ ${x##*.} =~ $mask_ext_re ]] && continue
+ filtered_args[$i]=$x
+ (( i++ ))
+ done
+ [ $i -eq 0 ] && exit 0
+ set -- "${filtered_args[@]}"
+
+ # If a compressed version of the file already exists, simply
+ # delete it so that the compressor doesn't whine (bzip2 will
+ # complain and skip, gzip will prompt for input)
+ suffix=$(ecompress --suffix)
+ [[ -n ${suffix} ]] && echo -n "${@/%/${suffix}$'\001'}" | \
+ tr '\001' '\000' | ${XARGS} -0 rm -f
+ # Finally, let's actually do some real work
+ exec "${PORTAGE_COMPRESS}" ${PORTAGE_COMPRESS_FLAGS} "$@"
+ ;;
+esac