From 4989cb0f4604c3e789482cff26f1e2cfaeda328d Mon Sep 17 00:00:00 2001 From: devorun Date: Thu, 13 Aug 2026 21:35:48 +0300 Subject: [PATCH] fix(arcup): accept checksum files without a trailing newline verify_checksum_file used `if ! read -r ... < file` to detect an empty checksum file, but `read` returns non-zero when the final line has no trailing newline even though it still populates the variables. A valid `.sha256` file whose last line lacks a trailing newline was therefore rejected as "Checksum file is empty", aborting an otherwise-good install. Check the parsed hash instead of read's exit status, and add a regression test for the no-trailing-newline case. Bump the installer version per the in-file convention. --- arcup/arcup | 9 +++++++-- arcup/test_arcup.sh | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/arcup/arcup b/arcup/arcup index 3590cd36..c4269b6f 100755 --- a/arcup/arcup +++ b/arcup/arcup @@ -6,7 +6,7 @@ set -euo pipefail # NOTE: if you make modifications to this script, please increment the version number. # WARNING: the SemVer pattern: major.minor.patch must be followed as we use it to determine if the script is up to date. -ARCUP_INSTALLER_VERSION="0.2.0" +ARCUP_INSTALLER_VERSION="0.2.1" REPO="${ARC_REPO:-circlefin/arc-node}" if [[ -n "${ARC_REPO:-}" ]] && [[ ! "$ARC_REPO" =~ ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$ ]]; then @@ -656,7 +656,12 @@ verify_checksum_file() { local archive_name="$3" local expected_checksum expected_name actual_checksum - if ! read -r expected_checksum expected_name < "$checksum_path"; then + # `read` returns non-zero when the final line has no trailing newline, even + # though it still populates the variables. Check the parsed hash rather than + # read's exit status so a valid checksum file whose last line lacks a + # trailing newline is not rejected as empty. + read -r expected_checksum expected_name < "$checksum_path" || true + if [[ -z "$expected_checksum" ]]; then error "Checksum file is empty: $checksum_path" fi diff --git a/arcup/test_arcup.sh b/arcup/test_arcup.sh index 49021191..c62688bc 100755 --- a/arcup/test_arcup.sh +++ b/arcup/test_arcup.sh @@ -119,6 +119,13 @@ test_checksum_validation() { printf '%s other-asset.tar.gz\n' "$checksum" > "$checksum_file" expect_fail "checksum filename mismatch fails" verify_checksum_file "$archive" "$checksum_file" "$archive_name" + + # A checksum file whose final line has no trailing newline is still valid. + # `read` returns non-zero at EOF but populates the fields, so it must be + # accepted rather than rejected as empty. + printf '%s %s' "$checksum" "$archive_name" > "$checksum_file" + verify_checksum_file "$archive" "$checksum_file" "$archive_name" + pass "checksum file without trailing newline passes" } test_download_error_lists_assets() {