fix: search (#625)
parent
73e0acaa71
commit
bafe9f0ad7
|
@ -18,16 +18,23 @@ type searchOptions struct {
|
||||||
func Search(fs afero.Fs, scope, query string, checker rules.Checker, found func(path string, f os.FileInfo) error) error {
|
func Search(fs afero.Fs, scope, query string, checker rules.Checker, found func(path string, f os.FileInfo) error) error {
|
||||||
search := parseSearch(query)
|
search := parseSearch(query)
|
||||||
|
|
||||||
return afero.Walk(fs, scope, func(path string, f os.FileInfo, err error) error {
|
scope = strings.Replace(scope, "\\", "/", -1)
|
||||||
path = strings.TrimPrefix(path, "/")
|
scope = strings.TrimPrefix(scope, "/")
|
||||||
path = strings.Replace(path, "\\", "/", -1)
|
scope = strings.TrimSuffix(scope, "/")
|
||||||
|
scope = "/" + scope + "/"
|
||||||
|
|
||||||
if !checker.Check(path) {
|
return afero.Walk(fs, scope, func(originalPath string, f os.FileInfo, err error) error {
|
||||||
|
originalPath = strings.Replace(originalPath, "\\", "/", -1)
|
||||||
|
originalPath = strings.TrimPrefix(originalPath, "/")
|
||||||
|
originalPath = "/" + originalPath
|
||||||
|
path := originalPath
|
||||||
|
|
||||||
|
if path == scope {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !search.CaseSensitive {
|
if !checker.Check(path) {
|
||||||
path = strings.ToLower(path)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !search.CaseSensitive {
|
if !search.CaseSensitive {
|
||||||
|
@ -52,7 +59,7 @@ func Search(fs afero.Fs, scope, query string, checker rules.Checker, found func(
|
||||||
if len(search.Terms) > 0 {
|
if len(search.Terms) > 0 {
|
||||||
for _, term := range search.Terms {
|
for _, term := range search.Terms {
|
||||||
if strings.Contains(path, term) {
|
if strings.Contains(path, term) {
|
||||||
return found(strings.TrimPrefix(path, scope), f)
|
return found(strings.TrimPrefix(originalPath, scope), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue