From dff6c62e563d6b86af91dc9019ada2390d1bc8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Wed, 3 Jul 2024 10:17:08 -0700 Subject: [PATCH] revert filter.showhidden to filter.ignorehidden because blank filter should show all files --- internal/files/files.go | 2 +- internal/filter/filter.go | 22 +++++++++++----------- internal/filter/filter_test.go | 20 ++++++++++---------- main.go | 7 ++++--- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/internal/files/files.go b/internal/files/files.go index b66037f..81cfd52 100644 --- a/internal/files/files.go +++ b/internal/files/files.go @@ -105,7 +105,7 @@ func walk_dir(dir string, f *filter.Filter) (files Files) { return nil } - if is_in_recursive_dir(dir, path) && !f.ShowHidden() { + if is_in_recursive_dir(dir, path) && !f.IgnoreHidden() { return nil } diff --git a/internal/filter/filter.go b/internal/filter/filter.go index 1f52652..ecf50bc 100644 --- a/internal/filter/filter.go +++ b/internal/filter/filter.go @@ -20,7 +20,7 @@ type Filter struct { unglob, unpattern string filenames []string dirsonly, filesonly bool - showhidden bool + ignorehidden bool matcher *regexp.Regexp unmatcher *regexp.Regexp minsize, maxsize int64 @@ -34,7 +34,7 @@ func (f *Filter) Pattern() string { return f.pattern } func (f *Filter) FileNames() []string { return f.filenames } func (f *Filter) FilesOnly() bool { return f.filesonly } func (f *Filter) DirsOnly() bool { return f.dirsonly } -func (f *Filter) ShowHidden() bool { return f.showhidden } +func (f *Filter) IgnoreHidden() bool { return f.ignorehidden } func (f *Filter) MinSize() int64 { return f.minsize } func (f *Filter) MaxSize() int64 { return f.maxsize } @@ -99,7 +99,7 @@ func (f *Filter) Match(filename string, modified time.Time, size int64, isdir bo return false } - if !f.showhidden && strings.HasPrefix(filename, ".") { + if f.ignorehidden && strings.HasPrefix(filename, ".") { return false } @@ -139,7 +139,7 @@ func (f *Filter) Blank() bool { f.before.Equal(t) && f.on.Equal(t) && len(f.filenames) == 0 && - !f.showhidden && + !f.ignorehidden && !f.filesonly && !f.dirsonly && f.minsize == 0 && @@ -161,7 +161,7 @@ func (f *Filter) String() string { f.unglob, unm, f.filenames, f.filesonly, f.dirsonly, - f.showhidden, + f.ignorehidden, ) } @@ -179,18 +179,18 @@ func (f *Filter) has_unregex() bool { return f.unmatcher.String() != "" } -func New(on, before, after, glob, pattern, unglob, unpattern string, filesonly, dirsonly, showhidden bool, minsize, maxsize string, names ...string) (*Filter, error) { +func New(on, before, after, glob, pattern, unglob, unpattern string, filesonly, dirsonly, ignorehidden bool, minsize, maxsize string, names ...string) (*Filter, error) { var ( err error now = time.Now() ) f := &Filter{ - glob: glob, - unglob: unglob, - filesonly: filesonly, - dirsonly: dirsonly, - showhidden: showhidden, + glob: glob, + unglob: unglob, + filesonly: filesonly, + dirsonly: dirsonly, + ignorehidden: ignorehidden, } f.AddFileNames(names...) diff --git a/internal/filter/filter_test.go b/internal/filter/filter_test.go index 725ced2..d2bfd56 100644 --- a/internal/filter/filter_test.go +++ b/internal/filter/filter_test.go @@ -27,7 +27,7 @@ type testholder struct { before, after, on string filenames []string filesonly, dirsonly bool - showhidden bool + ignorehidden bool good, bad []singletest minsize, maxsize string } @@ -38,7 +38,7 @@ func (t testholder) String() string { "before:'%s' after:'%s' on:'%s' filesonly:'%t' dirsonly:'%t' "+ "showhidden:'%t' minsize:'%s' maxsize:'%s'", t.pattern, t.glob, t.unpattern, t.unglob, t.filenames, t.before, t.after, t.on, - t.filesonly, t.dirsonly, t.showhidden, t.minsize, t.maxsize, + t.filesonly, t.dirsonly, t.ignorehidden, t.minsize, t.maxsize, ) } @@ -63,7 +63,7 @@ func testmatch(t *testing.T, testers []testholder) { f, err = New( tester.on, tester.before, tester.after, tester.glob, tester.pattern, tester.unglob, tester.unpattern, tester.filesonly, tester.dirsonly, - tester.showhidden, tester.minsize, tester.maxsize, + tester.ignorehidden, tester.minsize, tester.maxsize, tester.filenames..., ) if err != nil { @@ -375,13 +375,13 @@ func TestFilterDirsOnly(t *testing.T) { func TestFilterShowHidden(t *testing.T) { testmatch(t, []testholder{ { - showhidden: false, - good: append(blanktime(true, "test", "alsotest", "helloworld"), blanktime(false, "test", "alsotest", "helloworld")...), - bad: append(blanktime(true, ".test", ".alsotest", ".helloworld"), blanktime(false, ".test", ".alsotest", ".helloworld")...), + ignorehidden: true, + good: append(blanktime(true, "test", "alsotest", "helloworld"), blanktime(false, "test", "alsotest", "helloworld")...), + bad: append(blanktime(true, ".test", ".alsotest", ".helloworld"), blanktime(false, ".test", ".alsotest", ".helloworld")...), }, { - showhidden: true, - good: append(blanktime(true, "test", "alsotest", ".helloworld"), blanktime(false, "test", "alsotest", ".helloworld")...), + ignorehidden: false, + good: append(blanktime(true, "test", "alsotest", ".helloworld"), blanktime(false, "test", "alsotest", ".helloworld")...), }, }) } @@ -574,7 +574,7 @@ func TestFilterNotBlank(t *testing.T) { dirsonly: true, }, { - showhidden: true, + ignorehidden: true, }, } ) @@ -584,7 +584,7 @@ func TestFilterNotBlank(t *testing.T) { f, _ = New( tester.on, tester.before, tester.after, tester.glob, tester.pattern, tester.unglob, tester.unpattern, tester.filesonly, tester.dirsonly, - tester.showhidden, tester.minsize, tester.maxsize, + tester.ignorehidden, tester.minsize, tester.maxsize, tester.filenames..., ) if f.Blank() { diff --git a/main.go b/main.go index 801129f..f2a1ced 100644 --- a/main.go +++ b/main.go @@ -92,7 +92,7 @@ var ( ) if f == nil { - f, err = filter.New(o, b, a, g, p, ung, unp, fo, do, true, sm, lg) + f, err = filter.New(o, b, a, g, p, ung, unp, fo, do, false, sm, lg) } if err != nil { return err @@ -116,7 +116,7 @@ var ( beforeCommands = func(ctx *cli.Context) (err error) { // setup filter if f == nil { - f, err = filter.New(o, b, a, g, p, ung, unp, fo, do, true, sm, lg, ctx.Args().Slice()...) + f, err = filter.New(o, b, a, g, p, ung, unp, fo, do, false, sm, lg, ctx.Args().Slice()...) } log.Debugf("filter: %s", f.String()) return @@ -124,7 +124,7 @@ var ( beforeTrash = func(_ *cli.Context) (err error) { if f == nil { - f, err = filter.New(o, b, a, g, p, ung, unp, fo, do, sh, sm, lg) + f, err = filter.New(o, b, a, g, p, ung, unp, fo, do, !sh, sm, lg) } log.Debugf("filter: %s", f.String()) return @@ -200,6 +200,7 @@ var ( fls, err := trash.FindFiles(trashDir, ogdir, f) var msg string + log.Debugf("filter '%s' is blark? %t in %s", f, f.Blank(), ogdir) if f.Blank() && ogdir == "" { msg = "trash is empty" } else {