added custom filter options
This commit is contained in:
parent
f6e1813d15
commit
a4c746c7e9
4 changed files with 70 additions and 3 deletions
44
filter.go
Normal file
44
filter.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue