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 <[email protected]> AuthorDate: Sat Feb 4 23:48:42 2012 Commit: Mike Frysinger <[email protected]> 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 <[email protected]> --- eclass/unpacker.eclass | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/eclass/unpacker.eclass b/eclass/unpacker.eclass index 5ebc67a7b9ab..b366e49342a1 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}')" -- 2.52.0
