kata-deploy: packaging: fix buggy return statements in cache check

The `install_cached_tarball_component` function in the binaries
packaging script contained syntax errors where it attempted to capture
the empty stdout of the `cleanup_and_fail` function inside a return
statement (e.g., `return "$(cleanup_and_fail ...)"`).

Since `cleanup_and_fail` only returns an exit status and produces no
stdout, this evaluated to `return ""`, which is invalid in bash and
causes the script to crash with `numeric argument required` instead of
returning the failure status.

Fix this by replacing the buggy inline returns with proper `if` blocks
that call `cleanup_and_fail` and explicitly return `1`.

Signed-off-by: Huy Pham <huypham@google.com>
This commit is contained in:
Huy Pham
2026-05-20 10:27:51 -07:00
parent 9ddcc53f6f
commit ee4f756b75

View File

@@ -188,7 +188,7 @@ cleanup_and_fail_shim_v2_rust_specifics() {
[[ -f "${root_hash_file}" ]] && rm -f "${root_hash_file}"
done
return "$(cleanup_and_fail "${1:-}" "${2:-}")"
cleanup_and_fail "${1:-}" "${2:-}"
}
cleanup_and_fail() {
@@ -272,12 +272,18 @@ install_cached_tarball_component() {
rm -f "${component}"-version
rm -f "${component}"-builder-image-version
[[ "${cached_image_version}" != "${current_image_version}" ]] && return "$(cleanup_and_fail "${component_tarball_path}" "${extra_tarballs}")"
[[ "${cached_version}" != "${current_version}" ]] && return "$(cleanup_and_fail "${component_tarball_path}" "${extra_tarballs}")"
sha256sum -c "${component}-sha256sum" || return "$(cleanup_and_fail "${component_tarball_path}" "${extra_tarballs}")"
if [[ "${cached_image_version}" != "${current_image_version}" ]]; then
cleanup_and_fail "${component_tarball_path}" "${extra_tarballs}"
return 1
fi
if [[ "${cached_version}" != "${current_version}" ]]; then
cleanup_and_fail "${component_tarball_path}" "${extra_tarballs}"
return 1
fi
sha256sum -c "${component}-sha256sum" || { cleanup_and_fail "${component_tarball_path}" "${extra_tarballs}"; return 1; }
if [[ "${component}" = "shim-v2-rust" ]]; then
install_cached_shim_v2_rust_tarball_compare_root_hashes || return "$(cleanup_and_fail_shim_v2_rust_specifics "${component_tarball_path}" "${extra_tarballs}")"
install_cached_shim_v2_rust_tarball_compare_root_hashes || { cleanup_and_fail_shim_v2_rust_specifics "${component_tarball_path}" "${extra_tarballs}"; return 1; }
fi
info "Using cached tarball of ${component}"