move some logging around

This commit is contained in:
Lilian Jónsdóttir 2024-07-15 20:56:29 -07:00
parent 15bd040deb
commit 77e4f01a49
3 changed files with 18 additions and 17 deletions

View file

@ -126,21 +126,14 @@ func walk_dir(dir string, f *filter.Filter) (files Files) {
name := d.Name() name := d.Name()
info, _ := d.Info() info, _ := d.Info()
if f.Match(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{ files = append(files, DiskFile{
path: p, path: p,
name: name, name: name,
filesize: i.Size(), filesize: info.Size(),
modified: i.ModTime(), modified: info.ModTime(),
isdir: i.IsDir(), isdir: info.IsDir(),
mode: info.Mode(),
}) })
} else {
log.Debugf("ignoring file %s (%s)", name, info.ModTime())
} }
return nil return nil
}) })
@ -171,7 +164,6 @@ func read_dir(dir string, f *filter.Filter) (files Files) {
path := filepath.Dir(filepath.Join(dir, name)) path := filepath.Dir(filepath.Join(dir, name))
if f.Match(info) { if f.Match(info) {
log.Debugf("found matching file: %s %s", name, info.ModTime())
files = append(files, DiskFile{ files = append(files, DiskFile{
name: name, name: name,
path: filepath.Join(path, name), path: filepath.Join(path, name),
@ -179,8 +171,6 @@ func read_dir(dir string, f *filter.Filter) (files Files) {
filesize: info.Size(), filesize: info.Size(),
isdir: info.IsDir(), isdir: info.IsDir(),
}) })
} else {
log.Debugf("ignoring file %s (%s)", name, info.ModTime())
} }
} }
return return

View file

@ -96,7 +96,6 @@ func FindTrash(trashdir, ogdir string, f *filter.Filter) (files Files, outerr er
} }
if f.Match(info) { if f.Match(info) {
log.Debugf("%s: deleted on %s", filename, date.Format(trash_info_date_fmt))
files = append(files, TrashInfo{ files = append(files, TrashInfo{
name: filename, name: filename,
path: trashedpath, path: trashedpath,
@ -106,8 +105,6 @@ func FindTrash(trashdir, ogdir string, f *filter.Filter) (files Files, outerr er
isdir: info.IsDir(), isdir: info.IsDir(),
filesize: info.Size(), filesize: info.Size(),
}) })
} else {
log.Debugf("(ignored) %s: deleted on %s", filename, date.Format(trash_info_date_fmt))
} }
} }

View file

@ -59,62 +59,76 @@ func (f *Filter) Match(info fs.FileInfo) bool {
// 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) {
log.Debugf("%s: %s isn't on %s, bye!", filename, modified, f.on)
return false return false
} }
} else { } else {
if !f.after.IsZero() && f.after.After(modified) { if !f.after.IsZero() && f.after.After(modified) {
log.Debugf("%s: %s isn't after %s, bye!", filename, modified, f.after)
return false return false
} }
if !f.before.IsZero() && f.before.Before(modified) { if !f.before.IsZero() && f.before.Before(modified) {
log.Debugf("%s: %s isn't before %s, bye!", filename, modified, f.before)
return false return false
} }
} }
if f.has_regex() && !f.matcher.MatchString(filename) { if f.has_regex() && !f.matcher.MatchString(filename) {
log.Debugf("%s doesn't match `%s`, bye!", filename, f.matcher.String())
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 {
log.Debugf("%s doesn't match `%s`, bye!", filename, f.glob)
return false return false
} }
} }
if f.has_unregex() && f.unmatcher.MatchString(filename) { if f.has_unregex() && f.unmatcher.MatchString(filename) {
log.Debugf("%s matches `%s`, bye!", filename, f.unmatcher.String())
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 {
log.Debugf("%s matches `%s`, bye!", filename, f.unglob)
return false return false
} }
} }
if len(f.filenames) > 0 && !slices.Contains(f.filenames, filename) { if len(f.filenames) > 0 && !slices.Contains(f.filenames, filename) {
log.Debugf("%s isn't in %v, bye!", filename, f.filenames)
return false return false
} }
if f.filesonly && isdir { if f.filesonly && isdir {
log.Debugf("%s is dir, bye!", filename)
return false return false
} }
if f.dirsonly && !isdir { if f.dirsonly && !isdir {
log.Debugf("%s is file, bye!", filename)
return false return false
} }
if f.ignorehidden && strings.HasPrefix(filename, ".") { if f.ignorehidden && strings.HasPrefix(filename, ".") {
log.Debugf("%s is hidden, bye!", filename)
return false return false
} }
if f.maxsize != 0 && f.maxsize < size { if f.maxsize != 0 && f.maxsize < size {
log.Debugf("%s is larger than %d, bye!", filename, f.maxsize)
return false return false
} }
if f.minsize != 0 && f.minsize > size { if f.minsize != 0 && f.minsize > size {
log.Debugf("%s is smaller than %d, bye!", filename, f.minsize)
return false return false
} }
// okay it was good // okay it was good
log.Debugf("%s modified:'%s' dir:'%T' mode:'%s' was a good one!", filename, modified, isdir, mode)
return true return true
} }