Only apply filtering when --filtering is passed

This commit is contained in:
Seednode 2023-11-05 14:03:34 -06:00
parent a918737896
commit b5566eee27
2 changed files with 15 additions and 15 deletions

View File

@ -20,7 +20,7 @@ func (filters *filters) isEmpty() bool {
} }
func (filters *filters) hasIncludes() bool { func (filters *filters) hasIncludes() bool {
return len(filters.included) != 0 return len(filters.included) != 0 && Filtering
} }
func (filters *filters) includes() string { func (filters *filters) includes() string {
@ -28,7 +28,7 @@ func (filters *filters) includes() string {
} }
func (filters *filters) hasExcludes() bool { func (filters *filters) hasExcludes() bool {
return len(filters.excluded) != 0 return len(filters.excluded) != 0 && Filtering
} }
func (filters *filters) excludes() string { func (filters *filters) excludes() string {
@ -41,30 +41,30 @@ func (filters *filters) apply(fileList []string) []string {
copy(result, fileList) copy(result, fileList)
if filters.hasExcludes() { if filters.hasExcludes() {
for _, exclude := range filters.excluded { result = slices.DeleteFunc(result, func(s string) bool {
result = slices.DeleteFunc(result, func(s string) bool { p := filepath.Base(s)
if CaseSensitive {
return strings.Contains(s, filepath.Base(exclude)) for _, exclude := range filters.excluded {
} else { if (CaseSensitive && strings.Contains(p, exclude)) || (!CaseSensitive && strings.Contains(strings.ToLower(p), strings.ToLower(exclude))) {
return strings.Contains(strings.ToLower(s), strings.ToLower(filepath.Base(exclude))) return true
} }
}) }
}
return false
})
} }
if filters.hasIncludes() { if filters.hasIncludes() {
result = slices.DeleteFunc(result, func(s string) bool { result = slices.DeleteFunc(result, func(s string) bool {
var delete bool = true
p := filepath.Base(s) p := filepath.Base(s)
for _, include := range filters.included { for _, include := range filters.included {
if (CaseSensitive && strings.Contains(p, include)) || (!CaseSensitive && strings.Contains(strings.ToLower(p), strings.ToLower(include))) { if (CaseSensitive && strings.Contains(p, include)) || (!CaseSensitive && strings.Contains(strings.ToLower(p), strings.ToLower(include))) {
delete = false return false
} }
} }
return delete return true
}) })
} }

View File

@ -12,7 +12,7 @@ import (
) )
const ( const (
ReleaseVersion string = "3.2.0" ReleaseVersion string = "3.2.1"
) )
var ( var (