-
Notifications
You must be signed in to change notification settings - Fork 198
/
exclude.go
85 lines (66 loc) · 1.76 KB
/
exclude.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
package path_matcher
import (
"fmt"
"sort"
"strings"
"github.com/werf/werf/pkg/util"
)
func newExcludePathMatcher(excludeGlobs []string) excludePathMatcher {
return excludePathMatcher{excludeGlobs: formatPaths(excludeGlobs)}
}
type excludePathMatcher struct {
excludeGlobs []string
}
func (m excludePathMatcher) IsPathMatched(path string) bool {
path = formatPath(path)
if len(m.excludeGlobs) > 0 {
if isAnyPatternMatched(path, m.excludeGlobs) {
return false
}
}
return true
}
func (m excludePathMatcher) IsDirOrSubmodulePathMatched(path string) bool {
return m.IsPathMatched(path) || m.ShouldGoThrough(path)
}
func (m excludePathMatcher) ShouldGoThrough(path string) bool {
return m.shouldGoThrough(formatPath(path))
}
func (m excludePathMatcher) shouldGoThrough(path string) bool {
if len(m.excludeGlobs) == 0 {
return false
}
if hasUniversalGlob(m.excludeGlobs) {
return false
}
if path == "" {
return true
}
pathParts := util.SplitFilepath(path)
globsInProgress := m.excludeGlobs
var matchedGlobs []string
for _, pathPart := range pathParts {
if len(globsInProgress) == 0 {
break
}
globsInProgress, matchedGlobs = matchGlobs(pathPart, globsInProgress)
}
// the path partially matched any globe and not completely matched any other globe
if len(matchedGlobs) == 0 && len(globsInProgress) != 0 && !hasUniversalGlob(globsInProgress) {
return true
}
return false
}
func (m excludePathMatcher) ID() string {
if len(m.excludeGlobs) == 0 {
return ""
}
sort.Strings(m.excludeGlobs)
var args []string
args = append(args, "exclude")
args = append(args, m.excludeGlobs...)
return util.Sha256Hash(strings.Join(args, ":::"))
}
func (m excludePathMatcher) String() string {
return fmt.Sprintf("excludeGlobs=%v", m.excludeGlobs)
}