commit:     78c036c507ec8c87bf5dd7cc388cbf7e038a51ed
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Tue Sep 25 19:12:20 2018 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Sep 28 20:32:40 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=78c036c5

ecompress: Detect and report colliding (un)compressed files

Whenever the install directory contains files that would collide upon
(re)compressing, report them explicitly and skip decompressing.

To reduce performance impact, the check is only done whenever compressed
files are found.  This is sufficient since for issue to occur there must
be at least one compressed variant.

Bug: https://bugs.gentoo.org/667072
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
Reviewed-by: Zac Medico <zmedico <AT> gentoo.org>

 bin/ecompress | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/bin/ecompress b/bin/ecompress
index 36bdb585b..635073b5f 100755
--- a/bin/ecompress
+++ b/bin/ecompress
@@ -48,9 +48,41 @@ while [[ $# -gt 0 ]] ; do
                        [[ -n ${PORTAGE_DOCOMPRESS_SIZE_LIMIT} ]] &&
                                find_args+=( -size 
"+${PORTAGE_DOCOMPRESS_SIZE_LIMIT}c" )
 
+                       declare -A collisions
                        while IFS= read -d '' -r path; do
+                               # detect the horrible posibility of the ebuild 
installing
+                               # colliding compressed and/or uncompressed 
variants
+                               # and fail hard (bug #667072)
+                               #
+                               # note: to save time, we need to do this only 
if there's
+                               # at least one compressed file
+                               case ${path} in
+                                       *.Z|*.gz|*.bz2|*.lzma|*.xz)
+                                               vpath=${path%.*}
+                                               for comp in '' .Z .gz .bz2 
.lzma .xz; do
+                                                       if [[ ${vpath}${comp} 
!= ${path} && \
+                                                                       -e 
${vpath}${comp} ]]; then
+                                                               
collisions[${path}]=1
+                                                               
collisions[${vpath}]=1
+                                                               # ignore 
compressed variants in that case
+                                                               continue 2
+                                                       fi
+                                               done
+                                               ;;
+                               esac
+
                                >> "${path}.ecompress" || die
                        done < <(find "${find_args[@]}" -print0 || die)
+
+                       if [[ ${#collisions[@]} -gt 0 ]]; then
+                               eqawarn "Colliding files found by ecompress:"
+                               eqawarn
+                               for x in "${!collisions[@]}"; do
+                                       eqawarn "  ${x}"
+                               done
+                               eqawarn
+                               eqawarn "Please remove the extraneous 
compressed variants."
+                       fi
                fi
 
                exit 0

Reply via email to