2 # Copyright 1999-2011 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
5 source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/helper-functions.sh
8 helpers_die "${0##*/}: at least one argument needed"
12 [[ " ${FEATURES} " == *" force-prefix "* ]] || \
13 case "$EAPI" in 0|1|2) ED=${D} EPREFIX= ;; esac
19 [[ -d ${ED}${skip} || -f ${ED}${skip} ]] \
20 && >> "${ED}${skip}.ecompress.skip"
26 set -- "${@/%/.ecompress.dir}"
33 [[ $ret -ne 0 ]] && helpers_die "${0##*/} failed"
37 [[ -n $2 ]] && vecho "${0##*/}: --dequeue takes no additional arguments" 1>&2
38 find "${ED}" -name '*.ecompress.dir' -print0 \
39 | sed -e 's:\.ecompress\.dir::g' -e "s:${ED}:/:g" \
40 | ${XARGS} -0 ecompressdir
41 find "${ED}" -name '*.ecompress.skip' -print0 | ${XARGS} -0 rm -f
45 helpers_die "${0##*/}: unknown arguments '$*'"
50 # figure out the new suffix
51 suffix=$(ecompress --suffix)
53 # funk_up_dir(action, suffix, binary)
54 # - action: compress or decompress
55 # - suffix: the compression suffix to work with
56 # - binary: the program to execute that'll compress/decompress
57 # The directory we act on is implied in the ${dir} variable
59 local act=$1 suffix=$2 binary=$3
62 [[ ${act} == "compress" ]] && negate="!"
64 # first we act on all the files
65 find "${dir}" -type f ${negate} -iname '*'${suffix} -print0 | ${XARGS} -0 ${binary}
68 find "${dir}" -type l -print0 | \
69 while read -r -d $'\0' brokenlink ; do
70 [[ -e ${brokenlink} ]] && continue
71 olddest=$(readlink "${brokenlink}")
72 # Ignore temporarily broken symlinks due to
73 # _relocate_skip_dirs (bug #399595), and handle
74 # absolute symlinks to files that aren't merged
76 if [[ ${olddest} == /* ]] ; then
77 [ -e "${D}${olddest}" ] && continue
78 skip_dir_dest=${T}/ecompress-skip/${olddest#${EPREFIX}}
80 skip_dir_dest=${T}/ecompress-skip/${actual_dir#${ED}}/${brokenlink%/*}/${olddest}
82 [[ -e ${skip_dir_dest} ]] && continue
83 [[ ${act} == "compress" ]] \
84 && newdest="${olddest}${suffix}" \
85 || newdest="${olddest%${suffix}}"
87 [[ ${act} == "compress" ]] \
88 && ln -snf "${newdest}" "${brokenlink}${suffix}" \
89 || ln -snf "${newdest}" "${brokenlink%${suffix}}"
94 # _relocate_skip_dirs(srctree, dsttree)
95 # Move all files and directories we want to skip running compression
96 # on from srctree to dsttree.
97 _relocate_skip_dirs() {
98 local srctree="$1" dsttree="$2"
100 [[ -d ${srctree} ]] || return 0
102 find "${srctree}" -name '*.ecompress.skip' -print0 | \
103 while read -r -d $'\0' src ; do
104 src=${src%.ecompress.skip}
105 dst="${dsttree}${src#${srctree}}"
109 mv "${src}.ecompress.skip" "${dst}.ecompress.skip"
112 hide_skip_dirs() { _relocate_skip_dirs "${ED}" "${T}"/ecompress-skip/ ; }
113 restore_skip_dirs() { _relocate_skip_dirs "${T}"/ecompress-skip/ "${ED}" ; }
117 rm -rf "${T}"/ecompress-skip
132 if [[ ! -d ${dir} ]] ; then
133 vecho "${0##*/}: /${dir#${ED}} does not exist!"
138 dir=. # use relative path to avoid 'Argument list too long' errors
140 # hide all the stuff we want to skip
141 hide_skip_dirs "${dir}"
143 # since we've been requested to compress the whole dir,
144 # delete any individual queued requests
145 rm -f "${actual_dir}.ecompress.dir"
146 find "${dir}" -type f -name '*.ecompress.file' -print0 | ${XARGS} -0 rm -f
148 # not uncommon for packages to compress doc files themselves
149 for (( d = 0; d < ${#decompressors[@]}; d += 2 )) ; do
150 # It's faster to parallelize at this stage than to try to
151 # parallelize the compressors. This is because the find|xargs
152 # ends up launching less compressors overall, so the overhead
153 # of forking children ends up dominating.
156 funk_up_dir "decompress" "${decompressors[i]}" "${decompressors[i+1]}"
162 # forcibly break all hard links as some compressors whine about it
163 find "${dir}" -type f -links +1 -exec env file="{}" sh -c \
164 'cp -p "${file}" "${file}.ecompress.break" ; mv -f "${file}.ecompress.break" "${file}"' \;
169 # now lets do our work
170 if [[ -n ${suffix} ]] ; then
171 vecho "${0##*/}: $(ecompress --bin) /${actual_dir#${ED}}"
172 funk_up_dir "compress" "${suffix}" "ecompress"
175 # finally, restore the skipped stuff
179 [[ $ret -ne 0 ]] && helpers_die "${0##*/} failed"