提交 1b9d9aa0 编写于 作者: J Jake Chitel

Added exponential backoff for copying npm installation

上级 705e3f4b
......@@ -8,6 +8,7 @@ import (
"io/ioutil"
"regexp"
"bytes"
"time"
"./nvm/web"
"./nvm/arch"
"./nvm/file"
......@@ -280,13 +281,26 @@ func install(version string, cpuarch string) {
os.Rename(filepath.Join(tempNpmBin, "npx.cmd"), filepath.Join(env.root, "v"+version, "npx.cmd"))
}
os.Rename(filepath.Join(tempDir, "nvm-npm", "npm-"+npmv), filepath.Join(env.root, "v"+version, "node_modules", "npm"))
time.Sleep(10000*time.Millisecond)
err := os.Rename(filepath.Join(tempDir, "nvm-npm", "npm-"+npmv), filepath.Join(env.root, "v"+version, "node_modules", "npm"))
if err != nil {
// sometimes Windows can take some time to enable access to large amounts of files after unzip, use exponential backoff to wait until it is ready
for _, i := range [5]int{1, 2, 4, 8, 16} {
time.Sleep(time.Duration(i)*time.Second)
err = os.Rename(filepath.Join(tempDir, "nvm-npm", "npm-"+npmv), filepath.Join(env.root, "v"+version, "node_modules", "npm"))
if err == nil { break }
}
}
// Remove the temp directory
// may consider keep the temp files here
os.RemoveAll(tempDir)
if err == nil {
// Remove the temp directory
// may consider keep the temp files here
os.RemoveAll(tempDir)
fmt.Println("\n\nInstallation complete. If you want to use this version, type\n\nnvm use "+version)
fmt.Println("\n\nInstallation complete. If you want to use this version, type\n\nnvm use "+version)
} else {
fmt.Println("Error: Unable to install NPM: "+err.Error());
}
} else {
fmt.Println("Could not download npm for node v"+version+".")
fmt.Println("Please visit https://github.com/npm/npm/releases/tag/v"+npmv+" to download npm.")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册