From: Benjamin Drung <benjamin.drung@canonical.com>
Date: Wed, 6 Aug 2025 18:57:15 +0200
Subject: refactor(lsinitrd): introduce cpio_extract function

In preparation to support 3cpio as alternative archive tool, move the
cpio extraction call into `cpio_extract`.

Forwarded: https://github.com/dracut-ng/dracut-ng/pull/1530
---
 lsinitrd.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lsinitrd.sh b/lsinitrd.sh
index 2de972a..e6b9120 100755
--- a/lsinitrd.sh
+++ b/lsinitrd.sh
@@ -189,6 +189,11 @@ dracutlibdirs() {
 SQUASH_TMPFILE=""
 SQUASH_EXTRACT="$TMPDIR/squash-extract"
 
+# Takes optional pattern arguments
+cpio_extract() {
+    $CAT "$image" 2> /dev/null | cpio -id --quiet $verbose -- "$@"
+}
+
 extract_squash_img() {
     local _img _tmp
 
@@ -334,13 +339,13 @@ unpack_files() {
                     cp -rf "$SQUASH_EXTRACT/$f" "$f"
                     ;;
                 *)
-                    $CAT "$image" 2> /dev/null | cpio -id --quiet $verbose "$f"
+                    cpio_extract "$f"
                     ((ret += $?))
                     ;;
             esac
         done
     else
-        $CAT "$image" 2> /dev/null | cpio -id --quiet $verbose
+        cpio_extract
         ((ret += $?))
 
         extract_squash_img || return 0
