-
Notifications
You must be signed in to change notification settings - Fork 199
/
base_path.go
69 lines (52 loc) · 1.49 KB
/
base_path.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
package path_matcher
import (
"fmt"
"strings"
"github.com/werf/werf/pkg/util"
)
func newBasePathMatcher(basePath string, matcher PathMatcher) basePathMatcher {
return basePathMatcher{basePath: formatPath(basePath), matcher: matcher}
}
type basePathMatcher struct {
basePath string
matcher PathMatcher
}
func (m basePathMatcher) IsPathMatched(path string) bool {
path = formatPath(path)
basePathCheck := util.IsSubpathOfBasePath(m.basePath, path) || m.basePath == path
if !basePathCheck {
return false
}
if m.matcher == nil {
return true
}
return m.matcher.IsPathMatched(util.GetRelativeToBaseFilepath(m.basePath, path))
}
func (m basePathMatcher) IsDirOrSubmodulePathMatched(path string) bool {
return m.IsPathMatched(path) || m.ShouldGoThrough(path)
}
func (m basePathMatcher) ShouldGoThrough(path string) bool {
path = formatPath(path)
if util.IsSubpathOfBasePath(path, m.basePath) {
return true
}
if m.matcher == nil {
return false
}
return m.matcher.ShouldGoThrough(util.GetRelativeToBaseFilepath(m.basePath, path))
}
func (m basePathMatcher) ID() string {
if m.basePath == "" && (m.matcher == nil || m.matcher.ID() == "") {
return ""
}
var args []string
args = append(args, "basePath")
args = append(args, m.basePath)
if m.matcher != nil {
args = append(args, m.matcher.ID())
}
return util.Sha256Hash(strings.Join(args, ":::"))
}
func (m basePathMatcher) String() string {
return fmt.Sprintf("{ basePath=%q, matcher=%q }", m.basePath, m.matcher.String())
}