From 77e4f01a49117752fa36506a837549faaa7050bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Mon, 15 Jul 2024 20:56:29 -0700 Subject: [PATCH] move some logging around --- internal/files/disk.go | 18 ++++-------------- internal/files/trash.go | 3 --- internal/filter/filter.go | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/internal/files/disk.go b/internal/files/disk.go index 3ea6eb4..134fe7e 100644 --- a/internal/files/disk.go +++ b/internal/files/disk.go @@ -126,21 +126,14 @@ func walk_dir(dir string, f *filter.Filter) (files Files) { name := d.Name() info, _ := d.Info() if f.Match(info) { - log.Debugf("found matching file: %s %s", name, info.ModTime()) - i, err := os.Stat(p) - if err != nil { - log.Debugf("error in file stat: %s", err) - return nil - } files = append(files, DiskFile{ path: p, name: name, - filesize: i.Size(), - modified: i.ModTime(), - isdir: i.IsDir(), + filesize: info.Size(), + modified: info.ModTime(), + isdir: info.IsDir(), + mode: info.Mode(), }) - } else { - log.Debugf("ignoring file %s (%s)", name, info.ModTime()) } return nil }) @@ -171,7 +164,6 @@ func read_dir(dir string, f *filter.Filter) (files Files) { path := filepath.Dir(filepath.Join(dir, name)) if f.Match(info) { - log.Debugf("found matching file: %s %s", name, info.ModTime()) files = append(files, DiskFile{ name: name, path: filepath.Join(path, name), @@ -179,8 +171,6 @@ func read_dir(dir string, f *filter.Filter) (files Files) { filesize: info.Size(), isdir: info.IsDir(), }) - } else { - log.Debugf("ignoring file %s (%s)", name, info.ModTime()) } } return diff --git a/internal/files/trash.go b/internal/files/trash.go index b3aea3a..1052004 100644 --- a/internal/files/trash.go +++ b/internal/files/trash.go @@ -96,7 +96,6 @@ func FindTrash(trashdir, ogdir string, f *filter.Filter) (files Files, outerr er } if f.Match(info) { - log.Debugf("%s: deleted on %s", filename, date.Format(trash_info_date_fmt)) files = append(files, TrashInfo{ name: filename, path: trashedpath, @@ -106,8 +105,6 @@ func FindTrash(trashdir, ogdir string, f *filter.Filter) (files Files, outerr er isdir: info.IsDir(), filesize: info.Size(), }) - } else { - log.Debugf("(ignored) %s: deleted on %s", filename, date.Format(trash_info_date_fmt)) } } diff --git a/internal/filter/filter.go b/internal/filter/filter.go index 8d7540c..3eb2016 100644 --- a/internal/filter/filter.go +++ b/internal/filter/filter.go @@ -59,62 +59,76 @@ func (f *Filter) Match(info fs.FileInfo) bool { // on or before/after, not both if !f.on.IsZero() { if !same_day(f.on, modified) { + log.Debugf("%s: %s isn't on %s, bye!", filename, modified, f.on) return false } } else { if !f.after.IsZero() && f.after.After(modified) { + log.Debugf("%s: %s isn't after %s, bye!", filename, modified, f.after) return false } if !f.before.IsZero() && f.before.Before(modified) { + log.Debugf("%s: %s isn't before %s, bye!", filename, modified, f.before) return false } } if f.has_regex() && !f.matcher.MatchString(filename) { + log.Debugf("%s doesn't match `%s`, bye!", filename, f.matcher.String()) return false } if f.glob != "" { if match, err := filepath.Match(f.glob, filename); err != nil || !match { + log.Debugf("%s doesn't match `%s`, bye!", filename, f.glob) return false } } if f.has_unregex() && f.unmatcher.MatchString(filename) { + log.Debugf("%s matches `%s`, bye!", filename, f.unmatcher.String()) return false } if f.unglob != "" { if match, err := filepath.Match(f.unglob, filename); err != nil || match { + log.Debugf("%s matches `%s`, bye!", filename, f.unglob) return false } } if len(f.filenames) > 0 && !slices.Contains(f.filenames, filename) { + log.Debugf("%s isn't in %v, bye!", filename, f.filenames) return false } if f.filesonly && isdir { + log.Debugf("%s is dir, bye!", filename) return false } if f.dirsonly && !isdir { + log.Debugf("%s is file, bye!", filename) return false } if f.ignorehidden && strings.HasPrefix(filename, ".") { + log.Debugf("%s is hidden, bye!", filename) return false } if f.maxsize != 0 && f.maxsize < size { + log.Debugf("%s is larger than %d, bye!", filename, f.maxsize) return false } if f.minsize != 0 && f.minsize > size { + log.Debugf("%s is smaller than %d, bye!", filename, f.minsize) return false } // okay it was good + log.Debugf("%s modified:'%s' dir:'%T' mode:'%s' was a good one!", filename, modified, isdir, mode) return true }