MCPcopy
hub / github.com/git-lfs/git-lfs / translateCygwinPath

Function translateCygwinPath

tools/os_tools.go:30–59  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

28}
29
30func translateCygwinPath(path string) (string, error) {
31 cmd, err := subprocess.ExecCommand("cygpath", "-w", path)
32 if err != nil {
33 // If cygpath doesn't exist, that's okay: just return the paths
34 // as we got it.
35 return path, nil
36 }
37 // cygpath uses ISO-8850-1 as the default encoding if the locale is not
38 // set, resulting in breakage, since we want a UTF-8 path.
39 env := make([]string, 0, len(cmd.Env)+1)
40 for _, val := range cmd.Env {
41 if !strings.HasPrefix(val, "LC_ALL=") {
42 env = append(env, val)
43 }
44 }
45 cmd.Env = append(env, "LC_ALL=C.UTF-8")
46 buf := &bytes.Buffer{}
47 cmd.Stderr = buf
48 out, err := cmd.Output()
49 output := strings.TrimSpace(string(out))
50 if err != nil {
51 // If cygpath doesn't exist, that's okay: just return the paths
52 // as we got it.
53 if _, ok := err.(*exec.Error); ok {
54 return path, nil
55 }
56 return path, errors.New(tr.Tr.Get("failed to translate path from Cygwin to Windows: %s", buf.String()))
57 }
58 return output, nil
59}
60
61func TranslateCygwinPath(path string) (string, error) {
62 if isCygwin() {

Callers 2

GetwdFunction · 0.85
TranslateCygwinPathFunction · 0.85

Calls 4

ExecCommandFunction · 0.92
GetMethod · 0.65
StringMethod · 0.65
OutputMethod · 0.45

Tested by

no test coverage detected