-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexcludes.go
More file actions
41 lines (34 loc) · 825 Bytes
/
excludes.go
File metadata and controls
41 lines (34 loc) · 825 Bytes
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
package rfm
import "strings"
const (
resetKeyword = "reset"
)
/// Excludes contains simple starts-with patterns for upload/download excludes
type Excludes struct {
Excls []string
}
func (e *Excludes) String() string {
return strings.Join(e.Excls, ",")
}
func (e *Excludes) Set(value string) error {
if value == resetKeyword {
e.Excls = make([]string, 0)
}
e.Excls = append(e.Excls, value)
return nil
}
// ForEach performs the given function on all entries
func (e *Excludes) ForEach(f func(string) string) {
for i := 0; i < len(e.Excls); i++ {
e.Excls[i] = f(e.Excls[i])
}
}
// Contains checks if the given path starts with any of the known excludes
func (e *Excludes) Contains(path string) bool {
for _, excl := range e.Excls {
if strings.HasPrefix(path, excl) {
return true
}
}
return false
}