-
Notifications
You must be signed in to change notification settings - Fork 467
/
doctorcmd_unix.go
54 lines (45 loc) · 1.1 KB
/
doctorcmd_unix.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
//go:build unix
package cmd
import (
"bytes"
"fmt"
"log/slog"
"os"
"os/exec"
"runtime"
"golang.org/x/sys/unix"
"github.com/twpayne/chezmoi/v2/internal/chezmoi"
"github.com/twpayne/chezmoi/v2/internal/chezmoilog"
)
type (
systeminfoCheck struct{ skippedCheck }
umaskCheck struct{}
unameCheck struct{}
)
func (umaskCheck) Name() string {
return "umask"
}
func (umaskCheck) Run(system chezmoi.System, homeDirAbsPath chezmoi.AbsPath) (checkResult, string) {
umask := unix.Umask(0)
unix.Umask(umask)
result := checkResultOK
if umask != 0o002 && umask != 0o022 {
result = checkResultWarning
}
return result, fmt.Sprintf("%03o", umask)
}
func (unameCheck) Name() string {
return "uname"
}
func (unameCheck) Run(system chezmoi.System, homeDirAbsPath chezmoi.AbsPath) (checkResult, string) {
if runtime.GOOS == "windows" {
return checkResultSkipped, ""
}
cmd := exec.Command("uname", "-a")
cmd.Stderr = os.Stderr
data, err := chezmoilog.LogCmdOutput(slog.Default(), cmd)
if err != nil {
return checkResultFailed, err.Error()
}
return checkResultOK, string(bytes.TrimSpace(data))
}