1 |
commit: 778904f14cd059327453557a26eaabc3c42ddc5c |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Sep 24 14:27:09 2022 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Sep 27 20:28:03 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=778904f1 |
7 |
|
8 |
unpacker.eclass: Add on-the-fly .gpkg.tar unpacking support |
9 |
|
10 |
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> |
11 |
|
12 |
eclass/tests/unpacker.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ |
13 |
eclass/unpacker.eclass | 38 ++++++++++++++++++++++++++++++++++++++ |
14 |
2 files changed, 85 insertions(+) |
15 |
|
16 |
diff --git a/eclass/tests/unpacker.sh b/eclass/tests/unpacker.sh |
17 |
index 1f2327054521..40bde1bf30de 100755 |
18 |
--- a/eclass/tests/unpacker.sh |
19 |
+++ b/eclass/tests/unpacker.sh |
20 |
@@ -136,6 +136,43 @@ test_deb() { |
21 |
"create_deb '${suffix}' '${tool_cmd}' \${archive} \${TESTFILE}" |
22 |
} |
23 |
|
24 |
+create_gpkg() { |
25 |
+ local suffix=${1} |
26 |
+ local tool=${2} |
27 |
+ local archive=${3} |
28 |
+ local infile=${4} |
29 |
+ local gpkg_dir=${archive%.gpkg.tar} |
30 |
+ |
31 |
+ mkdir image metadata "${gpkg_dir}" || die |
32 |
+ cp "${infile}" image/ || die |
33 |
+ tar -c metadata | ${tool} > "${gpkg_dir}/metadata.tar${suffix}" |
34 |
+ assert "packing metadata.tar${suffix} failed" |
35 |
+ : > "${gpkg_dir}/metadata.tar${suffix}.sig" || die |
36 |
+ tar -c image | ${tool} > "${gpkg_dir}/image.tar${suffix}" |
37 |
+ assert "packing image.tar${suffix} failed" |
38 |
+ : > "${gpkg_dir}/image.tar${suffix}.sig" || die |
39 |
+ : > "${gpkg_dir}"/gpkg-1 || die |
40 |
+ tar -cf "${archive}" --format=ustar \ |
41 |
+ "${gpkg_dir}"/{gpkg-1,{metadata,image}.tar"${suffix}"} || die |
42 |
+ rm -r image metadata "${gpkg_dir}" || die |
43 |
+} |
44 |
+ |
45 |
+test_gpkg() { |
46 |
+ local suffix=${1} |
47 |
+ local tool=${2} |
48 |
+ local tool_cmd |
49 |
+ |
50 |
+ if [[ -n ${tool} ]]; then |
51 |
+ tool_cmd="${tool} -c" |
52 |
+ else |
53 |
+ tool_cmd=cat |
54 |
+ fi |
55 |
+ |
56 |
+ test_unpack "test-${tool}-1.2.3-1.gpkg.tar" \ |
57 |
+ "test-${tool}-1.2.3-1/image/test.in" "tar ${tool}" \ |
58 |
+ "create_gpkg '${suffix}' '${tool_cmd}' \${archive} \${TESTFILE}" |
59 |
+} |
60 |
+ |
61 |
test_reject_junk() { |
62 |
local suffix=${1} |
63 |
local archive=test${1} |
64 |
@@ -209,6 +246,16 @@ test_deb .xz xz |
65 |
test_deb .bz2 bzip2 |
66 |
test_deb .lzma lzma |
67 |
|
68 |
+test_gpkg |
69 |
+test_gpkg .gz gzip |
70 |
+test_gpkg .bz2 bzip2 |
71 |
+test_gpkg .lz4 lz4 |
72 |
+test_gpkg .lz lzip |
73 |
+test_gpkg .lzma lzma |
74 |
+test_gpkg .lzo lzop |
75 |
+test_gpkg .xz xz |
76 |
+test_gpkg .zst zstd |
77 |
+ |
78 |
test_unpack test.zip test.in zip 'zip -q ${archive} ${TESTFILE}' |
79 |
# test handling non-adjusted zip with junk prepended |
80 |
test_unpack test.zip test.in zip \ |
81 |
|
82 |
diff --git a/eclass/unpacker.eclass b/eclass/unpacker.eclass |
83 |
index a64c5eae18aa..70a46ac19709 100644 |
84 |
--- a/eclass/unpacker.eclass |
85 |
+++ b/eclass/unpacker.eclass |
86 |
@@ -408,6 +408,42 @@ _unpacker_get_decompressor() { |
87 |
esac |
88 |
} |
89 |
|
90 |
+# @FUNCTION: unpack_gpkg |
91 |
+# @USAGE: <gpkg file> |
92 |
+# @DESCRIPTION: |
93 |
+# Unpack the image subarchive of a GPKG package on-the-fly, preserving |
94 |
+# the original directory structure (i.e. into <gpkg-dir>/image). |
95 |
+unpack_gpkg() { |
96 |
+ [[ $# -eq 1 ]] || die "Usage: ${FUNCNAME} <file>" |
97 |
+ |
98 |
+ local gpkg=$(find_unpackable_file "$1") |
99 |
+ unpack_banner "${gpkg}" |
100 |
+ |
101 |
+ local l images=() |
102 |
+ while read -r l; do |
103 |
+ case ${l} in |
104 |
+ */image.tar*.sig) |
105 |
+ ;; |
106 |
+ */image.tar*) |
107 |
+ images+=( "${l}" ) |
108 |
+ ;; |
109 |
+ esac |
110 |
+ done < <(tar -tf "${gpkg}" || die "unable to list ${gpkg}") |
111 |
+ |
112 |
+ if [[ ${#images[@]} -eq 0 ]]; then |
113 |
+ die "No image.tar found in ${gpkg}" |
114 |
+ elif [[ ${#images[@]} -gt 1 ]]; then |
115 |
+ die "More than one image.tar found in ${gpkg}" |
116 |
+ fi |
117 |
+ |
118 |
+ local decomp=$(_unpacker_get_decompressor "${images[0]}") |
119 |
+ local dirname=${images[0]%/*} |
120 |
+ mkdir -p "${dirname}" || die |
121 |
+ tar -xOf "${gpkg}" "${images[0]}" | ${decomp:-cat} | |
122 |
+ tar --no-same-owner -xC "${dirname}" |
123 |
+ assert "Unpacking ${gpkg} failed" |
124 |
+} |
125 |
+ |
126 |
# @FUNCTION: _unpacker |
127 |
# @USAGE: <one archive to unpack> |
128 |
# @INTERNAL |
129 |
@@ -427,6 +463,8 @@ _unpacker() { |
130 |
# then figure out if there are any archiving aspects |
131 |
local arch="" |
132 |
case ${m} in |
133 |
+ *.gpkg.tar) |
134 |
+ arch="unpack_gpkg" ;; |
135 |
*.tgz|*.tbz|*.tbz2|*.txz|*.tar.*|*.tar) |
136 |
arch="tar --no-same-owner -xof" ;; |
137 |
*.cpio.*|*.cpio) |