From d81aca9a69d5fa5c00ac670a4cb1a2171cc19fc1 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 15 Jan 2014 13:41:51 +0800 Subject: [PATCH] update bug fixed on windows --- cmd/update.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/update.go b/cmd/update.go index 83722f61c..5f9529d27 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -103,8 +103,8 @@ func runUpdate(ctx *cli.Context) { localVerInfo.Gopm, remoteVerInfo.Gopm) installRepoPath = doc.HomeDir + "/repos" - tmpDirPath := path.Join(doc.HomeDir, "temp") - tmpBinPath := path.Join(tmpDirPath, "gopm") + tmpDirPath := filepath.Join(doc.HomeDir, "temp") + tmpBinPath := filepath.Join(tmpDirPath, "gopm") if runtime.GOOS == "windows" { tmpBinPath += ".exe" } @@ -142,15 +142,16 @@ func runUpdate(ctx *cli.Context) { } os.Chmod(movePath+"/"+path.Base(tmpBinPath), os.ModePerm) } else { - batPath := filepath.Join(workDir, "a.bat") + batPath := filepath.Join(tmpDirPath, "update.bat") f, err := os.Create(batPath) if err != nil { log.Error("Update", "Fail to generate bat file") log.Fatal("", err.Error()) } - //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", - tmpBinPath, movePath, tmpBinPath, batPath)) + f.WriteString("@echo off\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)) + //f.WriteString(fmt.Sprintf("del \"%v\"\r\n", batPath)) f.Close() attr := &os.ProcAttr{ @@ -159,7 +160,7 @@ func runUpdate(ctx *cli.Context) { 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 { log.Error("Update", "Fail to start bat process") log.Fatal("", err.Error()) @@ -184,6 +185,7 @@ func runUpdate(ctx *cli.Context) { if !isAnythingUpdated { log.Log("Nothing need to be updated") } + log.Log("Exit old gopm") } func loadLocalVerInfo() (ver version) {