From 5467d7a54957fd1d090694c849d51c098ad7d48c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Wed, 19 Jun 2024 17:14:50 -0700 Subject: [PATCH] make filter clean input filenames --- internal/filter/filter.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/internal/filter/filter.go b/internal/filter/filter.go index 74941f3..fc0b3b2 100644 --- a/internal/filter/filter.go +++ b/internal/filter/filter.go @@ -27,7 +27,20 @@ func (f *Filter) Glob() string { return f.glob } func (f *Filter) Pattern() string { return f.pattern } func (f *Filter) FileNames() []string { return f.filenames } +func (f *Filter) AddFileName(filename string) { + filename = filepath.Clean(filename) + f.filenames = append(f.filenames, filename) +} + +func (f *Filter) AddFileNames(filenames ...string) { + for _, filename := range filenames { + f.AddFileName(filename) + } +} + func (f *Filter) Match(filename string, modified time.Time) bool { + // this might be unnessary but w/e + filename = filepath.Clean(filename) // on or before/after, not both if !f.on.IsZero() { if !same_day(f.on, modified) { @@ -127,11 +140,12 @@ func New(on, before, after, glob, pattern, unglob, unpattern string, names ...st ) f := &Filter{ - glob: glob, - unglob: unglob, - filenames: append([]string{}, names...), + glob: glob, + unglob: unglob, } + f.AddFileNames(names...) + if on != "" { o, err := anytime.Parse(on, now) if err != nil {