Browse Source

update bug fixed on windows

pull/103/head
Lunny Xiao 11 years ago
parent
commit
d81aca9a69
  1. 16
      cmd/update.go

16
cmd/update.go

@ -103,8 +103,8 @@ func runUpdate(ctx *cli.Context) {
localVerInfo.Gopm, remoteVerInfo.Gopm) localVerInfo.Gopm, remoteVerInfo.Gopm)
installRepoPath = doc.HomeDir + "/repos" installRepoPath = doc.HomeDir + "/repos"
tmpDirPath := path.Join(doc.HomeDir, "temp") tmpDirPath := filepath.Join(doc.HomeDir, "temp")
tmpBinPath := path.Join(tmpDirPath, "gopm") tmpBinPath := filepath.Join(tmpDirPath, "gopm")
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
tmpBinPath += ".exe" tmpBinPath += ".exe"
} }
@ -142,15 +142,16 @@ func runUpdate(ctx *cli.Context) {
} }
os.Chmod(movePath+"/"+path.Base(tmpBinPath), os.ModePerm) os.Chmod(movePath+"/"+path.Base(tmpBinPath), os.ModePerm)
} else { } else {
batPath := filepath.Join(workDir, "a.bat") batPath := filepath.Join(tmpDirPath, "update.bat")
f, err := os.Create(batPath) f, err := os.Create(batPath)
if err != nil { if err != nil {
log.Error("Update", "Fail to generate bat file") log.Error("Update", "Fail to generate bat file")
log.Fatal("", err.Error()) log.Fatal("", err.Error())
} }
//f.WriteString("@echo off\r\n") f.WriteString("@echo off\r\n")
f.WriteString(fmt.Sprintf("ping -n 1 127.0.0.1>nul\r\ncopy \"%v\" \"%v\"\r\ndel \"%v\"\r\ndel \"%v\"\r\n", f.WriteString(fmt.Sprintf("ping -n 1 127.0.0.1>nul\r\ncopy \"%v\" \"%v\" >nul\r\ndel \"%v\" >nul\r\n\r\n",
tmpBinPath, movePath, tmpBinPath, batPath)) tmpBinPath, movePath, tmpBinPath))
//f.WriteString(fmt.Sprintf("del \"%v\"\r\n", batPath))
f.Close() f.Close()
attr := &os.ProcAttr{ attr := &os.ProcAttr{
@ -159,7 +160,7 @@ func runUpdate(ctx *cli.Context) {
Files: []*os.File{os.Stdin, os.Stdout, os.Stderr}, Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
} }
_, err = os.StartProcess(batPath, []string{"a.bat"}, attr) _, err = os.StartProcess(batPath, []string{batPath}, attr)
if err != nil { if err != nil {
log.Error("Update", "Fail to start bat process") log.Error("Update", "Fail to start bat process")
log.Fatal("", err.Error()) log.Fatal("", err.Error())
@ -184,6 +185,7 @@ func runUpdate(ctx *cli.Context) {
if !isAnythingUpdated { if !isAnythingUpdated {
log.Log("Nothing need to be updated") log.Log("Nothing need to be updated")
} }
log.Log("Exit old gopm")
} }
func loadLocalVerInfo() (ver version) { func loadLocalVerInfo() (ver version) {

Loading…
Cancel
Save