1
0
Fork 0
mirror of synced 2024-06-15 21:41:08 -04:00
zimfw/src/stage2/50_zimfw_check_version.zsh.erb
Eric Nielsen 49386cad6d
Make forced check-version asynchronous (again)
as it was before a34b8dab64.
Don't make zimfw hang in the foreground waiting for git to connect to
GitHub, mainly because the waiting can take too long in case of
connection issues or no network. Also set git timeout to 30 seconds so
background check also does hang for too long, just it case.

Fixes #514
2023-06-16 20:24:33 -05:00

26 lines
1.1 KiB
Plaintext

_zimfw_check_version() {
if (( ${1} )); then
# Get latest version (get all `v*` tags from repo, delete `*v` from beginning,
# sort in descending `O`rder `n`umerically, and get the `[1]` first)
if (( ${2} )); then
# background check
if [[ -w ${_zversion_target:h} ]]; then
print -R ${${(On)${(f)"$(GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=30 command git ls-remote --tags --refs \
https://github.com/zimfw/zimfw.git 'v*' 2>/dev/null)"}##*v}[1]} >! ${_zversion_target} &!
fi
else
# foreground check
local tags
tags=$(command git ls-remote --tags --refs https://github.com/zimfw/zimfw.git 'v*') || return 1
>! ${_zversion_target} <<<${${(On)${(f)tags}##*v}[1]} || return 1
fi
fi
if [[ -f ${_zversion_target} ]]; then
local -r zlatest_version=$(<${_zversion_target})
if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then
_zimfw_print -u2 -PR "%F{yellow}Latest zimfw version is %B${zlatest_version}%b. You're using version %B${_zversion}%b. Run %Bzimfw upgrade%b to upgrade.%f"
return 4
fi
fi
}