public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: lvivier@redhat.com, passt-dev@passt.top,
	David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 4/4] Remove unnecessary cpio_init function
Date: Fri, 22 Mar 2024 13:27:39 +1100	[thread overview]
Message-ID: <20240322022739.2746102-5-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20240322022739.2746102-1-david@gibson.dropbear.id.au>

The cpio_init function is now only every called with the "discard" option.
But, moreover, what it does is create an initial mostly empty archive which
will just get overwritten by the final archive.

So, it's entirely unnecessary except for one subtlety.  Our use of realpath
when generating the final output requires that a file already exist in the
output location.  We can fix that by shuffling some things out of a
subshell, removing the need for realpath.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 mbuto | 31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)

diff --git a/mbuto b/mbuto
index 550f76e..0c51e18 100755
--- a/mbuto
+++ b/mbuto
@@ -544,28 +544,6 @@ subopts_get() {
 
 ### CPIO #######################################################################
 
-# cpio_init() - Source existing CPIO archive, or create if needed
-# $1:	Path to CPIO archive, might exist, might be discarded if existing
-cpio_init() {
-	if [ -f "${OUT}" ] && [ "${1}" != "discard" ]; then
-		info "Sourcing CPIO archive from ${OUT}"
-
-		if ! "${GZIP}" -dfc "${OUT}" |
-		   "${CPIO}" --quiet -iD "${wd}"; then
-			err "Invalid CPIO archive ${OUT}"
-		fi
-	else
-		info "Creating new CPIO archive"
-
-		if [ -z "${OUT}" ]; then
-			OUT="$("${MKTEMP}")"
-			notice "Creating image: ${OUT}"
-		else
-			OUT="$("${REALPATH}" "${OUT}")"
-		fi
-	fi
-}
-
 # compress_select() - Try compressors and pick the fastest
 # $1:	Existing CPIO archive
 compress_select() {
@@ -987,7 +965,6 @@ pkg_add() {
 
 # build() - Build a new image, sourcing contents
 build() {
-	cpio_init discard
 	kmod_init
 
 	for __d in ${DIRS}; do
@@ -1083,11 +1060,11 @@ cmds() {
 
 	[ "${NOSTRIP}" != "y" ] && strip_all
 
-	( __out="$("${REALPATH}" "${OUT}")"
+	(
 		"${CD}" "${wd}"
-		"${FIND}" . | "${CPIO}" --create -H newc --quiet > "${OUT}"
-		cpio_compress "${__out}"
-	)
+		"${FIND}" . | "${CPIO}" --create -H newc --quiet
+	) > "${OUT}"
+	cpio_compress "${OUT}"
 
 	stats
 
-- 
@@ -544,28 +544,6 @@ subopts_get() {
 
 ### CPIO #######################################################################
 
-# cpio_init() - Source existing CPIO archive, or create if needed
-# $1:	Path to CPIO archive, might exist, might be discarded if existing
-cpio_init() {
-	if [ -f "${OUT}" ] && [ "${1}" != "discard" ]; then
-		info "Sourcing CPIO archive from ${OUT}"
-
-		if ! "${GZIP}" -dfc "${OUT}" |
-		   "${CPIO}" --quiet -iD "${wd}"; then
-			err "Invalid CPIO archive ${OUT}"
-		fi
-	else
-		info "Creating new CPIO archive"
-
-		if [ -z "${OUT}" ]; then
-			OUT="$("${MKTEMP}")"
-			notice "Creating image: ${OUT}"
-		else
-			OUT="$("${REALPATH}" "${OUT}")"
-		fi
-	fi
-}
-
 # compress_select() - Try compressors and pick the fastest
 # $1:	Existing CPIO archive
 compress_select() {
@@ -987,7 +965,6 @@ pkg_add() {
 
 # build() - Build a new image, sourcing contents
 build() {
-	cpio_init discard
 	kmod_init
 
 	for __d in ${DIRS}; do
@@ -1083,11 +1060,11 @@ cmds() {
 
 	[ "${NOSTRIP}" != "y" ] && strip_all
 
-	( __out="$("${REALPATH}" "${OUT}")"
+	(
 		"${CD}" "${wd}"
-		"${FIND}" . | "${CPIO}" --create -H newc --quiet > "${OUT}"
-		cpio_compress "${__out}"
-	)
+		"${FIND}" . | "${CPIO}" --create -H newc --quiet
+	) > "${OUT}"
+	cpio_compress "${OUT}"
 
 	stats
 
-- 
2.44.0


  parent reply	other threads:[~2024-03-22  2:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22  2:27 [PATCH 0/4] mbuto: Assorted fixes and simplifications David Gibson
2024-03-22  2:27 ` [PATCH 1/4] ${wd} is always set, no need to test for it David Gibson
2024-03-22  2:27 ` [PATCH 2/4] Remove stale archivemount support David Gibson
2024-04-05 18:09   ` Stefano Brivio
2024-04-06  3:02     ` David Gibson
2024-04-25  4:47       ` Stefano Brivio
2024-04-26  1:44         ` David Gibson
2024-03-22  2:27 ` [PATCH 3/4] Split "auto" compression mode into its own path David Gibson
2024-04-05 18:10   ` Stefano Brivio
2024-04-06  3:06     ` David Gibson
2024-04-25  4:46       ` Stefano Brivio
2024-04-26  1:46         ` David Gibson
2024-03-22  2:27 ` David Gibson [this message]
2024-04-05 18:08   ` [PATCH 4/4] Remove unnecessary cpio_init function Stefano Brivio
2024-04-06  3:11     ` David Gibson
2024-04-25  4:46       ` Stefano Brivio

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=20240322022739.2746102-5-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=lvivier@redhat.com \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).