2 # Copyright 1999-2010 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
5 source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh
8 helpers_die "${0##*/}: at least one argument needed"
16 [[ -d ${D}${skip} || -f ${D}${skip} ]] \
17 && >> "${D}${skip}.ecompress.skip"
23 set -- "${@/%/.ecompress.dir}"
30 [[ $ret -ne 0 ]] && helpers_die "${0##*/} failed"
34 [[ -n $2 ]] && vecho "${0##*/}: --dequeue takes no additional arguments" 1>&2
35 find "${D}" -name '*.ecompress.dir' -print0 \
36 | sed -e 's:\.ecompress\.dir::g' -e "s:${D}:/:g" \
37 | ${XARGS} -0 ecompressdir
38 find "${D}" -name '*.ecompress.skip' -print0 | ${XARGS} -0 rm -f
42 helpers_die "${0##*/}: unknown arguments '$*'"
47 # figure out the new suffix
48 suffix=$(ecompress --suffix)
50 # funk_up_dir(action, suffix, binary)
51 # - action: compress or decompress
52 # - suffix: the compression suffix to work with
53 # - binary: the program to execute that'll compress/decompress
54 # The directory we act on is implied in the ${dir} variable
56 local act=$1 suffix=$2 binary=$3
59 [[ ${act} == "compress" ]] && negate="!"
61 # first we act on all the files
62 find "${dir}" -type f ${negate} -iname '*'${suffix} -print0 | ${XARGS} -0 ${binary}
65 find "${dir}" -type l -print0 | \
66 while read -r -d $'\0' brokenlink ; do
67 [[ -e ${brokenlink} ]] && continue
68 olddest=$(readlink "${brokenlink}")
69 [[ ${act} == "compress" ]] \
70 && newdest="${olddest}${suffix}" \
71 || newdest="${olddest%${suffix}}"
73 [[ ${act} == "compress" ]] \
74 && ln -snf "${newdest}" "${brokenlink}${suffix}" \
75 || ln -snf "${newdest}" "${brokenlink%${suffix}}"
80 # _relocate_skip_dirs(srctree, dsttree)
81 # Move all files and directories we want to skip running compression
82 # on from srctree to dsttree.
83 _relocate_skip_dirs() {
84 local srctree="$1" dsttree="$2"
86 [[ -d ${srctree} ]] || return 0
88 find "${srctree}" -name '*.ecompress.skip' -print0 | \
89 while read -r -d $'\0' src ; do
90 src=${src%.ecompress.skip}
91 dst="${dsttree}${src#${srctree}}"
95 mv "${src}.ecompress.skip" "${dst}.ecompress.skip"
98 hide_skip_dirs() { _relocate_skip_dirs "${D}" "${T}"/ecompress-skip/ ; }
99 restore_skip_dirs() { _relocate_skip_dirs "${T}"/ecompress-skip/ "${D}" ; }
103 rm -rf "${T}"/ecompress-skip
108 if [[ ! -d ${dir} ]] ; then
109 vecho "${0##*/}: /${dir#${D}} does not exist!"
114 dir=. # use relative path to avoid 'Argument list too long' errors
116 # hide all the stuff we want to skip
117 hide_skip_dirs "${dir}"
119 # since we've been requested to compress the whole dir,
120 # delete any individual queued requests
121 rm -f "${actual_dir}.ecompress.dir"
122 find "${dir}" -type f -name '*.ecompress.file' -print0 | ${XARGS} -0 rm -f
124 # not uncommon for packages to compress doc files themselves
125 funk_up_dir "decompress" ".Z" "gunzip -f"
126 funk_up_dir "decompress" ".gz" "gunzip -f"
127 funk_up_dir "decompress" ".bz2" "bunzip2 -f"
129 # forcibly break all hard links as some compressors whine about it
130 find "${dir}" -type f -links +1 -exec env file="{}" sh -c \
131 'cp -p "${file}" "${file}.ecompress.break" ; mv -f "${file}.ecompress.break" "${file}"' \;
133 # now lets do our work
134 [[ -z ${suffix} ]] && continue
135 vecho "${0##*/}: $(ecompress --bin) /${actual_dir#${D}}"
136 funk_up_dir "compress" "${suffix}" "ecompress"
138 # finally, restore the skipped stuff
142 [[ $ret -ne 0 ]] && helpers_die "${0##*/} failed"