On Fri, 22 Mar 2024 13:27:39 +1100 David Gibson <david(a)gibson.dropbear.id.au> wrote: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(a)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 - elseThis, and the second part of 1/4, remove a functionality which I accidentally broke in commit b87e4f2e6595 ("mbuto: Create working directory before profiles are sourced"): it was once possible to add contents to an existing initramfs archive. I guess I might be the only interactive user of mbuto at the moment, so I got slightly annoyed by the fact it didn't work anymore but I didn't really investigate further. I used it whenever an initramfs took more than 5-10 seconds to build, and I'd keep forgetting to add stuff. Note that the help message still describes this mode of operation: "Build initramfs image unless an existing one is passed." and in the "Examples": ./mbuto -f kata.img zsh_5.6.2-3_amd64.deb Install zsh package to pre-existing kata.img but I also realised it's not convenient to have this as default, because, especially for initramfs images that can be built faster, one might just want to rebuild a single binary and the image, repeatedly. Perhaps, instead of dropping this altogether, we could introduce a new -K ("keep") option that skips the unconditional wd assignment and calls cpio_init() (which becomes cpio_load() or something like that). -- Stefano