forked from tools/godep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
60 lines (49 loc) · 1.37 KB
/
util.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
58
59
60
package main
import (
"fmt"
"os/exec"
"path/filepath"
"runtime"
"strings"
)
// Runs a command in dir.
// The name and args are as in exec.Command.
// Stdout, stderr, and the environment are inherited
// from the current process.
func runIn(dir, name string, args ...string) error {
_, err := runInWithOutput(dir, name, args...)
return err
}
func runInWithOutput(dir, name string, args ...string) (string, error) {
c := exec.Command(name, args...)
c.Dir = dir
o, err := c.CombinedOutput()
if debug {
fmt.Printf("execute: %+v\n", c)
fmt.Printf(" output: %s\n", string(o))
}
return string(o), err
}
// driveLetterToUpper converts Windows path's drive letters to uppercase. This
// is needed when comparing 2 paths with different drive letter case.
func driveLetterToUpper(path string) string {
if runtime.GOOS != "windows" || path == "" {
return path
}
p := path
// If path's drive letter is lowercase, change it to uppercase.
if len(p) >= 2 && p[1] == ':' && 'a' <= p[0] && p[0] <= 'z' {
p = string(p[0]+'A'-'a') + p[1:]
}
return p
}
// clean the path and ensure that a drive letter is upper case (if it exists).
func cleanPath(path string) string {
return driveLetterToUpper(filepath.Clean(path))
}
// deal with case insensitive filesystems and other weirdness
func pathEqual(a, b string) bool {
a = cleanPath(a)
b = cleanPath(b)
return strings.EqualFold(a, b)
}