revert filter.showhidden to filter.ignorehidden
because blank filter should show all files
This commit is contained in:
parent
1dd192cc91
commit
dff6c62e56
|
@ -105,7 +105,7 @@ func walk_dir(dir string, f *filter.Filter) (files Files) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_in_recursive_dir(dir, path) && !f.ShowHidden() {
|
if is_in_recursive_dir(dir, path) && !f.IgnoreHidden() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ type Filter struct {
|
||||||
unglob, unpattern string
|
unglob, unpattern string
|
||||||
filenames []string
|
filenames []string
|
||||||
dirsonly, filesonly bool
|
dirsonly, filesonly bool
|
||||||
showhidden bool
|
ignorehidden bool
|
||||||
matcher *regexp.Regexp
|
matcher *regexp.Regexp
|
||||||
unmatcher *regexp.Regexp
|
unmatcher *regexp.Regexp
|
||||||
minsize, maxsize int64
|
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) FileNames() []string { return f.filenames }
|
||||||
func (f *Filter) FilesOnly() bool { return f.filesonly }
|
func (f *Filter) FilesOnly() bool { return f.filesonly }
|
||||||
func (f *Filter) DirsOnly() bool { return f.dirsonly }
|
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) MinSize() int64 { return f.minsize }
|
||||||
func (f *Filter) MaxSize() int64 { return f.maxsize }
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if !f.showhidden && strings.HasPrefix(filename, ".") {
|
if f.ignorehidden && strings.HasPrefix(filename, ".") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ func (f *Filter) Blank() bool {
|
||||||
f.before.Equal(t) &&
|
f.before.Equal(t) &&
|
||||||
f.on.Equal(t) &&
|
f.on.Equal(t) &&
|
||||||
len(f.filenames) == 0 &&
|
len(f.filenames) == 0 &&
|
||||||
!f.showhidden &&
|
!f.ignorehidden &&
|
||||||
!f.filesonly &&
|
!f.filesonly &&
|
||||||
!f.dirsonly &&
|
!f.dirsonly &&
|
||||||
f.minsize == 0 &&
|
f.minsize == 0 &&
|
||||||
|
@ -161,7 +161,7 @@ func (f *Filter) String() string {
|
||||||
f.unglob, unm,
|
f.unglob, unm,
|
||||||
f.filenames,
|
f.filenames,
|
||||||
f.filesonly, f.dirsonly,
|
f.filesonly, f.dirsonly,
|
||||||
f.showhidden,
|
f.ignorehidden,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ func (f *Filter) has_unregex() bool {
|
||||||
return f.unmatcher.String() != ""
|
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 (
|
var (
|
||||||
err error
|
err error
|
||||||
now = time.Now()
|
now = time.Now()
|
||||||
|
@ -190,7 +190,7 @@ func New(on, before, after, glob, pattern, unglob, unpattern string, filesonly,
|
||||||
unglob: unglob,
|
unglob: unglob,
|
||||||
filesonly: filesonly,
|
filesonly: filesonly,
|
||||||
dirsonly: dirsonly,
|
dirsonly: dirsonly,
|
||||||
showhidden: showhidden,
|
ignorehidden: ignorehidden,
|
||||||
}
|
}
|
||||||
|
|
||||||
f.AddFileNames(names...)
|
f.AddFileNames(names...)
|
||||||
|
|
|
@ -27,7 +27,7 @@ type testholder struct {
|
||||||
before, after, on string
|
before, after, on string
|
||||||
filenames []string
|
filenames []string
|
||||||
filesonly, dirsonly bool
|
filesonly, dirsonly bool
|
||||||
showhidden bool
|
ignorehidden bool
|
||||||
good, bad []singletest
|
good, bad []singletest
|
||||||
minsize, maxsize string
|
minsize, maxsize string
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ func (t testholder) String() string {
|
||||||
"before:'%s' after:'%s' on:'%s' filesonly:'%t' dirsonly:'%t' "+
|
"before:'%s' after:'%s' on:'%s' filesonly:'%t' dirsonly:'%t' "+
|
||||||
"showhidden:'%t' minsize:'%s' maxsize:'%s'",
|
"showhidden:'%t' minsize:'%s' maxsize:'%s'",
|
||||||
t.pattern, t.glob, t.unpattern, t.unglob, t.filenames, t.before, t.after, t.on,
|
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(
|
f, err = New(
|
||||||
tester.on, tester.before, tester.after, tester.glob, tester.pattern,
|
tester.on, tester.before, tester.after, tester.glob, tester.pattern,
|
||||||
tester.unglob, tester.unpattern, tester.filesonly, tester.dirsonly,
|
tester.unglob, tester.unpattern, tester.filesonly, tester.dirsonly,
|
||||||
tester.showhidden, tester.minsize, tester.maxsize,
|
tester.ignorehidden, tester.minsize, tester.maxsize,
|
||||||
tester.filenames...,
|
tester.filenames...,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -375,12 +375,12 @@ func TestFilterDirsOnly(t *testing.T) {
|
||||||
func TestFilterShowHidden(t *testing.T) {
|
func TestFilterShowHidden(t *testing.T) {
|
||||||
testmatch(t, []testholder{
|
testmatch(t, []testholder{
|
||||||
{
|
{
|
||||||
showhidden: false,
|
ignorehidden: true,
|
||||||
good: append(blanktime(true, "test", "alsotest", "helloworld"), blanktime(false, "test", "alsotest", "helloworld")...),
|
good: append(blanktime(true, "test", "alsotest", "helloworld"), blanktime(false, "test", "alsotest", "helloworld")...),
|
||||||
bad: 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,
|
ignorehidden: false,
|
||||||
good: append(blanktime(true, "test", "alsotest", ".helloworld"), blanktime(false, "test", "alsotest", ".helloworld")...),
|
good: append(blanktime(true, "test", "alsotest", ".helloworld"), blanktime(false, "test", "alsotest", ".helloworld")...),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -574,7 +574,7 @@ func TestFilterNotBlank(t *testing.T) {
|
||||||
dirsonly: true,
|
dirsonly: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
showhidden: true,
|
ignorehidden: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -584,7 +584,7 @@ func TestFilterNotBlank(t *testing.T) {
|
||||||
f, _ = New(
|
f, _ = New(
|
||||||
tester.on, tester.before, tester.after, tester.glob, tester.pattern,
|
tester.on, tester.before, tester.after, tester.glob, tester.pattern,
|
||||||
tester.unglob, tester.unpattern, tester.filesonly, tester.dirsonly,
|
tester.unglob, tester.unpattern, tester.filesonly, tester.dirsonly,
|
||||||
tester.showhidden, tester.minsize, tester.maxsize,
|
tester.ignorehidden, tester.minsize, tester.maxsize,
|
||||||
tester.filenames...,
|
tester.filenames...,
|
||||||
)
|
)
|
||||||
if f.Blank() {
|
if f.Blank() {
|
||||||
|
|
7
main.go
7
main.go
|
@ -92,7 +92,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
if f == nil {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -116,7 +116,7 @@ var (
|
||||||
beforeCommands = func(ctx *cli.Context) (err error) {
|
beforeCommands = func(ctx *cli.Context) (err error) {
|
||||||
// setup filter
|
// setup filter
|
||||||
if f == nil {
|
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())
|
log.Debugf("filter: %s", f.String())
|
||||||
return
|
return
|
||||||
|
@ -124,7 +124,7 @@ var (
|
||||||
|
|
||||||
beforeTrash = func(_ *cli.Context) (err error) {
|
beforeTrash = func(_ *cli.Context) (err error) {
|
||||||
if f == nil {
|
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())
|
log.Debugf("filter: %s", f.String())
|
||||||
return
|
return
|
||||||
|
@ -200,6 +200,7 @@ var (
|
||||||
fls, err := trash.FindFiles(trashDir, ogdir, f)
|
fls, err := trash.FindFiles(trashDir, ogdir, f)
|
||||||
|
|
||||||
var msg string
|
var msg string
|
||||||
|
log.Debugf("filter '%s' is blark? %t in %s", f, f.Blank(), ogdir)
|
||||||
if f.Blank() && ogdir == "" {
|
if f.Blank() && ogdir == "" {
|
||||||
msg = "trash is empty"
|
msg = "trash is empty"
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue