Skip to content

Commit

Permalink
fix: search (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias authored and 1138-4EB committed Jan 9, 2019
1 parent 73e0aca commit bafe9f0
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
search := parseSearch(query)

return afero.Walk(fs, scope, func(path string, f os.FileInfo, err error) error {
path = strings.TrimPrefix(path, "/")
path = strings.Replace(path, "\\", "/", -1)
scope = strings.Replace(scope, "\\", "/", -1)
scope = strings.TrimPrefix(scope, "/")
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
}

if !search.CaseSensitive {
path = strings.ToLower(path)
if !checker.Check(path) {
return nil
}

if !search.CaseSensitive {
Expand All @@ -52,7 +59,7 @@ func Search(fs afero.Fs, scope, query string, checker rules.Checker, found func(
if len(search.Terms) > 0 {
for _, term := range search.Terms {
if strings.Contains(path, term) {
return found(strings.TrimPrefix(path, scope), f)
return found(strings.TrimPrefix(originalPath, scope), f)
}
}
}
Expand Down

0 comments on commit bafe9f0

Please sign in to comment.