-
Notifications
You must be signed in to change notification settings - Fork 24
/
gobrew_windows.go
40 lines (34 loc) · 860 Bytes
/
gobrew_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package gobrew
import (
"fmt"
"os"
"os/exec"
"strings"
"github.com/kevincobain2000/gobrew/utils"
)
const (
fileExt = ".exe"
tarNameExt = ".zip"
)
func removeFile(goBrewFile string) {
goBrewOldFile := goBrewFile + ".old"
utils.CheckError(os.Rename(goBrewFile, goBrewOldFile), "==> [Error] Cannot rename binary file")
}
func symlink(oldname string, newname string) {
utils.CheckError(
exec.Command("cmd", "/c", "mklink", "/J", newname, oldname).Run(),
"==> [Error]: symbolic link failed",
)
}
// https://github.com/golang/go/issues/63703
func evalSymlinks(path string) (string, error) {
cmd := fmt.Sprintf(
"Get-Item -Path %s | Select-Object -ExpandProperty Target",
path,
)
output, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
if err != nil {
return "", err
}
return strings.TrimSpace(string(output)), err
}