Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 08/15] unpacker.eclass: Move decompressor recognition into a function
Date: Sun, 25 Sep 2022 18:25:43
Message-Id: 20220925182317.1559529-9-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH 00/15] unpacker.eclass: Tests, bugfixes and GPKG support by "Michał Górny"
1 Signed-off-by: Michał Górny <mgorny@g.o>
2 ---
3 eclass/unpacker.eclass | 44 +++++++++++++++++++++++++-----------------
4 1 file changed, 26 insertions(+), 18 deletions(-)
5
6 diff --git a/eclass/unpacker.eclass b/eclass/unpacker.eclass
7 index ca6761488100..8fb1c2abd1cf 100644
8 --- a/eclass/unpacker.eclass
9 +++ b/eclass/unpacker.eclass
10 @@ -379,6 +379,31 @@ unpack_lha() {
11 lha xfq "${lha}" || die "unpacking ${lha} failed (arch=unpack_lha)"
12 }
13
14 +# @FUNCTION: _unpacker_get_decompressor
15 +# @INTERNAL
16 +# @USAGE: <filename>
17 +# @DESCRIPTION:
18 +# Get decompressor command for specified filename.
19 +_unpacker_get_decompressor() {
20 + case ${1} in
21 + *.bz2|*.tbz|*.tbz2)
22 + local bzcmd=${PORTAGE_BZIP2_COMMAND:-$(type -P pbzip2 || type -P bzip2)}
23 + local bzuncmd=${PORTAGE_BUNZIP2_COMMAND:-${bzcmd} -d}
24 + : ${UNPACKER_BZ2:=${bzuncmd}}
25 + echo "${UNPACKER_BZ2} -c"
26 + ;;
27 + *.z|*.gz|*.tgz)
28 + echo "gzip -dc" ;;
29 + *.lzma|*.xz|*.txz)
30 + echo "xz -dc" ;;
31 + *.lz)
32 + : ${UNPACKER_LZIP:=$(type -P plzip || type -P pdlzip || type -P lzip)}
33 + echo "${UNPACKER_LZIP} -dc" ;;
34 + *.zst)
35 + echo "zstd -dc" ;;
36 + esac
37 +}
38 +
39 # @FUNCTION: _unpacker
40 # @USAGE: <one archive to unpack>
41 # @INTERNAL
42 @@ -393,24 +418,7 @@ _unpacker() {
43 a=$(find_unpackable_file "${a}")
44
45 # first figure out the decompression method
46 - local comp=""
47 - case ${m} in
48 - *.bz2|*.tbz|*.tbz2)
49 - local bzcmd=${PORTAGE_BZIP2_COMMAND:-$(type -P pbzip2 || type -P bzip2)}
50 - local bzuncmd=${PORTAGE_BUNZIP2_COMMAND:-${bzcmd} -d}
51 - : ${UNPACKER_BZ2:=${bzuncmd}}
52 - comp="${UNPACKER_BZ2} -c"
53 - ;;
54 - *.z|*.gz|*.tgz)
55 - comp="gzip -dc" ;;
56 - *.lzma|*.xz|*.txz)
57 - comp="xz -dc" ;;
58 - *.lz)
59 - : ${UNPACKER_LZIP:=$(type -P plzip || type -P pdlzip || type -P lzip)}
60 - comp="${UNPACKER_LZIP} -dc" ;;
61 - *.zst)
62 - comp="zstd -dc" ;;
63 - esac
64 + local comp=$(_unpacker_get_decompressor "${m}")
65
66 # then figure out if there are any archiving aspects
67 local arch=""
68 --
69 2.37.3