Skip to content

Commit d50d176

Browse files
committed
fix(arcup): accept checksum files without a trailing newline
verify_checksum_file() decided emptiness from the exit status of `read -r expected_checksum expected_name < "$checksum_path"`. `read` returns non-zero when it reaches EOF before a newline, even though it has already populated the variables. A .sha256 whose single line lacks a trailing newline is valid, but arcup rejected it with "Checksum file is empty", aborting a correct install. Decide emptiness from the parsed hash instead of read's exit status. A genuinely empty file still yields an empty hash and is still rejected. Adds regression tests covering the no-trailing-newline and empty cases.
1 parent 90d71dc commit d50d176

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎arcup/arcup‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,12 @@ verify_checksum_file() {
656656
local archive_name="$3"
657657
local expected_checksum expected_name actual_checksum
658658

659-
if ! read -r expected_checksum expected_name < "$checksum_path"; then
659+
# `read` returns non-zero when it hits EOF before a newline, even though it
660+
# still populates the variables. A checksum file whose single line has no
661+
# trailing newline is valid, so decide emptiness from the parsed hash rather
662+
# than from read's exit status.
663+
read -r expected_checksum expected_name < "$checksum_path" || true
664+
if [[ -z "$expected_checksum" ]]; then
660665
error "Checksum file is empty: $checksum_path"
661666
fi
662667

‎arcup/test_arcup.sh‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ test_checksum_validation() {
119119

120120
printf '%s other-asset.tar.gz\n' "$checksum" > "$checksum_file"
121121
expect_fail "checksum filename mismatch fails" verify_checksum_file "$archive" "$checksum_file" "$archive_name"
122+
123+
# A checksum file whose only line has no trailing newline is still valid.
124+
printf '%s %s' "$checksum" "$archive_name" > "$checksum_file"
125+
verify_checksum_file "$archive" "$checksum_file" "$archive_name"
126+
pass "checksum file without trailing newline passes"
127+
128+
# A genuinely empty checksum file must still be rejected.
129+
: > "$checksum_file"
130+
expect_fail "empty checksum file fails" verify_checksum_file "$archive" "$checksum_file" "$archive_name"
122131
}
123132

124133
test_download_error_lists_assets() {

0 commit comments

Comments
 (0)