mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-11 14:51:49 +00:00
Add retries, to make it fail-safe against network interruptions
This commit is contained in:
parent
d2bea48975
commit
4c21abea52
30
nvm.sh
30
nvm.sh
@ -2684,10 +2684,38 @@ nvm() {
|
|||||||
|
|
||||||
# Install version if not available
|
# Install version if not available
|
||||||
if ! nvm ls "$PROVIDED_VERSION" &>/dev/null; then
|
if ! nvm ls "$PROVIDED_VERSION" &>/dev/null; then
|
||||||
nvm install "$PROVIDED_VERSION"
|
tries_global=3
|
||||||
|
installed_flag="/tmp/.nvm_success"
|
||||||
|
|
||||||
|
while [ $tries_global -gt 0 ]; do
|
||||||
|
( nvm install "$PROVIDED_VERSION" && touch $installed_flag ) &
|
||||||
|
proc_id="$!"
|
||||||
|
#wait $proc_id
|
||||||
|
#result=$?
|
||||||
|
|
||||||
|
# Check every 2 seconds if the installation finished,
|
||||||
|
# if it did, install the needed npm packages and exit
|
||||||
|
tries_install=10
|
||||||
|
while [ $tries_install -gt 0 ]; do
|
||||||
|
if [ -f $installed_flag ]; then
|
||||||
npm install -g grunt-cli bower
|
npm install -g grunt-cli bower
|
||||||
|
|
||||||
|
rm $installed_flag &>/dev/null
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
sleep 2
|
||||||
|
tries_install=$(( $tries_install - 1 ))
|
||||||
|
done
|
||||||
|
|
||||||
|
# Kill process after 20 seconds
|
||||||
|
kill $proc_id &>/dev/null
|
||||||
|
|
||||||
|
tries_global=$(( $tries_global - 1 ))
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Cannot install and use $PROVIDED_VERSION - network/disk space issues might be the reason."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "_$VERSION" = '_system' ]; then
|
if [ "_$VERSION" = '_system' ]; then
|
||||||
if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then
|
if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then
|
||||||
|
Loading…
Reference in New Issue
Block a user