1
0
Fork 0
This commit is contained in:
ston1th 2019-09-02 09:48:18 +02:00
commit 0c7423d604

View file

@ -8,31 +8,37 @@ import (
"strings" "strings"
) )
// Matcher is the matcher function type
type Matcher func(path string) bool type Matcher func(path string) bool
// Filter defines an interface to filter paths or files
type Filter interface { type Filter interface {
Filter(path string) error Filter(path string) error
} }
// ErrMacOSFilter error returned by the MacOSFilter
var ErrMacOSFilter = errors.New("authdav: MacOS filter: access denied") var ErrMacOSFilter = errors.New("authdav: MacOS filter: access denied")
// MacOSFilter implements a filter for MacOS specific files
type MacOSFilter struct { type MacOSFilter struct {
match []Matcher match []Matcher
} }
// NewMacOSFilter returns a new MacOSFilter
func NewMacOSFilter() *MacOSFilter { func NewMacOSFilter() *MacOSFilter {
return &MacOSFilter{ return &MacOSFilter{
match: []Matcher{ match: []Matcher{
func(p string) { func(p string) bool {
return p == ".DS_Store" return p == ".DS_Store"
}, },
func(p string) { func(p string) bool {
return strings.HasPrefix(p, "._") return strings.HasPrefix(p, "._")
}, },
}, },
} }
} }
// Filter implements the Filter interface
func (f *MacOSFilter) Filter(path string) error { func (f *MacOSFilter) Filter(path string) error {
_, f := filepath.Split(path) _, f := filepath.Split(path)
for _, m := range f.match { for _, m := range f.match {