1
0
Fork 0

added custom filter options

This commit is contained in:
ston1th 2019-09-02 09:42:41 +02:00
commit a4c746c7e9
4 changed files with 70 additions and 3 deletions

44
filter.go Normal file
View file

@ -0,0 +1,44 @@
// Copyright (C) 2019 Marius Schellenberger
package authdav
import (
"errors"
"path/filepath"
"strings"
)
type Matcher func(path string) bool
type Filter interface {
Filter(path string) error
}
var ErrMacOSFilter = errors.New("authdav: MacOS filter: access denied")
type MacOSFilter struct {
match []Matcher
}
func NewMacOSFilter() *MacOSFilter {
return &MacOSFilter{
match: []Matcher{
func(p string) {
return p == ".DS_Store"
},
func(p string) {
return strings.HasPrefix(p, "._")
},
},
}
}
func (f *MacOSFilter) Filter(path string) error {
_, f := filepath.Split(path)
for _, m := range f.match {
if m(f) {
return ErrMacOSFilter
}
}
return nil
}