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