make filter.Match a bit easier to read

This commit is contained in:
Lilian Jónsdóttir 2024-06-30 18:17:42 -07:00
parent 0113c56a5e
commit 75370f719a

View file

@ -47,6 +47,7 @@ func (f *Filter) AddFileNames(filenames ...string) {
func (f *Filter) Match(filename string, modified time.Time, isdir bool) bool { func (f *Filter) Match(filename string, modified time.Time, isdir bool) bool {
// this might be unnessary but w/e // this might be unnessary but w/e
filename = filepath.Clean(filename) filename = filepath.Clean(filename)
// on or before/after, not both // on or before/after, not both
if !f.on.IsZero() { if !f.on.IsZero() {
if !same_day(f.on, modified) { if !same_day(f.on, modified) {
@ -60,34 +61,43 @@ func (f *Filter) Match(filename string, modified time.Time, isdir bool) bool {
return false return false
} }
} }
if f.has_regex() && !f.matcher.MatchString(filename) { if f.has_regex() && !f.matcher.MatchString(filename) {
return false return false
} }
if f.glob != "" { if f.glob != "" {
if match, err := filepath.Match(f.glob, filename); err != nil || !match { if match, err := filepath.Match(f.glob, filename); err != nil || !match {
return false return false
} }
} }
if f.has_unregex() && f.unmatcher.MatchString(filename) { if f.has_unregex() && f.unmatcher.MatchString(filename) {
return false return false
} }
if f.unglob != "" { if f.unglob != "" {
if match, err := filepath.Match(f.unglob, filename); err != nil || match { if match, err := filepath.Match(f.unglob, filename); err != nil || match {
return false return false
} }
} }
if len(f.filenames) > 0 && !slices.Contains(f.filenames, filename) { if len(f.filenames) > 0 && !slices.Contains(f.filenames, filename) {
return false return false
} }
if f.filesonly && isdir { if f.filesonly && isdir {
return false return false
} }
if f.dirsonly && !isdir { if f.dirsonly && !isdir {
return false return false
} }
if !f.showhidden && strings.HasPrefix(filename, ".") { if !f.showhidden && strings.HasPrefix(filename, ".") {
return false return false
} }
// okay it was good // okay it was good
return true return true
} }