From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH 10/15] unpacker.eclass: Add on-the-fly .gpkg.tar unpacking support
Date: Sun, 25 Sep 2022 20:23:12 +0200 [thread overview]
Message-ID: <20220925182317.1559529-11-mgorny@gentoo.org> (raw)
In-Reply-To: <20220925182317.1559529-1-mgorny@gentoo.org>
Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
eclass/tests/unpacker.sh | 47 ++++++++++++++++++++++++++++++++++++++++
eclass/unpacker.eclass | 38 ++++++++++++++++++++++++++++++++
2 files changed, 85 insertions(+)
diff --git a/eclass/tests/unpacker.sh b/eclass/tests/unpacker.sh
index 60b651759a52..bbbfa32623ab 100755
--- a/eclass/tests/unpacker.sh
+++ b/eclass/tests/unpacker.sh
@@ -136,6 +136,43 @@ test_deb() {
"create_deb '${suffix}' '${tool_cmd}' \${archive} \${TESTFILE}"
}
+create_gpkg() {
+ local suffix=${1}
+ local tool=${2}
+ local archive=${3}
+ local infile=${4}
+ local gpkg_dir=${archive%.gpkg.tar}
+
+ mkdir image metadata "${gpkg_dir}" || die
+ cp "${infile}" image/ || die
+ tar -c metadata | ${tool} > "${gpkg_dir}/metadata.tar${suffix}"
+ assert "packing metadata.tar${suffix} failed"
+ : > "${gpkg_dir}/metadata.tar${suffix}.sig" || die
+ tar -c image | ${tool} > "${gpkg_dir}/image.tar${suffix}"
+ assert "packing image.tar${suffix} failed"
+ : > "${gpkg_dir}/image.tar${suffix}.sig" || die
+ : > "${gpkg_dir}"/gpkg-1 || die
+ tar -cf "${archive}" --format=ustar \
+ "${gpkg_dir}"/{gpkg-1,{metadata,image}.tar"${suffix}"} || die
+ rm -r image metadata "${gpkg_dir}" || die
+}
+
+test_gpkg() {
+ local suffix=${1}
+ local tool=${2}
+ local tool_cmd
+
+ if [[ -n ${tool} ]]; then
+ tool_cmd="${tool} -c"
+ else
+ tool_cmd=cat
+ fi
+
+ test_unpack "test-${tool}-1.2.3-1.gpkg.tar" \
+ "test-${tool}-1.2.3-1/image/test.in" "tar ${tool}" \
+ "create_gpkg '${suffix}' '${tool_cmd}' \${archive} \${TESTFILE}"
+}
+
test_reject_junk() {
local suffix=${1}
local archive=test${1}
@@ -209,6 +246,16 @@ test_deb .xz xz
test_deb .bz2 bzip2
test_deb .lzma lzma
+test_gpkg
+test_gpkg .gz gzip
+test_gpkg .bz2 bzip2
+test_gpkg .lz4 lz4
+test_gpkg .lz lzip
+test_gpkg .lzma lzma
+test_gpkg .lzo lzop
+test_gpkg .xz xz
+test_gpkg .zst zstd
+
test_unpack test.zip test.in zip 'zip -q ${archive} ${TESTFILE}'
# test handling non-adjusted zip with junk prepended
test_unpack test.zip test.in zip \
diff --git a/eclass/unpacker.eclass b/eclass/unpacker.eclass
index a64c5eae18aa..70a46ac19709 100644
--- a/eclass/unpacker.eclass
+++ b/eclass/unpacker.eclass
@@ -408,6 +408,42 @@ _unpacker_get_decompressor() {
esac
}
+# @FUNCTION: unpack_gpkg
+# @USAGE: <gpkg file>
+# @DESCRIPTION:
+# Unpack the image subarchive of a GPKG package on-the-fly, preserving
+# the original directory structure (i.e. into <gpkg-dir>/image).
+unpack_gpkg() {
+ [[ $# -eq 1 ]] || die "Usage: ${FUNCNAME} <file>"
+
+ local gpkg=$(find_unpackable_file "$1")
+ unpack_banner "${gpkg}"
+
+ local l images=()
+ while read -r l; do
+ case ${l} in
+ */image.tar*.sig)
+ ;;
+ */image.tar*)
+ images+=( "${l}" )
+ ;;
+ esac
+ done < <(tar -tf "${gpkg}" || die "unable to list ${gpkg}")
+
+ if [[ ${#images[@]} -eq 0 ]]; then
+ die "No image.tar found in ${gpkg}"
+ elif [[ ${#images[@]} -gt 1 ]]; then
+ die "More than one image.tar found in ${gpkg}"
+ fi
+
+ local decomp=$(_unpacker_get_decompressor "${images[0]}")
+ local dirname=${images[0]%/*}
+ mkdir -p "${dirname}" || die
+ tar -xOf "${gpkg}" "${images[0]}" | ${decomp:-cat} |
+ tar --no-same-owner -xC "${dirname}"
+ assert "Unpacking ${gpkg} failed"
+}
+
# @FUNCTION: _unpacker
# @USAGE: <one archive to unpack>
# @INTERNAL
@@ -427,6 +463,8 @@ _unpacker() {
# then figure out if there are any archiving aspects
local arch=""
case ${m} in
+ *.gpkg.tar)
+ arch="unpack_gpkg" ;;
*.tgz|*.tbz|*.tbz2|*.txz|*.tar.*|*.tar)
arch="tar --no-same-owner -xof" ;;
*.cpio.*|*.cpio)
--
2.37.3
next prev parent reply other threads:[~2022-09-25 18:26 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-25 18:23 [gentoo-dev] [PATCH 00/15] unpacker.eclass: Tests, bugfixes and GPKG support Michał Górny
2022-09-25 18:23 ` [gentoo-dev] [PATCH 01/15] eclass/tests: Add tests for unpacker.eclass Michał Górny
2022-09-25 18:23 ` [gentoo-dev] [PATCH 02/15] unpacker.eclass: Remove `-f` from zstd arguments Michał Górny
2022-09-25 18:23 ` [gentoo-dev] [PATCH 03/15] unpacker.eclass: Fix unpack_7z to respect the exit status Michał Górny
2022-09-25 18:23 ` [gentoo-dev] [PATCH 04/15] unpacker.eclass: Remove support for EAPI 5 Michał Górny
2022-09-25 18:23 ` [gentoo-dev] [PATCH 05/15] unpacker.eclass: Use bash substitution instead of tr for lowercase Michał Górny
2022-09-25 18:23 ` [gentoo-dev] [PATCH 06/15] unpacker.eclass: Use lowercase in unpacker_src_uri_depends Michał Górny
2022-09-25 21:04 ` John Helmert III
2022-09-25 21:06 ` John Helmert III
2022-09-25 18:23 ` [gentoo-dev] [PATCH 07/15] unpacker.eclass: Remove uppercase RAR/LHA variants Michał Górny
2022-09-25 18:23 ` [gentoo-dev] [PATCH 08/15] unpacker.eclass: Move decompressor recognition into a function Michał Górny
2022-09-25 18:23 ` [gentoo-dev] [PATCH 09/15] unpacker.eclass: Add support for .lz4 and .lzo compression Michał Górny
2022-09-25 18:23 ` Michał Górny [this message]
2022-09-25 18:23 ` [gentoo-dev] [PATCH 11/15] sys-kernel/gentoo-kernel-bin: Use unpacker.eclass for .gpkg.tar Michał Górny
2022-09-25 18:23 ` [gentoo-dev] [PATCH 12/15] unpacker.eclass: decompress xz in parallel Michał Górny
2022-09-25 18:23 ` [gentoo-dev] [PATCH 13/15] unpacker.eclass: Support lbzip2 as parallel bz2 decompressor Michał Górny
2022-09-25 18:23 ` [gentoo-dev] [PATCH 14/15] unpacker.eclass: Fix handling GNU ar archives in hand-weaved impl Michał Górny
2022-09-25 18:23 ` [gentoo-dev] [PATCH 15/15] unpacker.eclass: Unpack .deb packages on-the-fly as well Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220925182317.1559529-11-mgorny@gentoo.org \
--to=mgorny@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox