commit: ec90042d02d365b72f25da5a7ff5d5298df80021
Author: Eli Schwartz <eschwartz <AT> gentoo <DOT> org>
AuthorDate: Tue Jan 27 02:22:33 2026 +0000
Commit: Eli Schwartz <eschwartz <AT> gentoo <DOT> org>
CommitDate: Thu Mar 12 15:21:07 2026 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ec90042d
unpacker.eclass: reduce unreadable deduplication in unpack_pdv
If you look hard enough, every single code branch uses the same byte
range processor, repetitively repeated again (and also again) and then
branches on tar or gzip depending on the inner contents. That final
command is better suited as an array, so we can run the main command
*once*.
It is not clear to me why this function has "true" followed by commented
out dies. It lacks real explanation, and dates back to
gentoo-historical-2.git:
```
commit 557d48b91a21b650f2fadd609fc8bee679dc1af3
Author: Mike Frysinger <vapier <AT> gentoo.org>
AuthorDate: Sat Feb 4 23:48:42 2012
Commit: Mike Frysinger <vapier <AT> gentoo.org>
CommitDate: Sat Feb 4 23:48:42 2012
initial unpacker eclass
```
Do I dare add the relevant `pipestatus || die` here? Not really, this
code already terrifies me. But *perhaps* running the command here once
would solve whatever concerns the year 2012 had about this code. Maybe.
Possibly. You be the judge!
Signed-off-by: Eli Schwartz <eschwartz <AT> gentoo.org>
eclass/unpacker.eclass | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/eclass/unpacker.eclass b/eclass/unpacker.eclass
index 524221040350..a31d2580b4e8 100644
--- a/eclass/unpacker.eclass
+++ b/eclass/unpacker.eclass
@@ -142,28 +142,23 @@ unpack_pdv() {
# | dd ibs=${tailskip} skip=1 \
# | gzip -dc \
# > ${datafile}
+ local decompress=(cat)
if [ ${iscompressed} -eq 1 ] ; then
if [ ${istar} -eq 1 ] ; then
- tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \
- | head -c $((${metaskip}-${tailskip})) \
- | tar -xzf -
+ decompress=(tar -xzf -)
else
- tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \
- | head -c $((${metaskip}-${tailskip})) \
- | gzip -dc \
- > ${datafile}
+ decompress=(gzip -dc)
fi
else
if [ ${istar} -eq 1 ] ; then
- tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \
- | head -c $((${metaskip}-${tailskip})) \
- | tar --no-same-owner -xf -
- else
- tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \
- | head -c $((${metaskip}-${tailskip})) \
- > ${datafile}
+ decompress=(tar --no-same-owner -xf -)
fi
+
fi
+
+ tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \
+ | head -c $((${metaskip}-${tailskip})) \
+ "${decompress[@]}" > "${datafile}"
true
#[ -s "${datafile}" ] || die "failure unpacking pdv ('${metaskip}'
'${tailskip}' '${datafile}')"
#assert "failure unpacking pdv ('${metaskip}' '${tailskip}'
'${datafile}')"