Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: bin/
Date: Wed, 14 Aug 2019 02:08:35
Message-Id: 1565748164.17ecafa949c87a6f2a2d2c98c7de18ed06f08f2f.zmedico@gentoo
commit:     17ecafa949c87a6f2a2d2c98c7de18ed06f08f2f
Author:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 12 20:20:16 2019 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Aug 14 02:02:44 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=17ecafa9

unpack: Unconditionally die if an unpacker returns an error.

As specified by PMS: "If unpacking a supported file format fails,
unpack shall abort the build process."
https://projects.gentoo.org/pms/7/pms.html#x1-13500012.3.15:

This partially reverts commit 525e69351d45621c34a9326fcbc11ca592cb6539,
as far as unpack() is concerned.

Bug: https://bugs.gentoo.org/691776
Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org>
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 bin/isolated-functions.sh | 13 ++-----
 bin/phase-helpers.sh      | 87 +++++++++++++----------------------------------
 2 files changed, 27 insertions(+), 73 deletions(-)

diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index e4e769a04..893c02f9b 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-# Copyright 1999-2018 Gentoo Foundation
+# Copyright 1999-2019 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 source "${PORTAGE_BIN_PATH}/eapi.sh" || exit 1
@@ -38,18 +38,11 @@ __assert_sigpipe_ok() {
 	local x pipestatus=${PIPESTATUS[*]}
 	for x in $pipestatus ; do
 		# Allow SIGPIPE through (128 + 13)
-		if [[ $x -ne 0 && $x -ne ${PORTAGE_SIGPIPE_STATUS:-141} ]]
-		then
-			__helpers_die "$@"
-			return 1
-		fi
+		[[ $x -ne 0 && $x -ne ${PORTAGE_SIGPIPE_STATUS:-141} ]] && die "$@"
 	done
 
 	# Require normal success for the last process (tar).
-	if [[ $x -ne 0 ]]; then
-		__helpers_die "$@"
-		return 1
-	fi
+	[[ $x -eq 0 ]] || die "$@"
 }
 
 shopt -s extdebug

diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index 02633125f..15fe8c682 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-# Copyright 1999-2018 Gentoo Foundation
+# Copyright 1999-2019 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 if ___eapi_has_DESTTREE_INSDESTTREE; then
@@ -347,10 +347,7 @@ unpack() {
 				die "Relative paths to unpack() must be prefixed with './' in EAPI ${EAPI}"
 			fi
 		fi
-		if [[ ! -s ${srcdir}${x} ]]; then
-			__helpers_die "unpack: ${x} does not exist"
-			return 1
-		fi
+		[[ ! -s ${srcdir}${x} ]] && die "${x} does not exist"
 
 		__unpack_tar() {
 			if [[ ${y_insensitive} == tar ]] ; then
@@ -361,18 +358,15 @@ unpack() {
 						"supported with EAPI '${EAPI}'. Instead use 'tar'."
 				fi
 				$1 -c -- "$srcdir$x" | tar xof -
-				__assert_sigpipe_ok "$myfail" || return 1
+				__assert_sigpipe_ok "$myfail"
 			else
 				local cwd_dest=${x##*/}
 				cwd_dest=${cwd_dest%.*}
-				if ! $1 -c -- "${srcdir}${x}" > "${cwd_dest}"; then
-					__helpers_die "$myfail"
-					return 1
-				fi
+				$1 -c -- "${srcdir}${x}" > "${cwd_dest}" || die "$myfail"
 			fi
 		}
 
-		myfail="unpack: failure unpacking ${x}"
+		myfail="failure unpacking ${x}"
 		case "${suffix_insensitive}" in
 			tar)
 				if ___eapi_unpack_is_case_sensitive && \
@@ -381,10 +375,7 @@ unpack() {
 						"suffix '${suffix}' which is unofficially supported" \
 						"with EAPI '${EAPI}'. Instead use 'tar'."
 				fi
-				if ! tar xof "$srcdir$x"; then
-					__helpers_die "$myfail"
-					return 1
-				fi
+				tar xof "$srcdir$x" || die "$myfail"
 				;;
 			tgz)
 				if ___eapi_unpack_is_case_sensitive && \
@@ -393,10 +384,7 @@ unpack() {
 						"suffix '${suffix}' which is unofficially supported" \
 						"with EAPI '${EAPI}'. Instead use 'tgz'."
 				fi
-				if ! tar xozf "$srcdir$x"; then
-					__helpers_die "$myfail"
-					return 1
-				fi
+				tar xozf "$srcdir$x" || die "$myfail"
 				;;
 			tbz|tbz2)
 				if ___eapi_unpack_is_case_sensitive && \
@@ -406,7 +394,7 @@ unpack() {
 						"with EAPI '${EAPI}'. Instead use 'tbz' or 'tbz2'."
 				fi
 				${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "$srcdir$x" | tar xof -
-				__assert_sigpipe_ok "$myfail" || return 1
+				__assert_sigpipe_ok "$myfail"
 				;;
 			zip|jar)
 				if ___eapi_unpack_is_case_sensitive && \
@@ -418,10 +406,8 @@ unpack() {
 				fi
 				# unzip will interactively prompt under some error conditions,
 				# as reported in bug #336285
-				if ! unzip -qo "${srcdir}${x}"; then
-					__helpers_die "$myfail"
-					return 1
-				fi < <(set +x ; while true ; do echo n || break ; done)
+				( set +x ; while true ; do echo n || break ; done ) | \
+				unzip -qo "${srcdir}${x}" || die "$myfail"
 				;;
 			gz|z)
 				if ___eapi_unpack_is_case_sensitive && \
@@ -430,7 +416,7 @@ unpack() {
 						"suffix '${suffix}' which is unofficially supported" \
 						"with EAPI '${EAPI}'. Instead use 'gz', 'z', or 'Z'."
 				fi
-				__unpack_tar "gzip -d" || return 1
+				__unpack_tar "gzip -d"
 				;;
 			bz2|bz)
 				if ___eapi_unpack_is_case_sensitive && \
@@ -439,8 +425,7 @@ unpack() {
 						"suffix '${suffix}' which is unofficially supported" \
 						"with EAPI '${EAPI}'. Instead use 'bz' or 'bz2'."
 				fi
-				__unpack_tar "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}" \
-					|| return 1
+				__unpack_tar "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}"
 				;;
 			7z)
 				local my_output
@@ -457,10 +442,7 @@ unpack() {
 						"suffix '${suffix}' which is unofficially supported" \
 						"with EAPI '${EAPI}'. Instead use 'rar' or 'RAR'."
 				fi
-				if ! unrar x -idq -o+ "${srcdir}${x}"; then
-					__helpers_die "$myfail"
-					return 1
-				fi
+				unrar x -idq -o+ "${srcdir}${x}" || die "$myfail"
 				;;
 			lha|lzh)
 				if ___eapi_unpack_is_case_sensitive && \
@@ -470,10 +452,7 @@ unpack() {
 						"with EAPI '${EAPI}'." \
 						"Instead use 'LHA', 'LHa', 'lha', or 'lzh'."
 				fi
-				if ! lha xfq "${srcdir}${x}"; then
-					__helpers_die "$myfail"
-					return 1
-				fi
+				lha xfq "${srcdir}${x}" || die "$myfail"
 				;;
 			a)
 				if ___eapi_unpack_is_case_sensitive && \
@@ -482,10 +461,7 @@ unpack() {
 						"suffix '${suffix}' which is unofficially supported" \
 						"with EAPI '${EAPI}'. Instead use 'a'."
 				fi
-				if ! ar x "${srcdir}${x}"; then
-					__helpers_die "$myfail"
-					return 1
-				fi
+				ar x "${srcdir}${x}" || die "$myfail"
 				;;
 			deb)
 				if ___eapi_unpack_is_case_sensitive && \
@@ -508,32 +484,20 @@ unpack() {
 						# deb2targz always extracts into the same directory as
 						# the source file, so create a symlink in the current
 						# working directory if necessary.
-						if ! ln -sf "$srcdir$x" "$y"; then
-							__helpers_die "$myfail"
-							return 1
-						fi
+						ln -sf "$srcdir$x" "$y" || die "$myfail"
 						created_symlink=1
 					fi
-					if ! deb2targz "$y"; then
-						__helpers_die "$myfail"
-						return 1
-					fi
+					deb2targz "$y" || die "$myfail"
 					if [ $created_symlink = 1 ] ; then
 						# Clean up the symlink so the ebuild
 						# doesn't inadvertently install it.
 						rm -f "$y"
 					fi
-					if ! mv -f "${y%.deb}".tar.gz data.tar.gz; then
-						if ! mv -f "${y%.deb}".tar.xz data.tar.xz; then
-							__helpers_die "$myfail"
-							return 1
-						fi
-					fi
+					mv -f "${y%.deb}".tar.gz data.tar.gz \
+						|| mv -f "${y%.deb}".tar.xz data.tar.xz \
+						|| die "$myfail"
 				else
-					if ! ar x "$srcdir$x"; then
-						__helpers_die "$myfail"
-						return 1
-					fi
+					ar x "$srcdir$x" || die "$myfail"
 				fi
 				;;
 			lzma)
@@ -543,7 +507,7 @@ unpack() {
 						"suffix '${suffix}' which is unofficially supported" \
 						"with EAPI '${EAPI}'. Instead use 'lzma'."
 				fi
-				__unpack_tar "lzma -d" || return 1
+				__unpack_tar "lzma -d"
 				;;
 			xz)
 				if ___eapi_unpack_is_case_sensitive && \
@@ -553,7 +517,7 @@ unpack() {
 						"with EAPI '${EAPI}'. Instead use 'xz'."
 				fi
 				if ___eapi_unpack_supports_xz; then
-					__unpack_tar "xz -d" || return 1
+					__unpack_tar "xz -d"
 				else
 					__vecho "unpack ${x}: file format not recognized. Ignoring."
 				fi
@@ -566,10 +530,7 @@ unpack() {
 						"with EAPI '${EAPI}'. Instead use 'txz'."
 				fi
 				if ___eapi_unpack_supports_txz; then
-					if ! tar xof "$srcdir$x"; then
-						__helpers_die "$myfail"
-						return 1
-					fi
+					tar xof "$srcdir$x" || die "$myfail"
 				else
 					__vecho "unpack ${x}: file format not recognized. Ignoring."
 				fi