-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
96 lines (77 loc) · 1.2 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"errors"
"os"
"runtime"
)
var (
errShutdown = errors.New("shutting down")
)
type coms struct {
donec chan struct{}
}
func newComs() *coms {
return &coms{
donec: make(chan struct{}),
}
}
func (c *coms) term() error {
select {
case <-c.donec:
return errShutdown
default:
return nil
}
}
func (c *coms) close() {
select {
case <-c.donec:
default:
close(c.donec)
}
}
func tripFn(c *coms, l Logger) func(error) {
return func(err error) {
if err != nil {
c.close()
l.Errorf("TRIPPED: %s", err)
l.Error("i'm melting! melting! oh, what a world! what a world!-")
os.Exit(1)
}
}
}
func runWidth(reserved, concurrency int) int {
maxProcs := runtime.NumCPU() - reserved
if maxProcs < 1 {
maxProcs = 1
}
runtime.GOMAXPROCS(maxProcs)
if concurrency > maxProcs {
concurrency = maxProcs
}
return concurrency
}
func pathNameMatches(ref, val string) bool {
if len(val) < len(ref) {
return false
}
n := -1
for i := 0; i < len(ref); i++ {
n++
if n >= len(val)-1 {
break
}
if ref[i] == '*' {
if val[n] == '/' {
n--
continue
}
i--
continue
}
if ref[i] != val[n] {
return false
}
}
return n == len(val)-1
}