commit: c02556ffeae95b01a6a349d6e41f3323afde8306
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Tue May 27 04:22:11 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 30 08:14:19 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=c02556ff
phase-helpers.sh: name and employ unpack() variables coherently
This commit accomplishes the following:-
- introduces a new 'inner_suffix' variable
- introduces a new 'basename' variable
- renames the 'x' variable to 'f'
- drops the 'cwd_dest' variable
- drops the 'y' variable
The rationale for these changes is described herewith.
Firstly, 'f' is slightly more intuitive as the name of a variable whose
value refers to a regular file (or a symlink to one). While 'x' might
commonly be inferred as an item collected from the positional parameter
list, it affords the reader no immediate insight as to its provenance.
Secondly, the basename of 'f' is considered not only within the body of
the loop that iterates over the positional parameters, but also within
the body of the __unpack_tar() helper function. In the former case, it
is calculated while handling deb archives, just before clobbering the
value of 'y'. In the latter case, it is calculated and assigned to a
variable named 'cwd_dest'. Instead, simply assign the basename to the
rather appropriately named 'basename' variable.
Thirdly, drop the 'y' variable. Not only does its name convey no
semantic meaning, it was being employed for two starkly contrasting
purposes:
1) holding the value of the inner suffix e.g. "f.tar.gz" -> "tar"
2) holding the basename of 'f'
As regards the first case, the __unpack_tar() now defines a localised
'inner_suffix' variable. As regards the second case, it is now covered
by the 'basename' variable.
I am of the view that these otherwise unobtrusive changes render the
intended behaviour of the unpack() function markedly more apparent,
especially for those who may be reading the code for the first time.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/phase-helpers.sh | 82 ++++++++++++++++++++++++++--------------------------
1 file changed, 41 insertions(+), 41 deletions(-)
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index 444575a7c6..41175886dd 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -326,38 +326,39 @@ use_enable() {
}
unpack() {
- local srcdir
- local x
- local y
- local suffix
local suffix_known
+ local basename
local myfail
+ local srcdir
+ local suffix
+ local f
[[ -z "$*" ]] && die "Nothing passed to the 'unpack' command"
__unpack_tar() {
- if [[ ${y,,} == tar ]] \
- && ! ___eapi_unpack_is_case_sensitive \
- || [[ ${y} == tar ]]; then
- $1 -c -- "${srcdir}${x}" | tar xof -
+ local inner_suffix
+
+ inner_suffix=${basename%.*} inner_suffix=${inner_suffix##*.}
+ if ! ___eapi_unpack_is_case_sensitive; then
+ inner_suffix=${inner_suffix,,}
+ fi
+ if [[ ${inner_suffix} == tar ]]; then
+ $1 -c -- "${srcdir}${f}" | tar xof -
__assert_sigpipe_ok "${myfail}"
else
- local cwd_dest=${x##*/}
- cwd_dest=${cwd_dest%.*}
- $1 -c -- "${srcdir}${x}" > "${cwd_dest}" || die
"${myfail}"
+ $1 -c -- "${srcdir}${f}" > "${basename%.*}" || die
"${myfail}"
fi
}
- for x in "$@"; do
- suffix=${x##*.}
- y=${x%.*}
- y=${y##*.}
+ for f in "$@"; do
+ basename=${f##*/}
+ suffix=${basename##*.}
# wrt PMS 12.3.15 Misc Commands
- if [[ ${x} != */* ]]; then
+ if [[ ${f} != */* ]]; then
# filename without path of any kind
srcdir=${DISTDIR}/
- elif [[ ${x} == ./* ]]; then
+ elif [[ ${f} == ./* ]]; then
# relative path starting with './'
srcdir=
else
@@ -366,18 +367,18 @@ unpack() {
# EAPI 6 allows absolute and deep relative paths
srcdir=
- if [[ ${x} == ${DISTDIR%/}/* ]]; then
+ if [[ ${f} == ${DISTDIR%/}/* ]]; then
eqawarn "QA Notice: unpack called with
redundant \${DISTDIR} in path"
fi
- elif [[ ${x} == ${DISTDIR%/}/* ]]; then
+ elif [[ ${f} == ${DISTDIR%/}/* ]]; then
die "Arguments to unpack() cannot begin with
\${DISTDIR} in EAPI ${EAPI}"
- elif [[ ${x} == /* ]] ; then
+ elif [[ ${f} == /* ]] ; then
die "Arguments to unpack() cannot be absolute
in EAPI ${EAPI}"
else
die "Relative paths to unpack() must be
prefixed with './' in EAPI ${EAPI}"
fi
fi
- [[ ! -s ${srcdir}${x} ]] && die "unpack: ${x} does not exist"
+ [[ ! -s ${srcdir}${f} ]] && die "unpack: ${f} does not exist"
suffix_known=""
case ${suffix,,} in
@@ -395,29 +396,29 @@ unpack() {
fi
if [[ -n ${suffix_known} ]]; then
- __vecho ">>> Unpacking ${x} to ${PWD}"
+ __vecho ">>> Unpacking ${f} to ${PWD}"
else
- __vecho "=== Skipping unpack of ${x}"
+ __vecho "=== Skipping unpack of ${f}"
continue
fi
- myfail="unpack: failure unpacking ${x}"
+ myfail="unpack: failure unpacking ${f}"
case ${suffix,,} in
tar)
- tar xof "${srcdir}${x}" || die "${myfail}"
+ tar xof "${srcdir}${f}" || die "${myfail}"
;;
tgz)
- tar xozf "${srcdir}${x}" || die "${myfail}"
+ tar xozf "${srcdir}${f}" || die "${myfail}"
;;
tbz|tbz2)
-
${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "${srcdir}${x}" |
tar xof -
+
${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "${srcdir}${f}" |
tar xof -
__assert_sigpipe_ok "${myfail}"
;;
zip|jar)
# unzip will interactively prompt under some
error conditions,
# as reported in bug #336285
( set +x ; while true ; do echo n || break ;
done ) | \
- unzip -qo "${srcdir}${x}" || die "${myfail}"
+ unzip -qo "${srcdir}${f}" || die "${myfail}"
;;
gz|z)
__unpack_tar "gzip -d"
@@ -427,20 +428,20 @@ unpack() {
;;
7z)
local my_output
- my_output="$(7z x -y "${srcdir}${x}")"
+ my_output="$(7z x -y "${srcdir}${f}")"
if [[ $? -ne 0 ]]; then
echo "${my_output}" >&2
die "${myfail}"
fi
;;
rar)
- unrar x -idq -o+ "${srcdir}${x}" || die
"${myfail}"
+ unrar x -idq -o+ "${srcdir}${f}" || die
"${myfail}"
;;
lha|lzh)
- lha xfq "${srcdir}${x}" || die "${myfail}"
+ lha xfq "${srcdir}${f}" || die "${myfail}"
;;
a)
- ar x "${srcdir}${x}" || die "${myfail}"
+ ar x "${srcdir}${f}" || die "${myfail}"
;;
deb)
# Unpacking .deb archives can not always be
done with
@@ -451,29 +452,28 @@ unpack() {
# installed.
if [[ $(ar --version 2>/dev/null) != "GNU ar"*
]] && \
type -P deb2targz > /dev/null; then
- y=${x##*/}
local created_symlink=0
- if [[ ! "${srcdir}${x}" -ef "${y}" ]];
then
+ if [[ ! "${srcdir}${f}" -ef
"${basename}" ]]; then
# deb2targz always extracts
into the same directory as
# the source file, so create a
symlink in the current
# working directory if
necessary.
- ln -sf "${srcdir}${x}" "${y}"
|| die "${myfail}"
+ ln -sf "${srcdir}${f}"
"${basename}" || die "${myfail}"
created_symlink=1
fi
- deb2targz "${y}" || die "${myfail}"
+ deb2targz "${basename}" || die
"${myfail}"
if [[ ${created_symlink} = 1 ]]; then
# Clean up the symlink so the
ebuild
# doesn't inadvertently install
it.
- rm -f "${y}"
+ rm -f "${basename}"
fi
- mv -f "${y%.deb}".tar.gz data.tar.gz \
- || mv -f "${y%.deb}".tar.xz
data.tar.xz \
+ mv -f "${basename%.deb}".tar.gz
data.tar.gz \
+ || mv -f
"${basename%.deb}".tar.xz data.tar.xz \
|| die "${myfail}"
else
- ar x "${srcdir}${x}" || die "${myfail}"
+ ar x "${srcdir}${f}" || die "${myfail}"
fi
;;
lzma)
@@ -483,7 +483,7 @@ unpack() {
__unpack_tar "xz -T$(___makeopts_jobs) -d"
;;
txz)
- XZ_OPT="-T$(___makeopts_jobs)" tar xof
"${srcdir}${x}" || die "${myfail}"
+ XZ_OPT="-T$(___makeopts_jobs)" tar xof
"${srcdir}${f}" || die "${myfail}"
;;
esac
done