44 lines
697 B
Go
44 lines
697 B
Go
// 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
|
|
}
|