wfarr / goenv

You know, rbenv but for go.
MIT License
111 stars 36 forks source link

Fix goenv install for 1.3.1 and later #13

Open alext opened 10 years ago

alext commented 10 years ago

There was a problem with the vercomp function that caused it to echo more than once for some comparisons. This would appear to be a side effect of changing the stackoverflow function to echo instead of using return value.

Comparing 1.2 and 1.3.1 is one of the cases that was echoing more than once. This then caused the test for "$rtn" == "1" to be false, which meant that it was trying to use the old source URL.

meatballhat commented 10 years ago

:clap: :shipit:

(assuming it works! :laughing:)

Syncsecure commented 10 years ago

While it technically works for downloading version 1.3.1, this doesn't actually work when trying to download an older version such as 1.0.3 -- it attempts to find it in the newer download location rather than the expected location (at least for me).

alext commented 10 years ago

@Solistra I can't reproduce that issue. It downloaded 1.0.3 for me correctly. Additionally, I extracted the function into this test script:

#! /usr/bin/env bash

function vercomp () {
    # http://stackoverflow.com/questions/4023830
    # 0: '='
    # 1: '>'
    # 2: '<'
    if [[ $1 == $2 ]]
    then
        echo 0
        return
    fi
    local IFS=.
    local i ver1=($1) ver2=($2)
    # fill empty fields in ver1 with zeros
    for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
    do
        ver1[i]=0
    done
    for ((i=0; i<${#ver1[@]}; i++))
    do
        if [[ -z ${ver2[i]} ]]
        then
            # fill empty fields in ver2 with zeros
            ver2[i]=0
        fi
        if ((10#${ver1[i]} > 10#${ver2[i]}))
        then
            echo 1
            return
        fi
        if ((10#${ver1[i]} < 10#${ver2[i]}))
        then
            echo 2
            return
        fi
    done
#    echo 0
}

for ver in 1.0 1.0.3 1.1 1.1.1 1.2 1.2.1 1.3 1.3.1; do
  echo "${ver}         $(vercomp ${ver} 1.2)"
done

and it returned the values expected:

1.0       2
1.0.3       2
1.1       2
1.1.1       2
1.2       0
1.2.1       1
1.3       1
1.3.1       1
Syncsecure commented 9 years ago

@alext I just double-checked, and you're correct -- apologies for the misunderstanding, it does work as-is. Ignore my previous comment.

jszwedko commented 9 years ago

:+1: any news on this @wfarr ?