mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-21 02:33:32 +00:00
fix: install script no longer crashes when comparing RC versions
The version comparison function was attempting numeric comparisons on version parts containing RC suffixes (e.g., "0-rc" from "4.8.0-rc.2"), causing an "unbound variable" error due to set -u. Now properly strips and handles pre-release suffixes separately, allowing correct comparison of RC versions. Addresses discussion #344 comment from RLSinRFV
This commit is contained in:
+28
-3
@@ -636,9 +636,19 @@ compare_versions() {
|
||||
local v1="${1#v}" # Remove 'v' prefix
|
||||
local v2="${2#v}"
|
||||
|
||||
# Split versions into parts
|
||||
IFS='.' read -ra V1_PARTS <<< "$v1"
|
||||
IFS='.' read -ra V2_PARTS <<< "$v2"
|
||||
# Strip any pre-release suffix (e.g., -rc.1, -beta, etc.)
|
||||
local base_v1="${v1%%-*}"
|
||||
local base_v2="${v2%%-*}"
|
||||
local suffix_v1="${v1#*-}"
|
||||
local suffix_v2="${v2#*-}"
|
||||
|
||||
# If no suffix, suffix equals the full version
|
||||
[[ "$suffix_v1" == "$v1" ]] && suffix_v1=""
|
||||
[[ "$suffix_v2" == "$v2" ]] && suffix_v2=""
|
||||
|
||||
# Split base versions into parts
|
||||
IFS='.' read -ra V1_PARTS <<< "$base_v1"
|
||||
IFS='.' read -ra V2_PARTS <<< "$base_v2"
|
||||
|
||||
# Compare major.minor.patch
|
||||
for i in 0 1 2; do
|
||||
@@ -651,6 +661,21 @@ compare_versions() {
|
||||
fi
|
||||
done
|
||||
|
||||
# Base versions are equal, now compare suffixes
|
||||
# No suffix (stable) > rc suffix
|
||||
if [[ -z "$suffix_v1" ]] && [[ -n "$suffix_v2" ]]; then
|
||||
return 1 # v1 (stable) > v2 (rc)
|
||||
elif [[ -n "$suffix_v1" ]] && [[ -z "$suffix_v2" ]]; then
|
||||
return 2 # v1 (rc) < v2 (stable)
|
||||
elif [[ -n "$suffix_v1" ]] && [[ -n "$suffix_v2" ]]; then
|
||||
# Both have suffixes, compare them lexicographically
|
||||
if [[ "$suffix_v1" > "$suffix_v2" ]]; then
|
||||
return 1
|
||||
elif [[ "$suffix_v1" < "$suffix_v2" ]]; then
|
||||
return 2
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0 # versions are equal
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user