mirror of
https://github.com/coreybutler/nvm-windows.git
synced 2026-01-15 07:04:31 +08:00
Fixed version architecture detection
This commit is contained in:
@@ -193,6 +193,11 @@ func uninstall(version string) {
|
||||
// Determine if the version exists and skip if it doesn't
|
||||
if node.IsVersionInstalled(env.root,version,"32") || node.IsVersionInstalled(env.root,version,"64") {
|
||||
fmt.Printf("Uninstalling node v"+version+"...")
|
||||
v, _ := node.GetCurrentVersion()
|
||||
if v == version {
|
||||
cmd := exec.Command(env.root+"\\elevate.cmd", "cmd", "/C", "rmdir", env.symlink)
|
||||
cmd.Run()
|
||||
}
|
||||
e := os.RemoveAll(env.root+"\\v"+version)
|
||||
if e != nil {
|
||||
fmt.Println("Error removing node v"+version)
|
||||
|
||||
@@ -38,7 +38,7 @@ func IsVersionInstalled(root string, version string, cpu string) bool {
|
||||
if ((e32||e64) && used) || (e32 && e64) {
|
||||
return true
|
||||
}
|
||||
if !e32 && !e64 && used && arch.Validate(cpu) == arch.Validate("") {
|
||||
if !e32 && !e64 && used && arch.Validate(cpu) == arch.Bit(root+"\\v"+version+"\\node.exe") {
|
||||
return true
|
||||
}
|
||||
if cpu == "32" {
|
||||
|
||||
124
src/nvm/web/web.go
Normal file
124
src/nvm/web/web.go
Normal file
@@ -0,0 +1,124 @@
|
||||
package web
|
||||
|
||||
import(
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"strconv"
|
||||
"../arch"
|
||||
)
|
||||
|
||||
func Download(url string, target string) bool {
|
||||
|
||||
output, err := os.Create(target)
|
||||
if err != nil {
|
||||
fmt.Println("Error while creating", target, "-", err)
|
||||
}
|
||||
defer output.Close()
|
||||
|
||||
response, err := http.Get(url)
|
||||
if err != nil {
|
||||
fmt.Println("Error while downloading", url, "-", err)
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
n, err := io.Copy(output, response.Body)
|
||||
n=n
|
||||
if err != nil {
|
||||
fmt.Println("Error while downloading", url, "-", err)
|
||||
}
|
||||
|
||||
if response.Status[0:3] != "200" {
|
||||
fmt.Println("Download failed. Rolling Back.")
|
||||
err := os.Remove(target)
|
||||
if err != nil {
|
||||
fmt.Println("Rollback failed.",err)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func GetNodeJS(root string, v string, a string) bool {
|
||||
|
||||
a = arch.Validate(a)
|
||||
|
||||
url := ""
|
||||
if a == "32" {
|
||||
url = "http://nodejs.org/dist/v"+v+"/node.exe"
|
||||
} else {
|
||||
if !IsNode64bitAvailable(v) {
|
||||
fmt.Println("Node.js v"+v+" is only available in 32-bit.")
|
||||
return false
|
||||
}
|
||||
url = "http://nodejs.org/dist/v"+v+"/x64/node.exe"
|
||||
}
|
||||
fileName := root+"\\v"+v+"\\node"+a+".exe"
|
||||
|
||||
fmt.Printf("Downloading node.js version "+v+" ("+a+"-bit)... ")
|
||||
|
||||
if Download(url,fileName) {
|
||||
fmt.Printf("Complete\n")
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func GetNpm(v string) bool {
|
||||
url := "https://github.com/npm/npm/archive/v"+v+".zip"
|
||||
fileName := os.TempDir()+"\\"+"npm-v"+v+".zip"
|
||||
|
||||
fmt.Printf("Downloading npm version "+v+"... ")
|
||||
if Download(url,fileName) {
|
||||
fmt.Printf("Complete\n")
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func GetRemoteTextFile(url string) string {
|
||||
response, httperr := http.Get(url)
|
||||
if httperr != nil {
|
||||
fmt.Println("\nCould not retrieve "+url+".\n\n")
|
||||
fmt.Printf("%s", httperr)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
defer response.Body.Close()
|
||||
contents, readerr := ioutil.ReadAll(response.Body)
|
||||
if readerr != nil {
|
||||
fmt.Printf("%s", readerr)
|
||||
os.Exit(1)
|
||||
}
|
||||
return string(contents)
|
||||
}
|
||||
os.Exit(1)
|
||||
return ""
|
||||
}
|
||||
|
||||
func IsNode64bitAvailable(v string) bool {
|
||||
if v == "latest" {
|
||||
return true
|
||||
}
|
||||
|
||||
// Anything below version 8 doesn't have a 64 bit version
|
||||
vers := strings.Fields(strings.Replace(v,"."," ",-1))
|
||||
main, _ := strconv.ParseInt(vers[0],0,0)
|
||||
minor, _ := strconv.ParseInt(vers[1],0,0)
|
||||
if main == 0 && minor < 8 {
|
||||
return false
|
||||
}
|
||||
|
||||
// Check online to see if a 64 bit version exists
|
||||
res, err := http.Head("http://nodejs.org/dist/v"+v+"/x64/node.exe")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return res.StatusCode == 200
|
||||
}
|
||||
Reference in New Issue
Block a user