From 807072a77ffdba65690c6aad0da1bac9eba064f5 Mon Sep 17 00:00:00 2001 From: bel Date: Sun, 1 Dec 2019 14:16:45 -0700 Subject: [PATCH] Unittest and exec file proof on search --- notes/search.go | 6 ++++-- notes/search_test.go | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/notes/search.go b/notes/search.go index bef58a3..4651c62 100755 --- a/notes/search.go +++ b/notes/search.go @@ -8,7 +8,6 @@ import ( "os" "path" "path/filepath" - "strings" ) func (n *Notes) Search(phrase string) (string, error) { @@ -21,10 +20,13 @@ func (n *Notes) Search(phrase string) (string, error) { if info.IsDir() { return nil } - if splits := strings.Split(info.Name(), "."); len(splits) > 1 && !(strings.HasSuffix(info.Name(), ".md") || strings.HasSuffix(info.Name(), ".txt")) { + if size := info.Size(); size < 1 || size > (5*1024*1024) { return nil } ok, err := grepFile(walked, []byte(phrase)) + if err != nil && err.Error() == "bufio.Scanner: token too long" { + err = nil + } if err == nil && ok { p := filetree.NewPathFromLocal(path.Dir(walked)) files.Push(p, info) diff --git a/notes/search_test.go b/notes/search_test.go index 6dfcb98..5660eca 100755 --- a/notes/search_test.go +++ b/notes/search_test.go @@ -42,3 +42,13 @@ func TestSearch(t *testing.T) { t.Fatal(v, result) } } + +func TestSearchBigFiles(t *testing.T) { + n := New() + n.root = "/usr/local/bin" + + _, err := n.Search("this file") + if err != nil { + t.Fatal(err) + } +}