Debian Codegraph @

tools/cygwin_windows.go

raw symbols SCIP
1 //go:build windows
2 // +build windows
3
4 package tools
5
6 import (
7 "bytes"
8
9 "github.com/git-lfs/git-lfs/v3/subprocess"
10 "github.com/git-lfs/git-lfs/v3/tr"
11 )
12
13 type cygwinSupport byte
14
15 const (
16 cygwinStateUnknown cygwinSupport = iota
17 cygwinStateEnabled
18 cygwinStateDisabled
19 )
20
21 func (c cygwinSupport) Enabled() bool {
22 switch c {
23 case cygwinStateEnabled:
24 return true
25 case cygwinStateDisabled:
26 return false
27 default:
28 panic(tr.Tr.Get("unknown enabled state for %v", c))
29 }
30 }
31
32 var (
33 cygwinState cygwinSupport
34 )
35
36 func isCygwin() bool {
37 if cygwinState != cygwinStateUnknown {
38 return cygwinState.Enabled()
39 }
40
41 cmd, err := subprocess.ExecCommand("uname")
42 if err != nil {
43 return false
44 }
45 out, err := cmd.Output()
46 if err != nil {
47 return false
48 }
49
50 if bytes.Contains(out, []byte("CYGWIN")) || bytes.Contains(out, []byte("MSYS")) {
51 cygwinState = cygwinStateEnabled
52 } else {
53 cygwinState = cygwinStateDisabled
54 }
55
56 return cygwinState.Enabled()
57 }