forked from takama/daemon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper_win.go
57 lines (48 loc) · 1.05 KB
/
helper_win.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// +build windows
package daemon
import (
"os"
"os/exec"
"os/user"
"strings"
)
// Service constants
const (
rootPrivileges = "You must have root user privileges. Possibly using 'sudo' command should help"
success = "\t\t\t[ OK ]" // Show colored "OK"
failed = "\t\t\t[FAILED]" // Show colored "FAILED"
)
func IsExecutable(path string) (bool, error) {
in, err := os.Open(path)
if err != nil {
return false, err
}
defer in.Close()
stat, err := in.Stat()
if err != nil {
return false, err
}
if stat.Mode().IsRegular() && strings.HasSuffix(path, ".exe") {
return true, nil
} else {
return false, nil
}
}
// Lookup path for executable file
func executablePath(name string) (string, error) {
if path, err := exec.LookPath(name); err == nil {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return execPath()
}
return path, nil
}
return execPath()
}
// Check root rights to use system service
func checkPrivileges() bool {
if user, err := user.Current(); err == nil && user.Gid == "0" {
return true
}
return false
}