From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 3467F5A026F for ; Fri, 22 Mar 2024 03:27:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1711074461; bh=l4KiElOPajCZ/ljbreiLCx500RYtn2XBzRmQnRq+stY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LNDjrNwuYYPsFY2dDpaYs4fU9+LEuRPQjliCSFPuR5C2N1dlU8iT2gmwNSFC8LlgR WFMvE6x4SFJPOdIXEwZy/SuX+FeZAOAhlg94RBVLTRoHPYjYBOU2Da9GVBesZ/6JxM fGkY+RTnGtLbPmtcmwaU7K3M53rKhVkVBTXbr/eRBTgnEBzUhzjp8sRkKqNWDnk9FK sYfzFLeC2dmVdQjJnd8szSEL/5fyUyUrWwG9bRpZdtwqbU/jS6IykNWLzR2V8XZIWV pvG6/4dzaAHy9jAaqdAqOZcR05WCoAWoaSB/DJ4os1d3IsyvEh8c4Zd+ZQXntUrBJz ZKM0XArYXbkiw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4V15p53hHxz4wxx; Fri, 22 Mar 2024 13:27:41 +1100 (AEDT) From: David Gibson To: Stefano Brivio Subject: [PATCH 4/4] Remove unnecessary cpio_init function Date: Fri, 22 Mar 2024 13:27:39 +1100 Message-ID: <20240322022739.2746102-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322022739.2746102-1-david@gibson.dropbear.id.au> References: <20240322022739.2746102-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: J3NJSNITAI4IXGGGFSCOQFQNRVYGHSSD X-Message-ID-Hash: J3NJSNITAI4IXGGGFSCOQFQNRVYGHSSD X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: lvivier@redhat.com, passt-dev@passt.top, David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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 -- 2.44.0