(selected_file FILE_SEARCH)
| 611 | |
| 612 | |
| 613 | func SearchFile(selected_file FILE_SEARCH) []map[string]string { |
| 614 | ans := []map[string]string{} |
| 615 | for _, file := range selected_file.Path { |
| 616 | if !AccessSuperPath(file) { |
| 617 | continue |
| 618 | } |
| 619 | info, err := os.Stat(filepath.Join(SHARE_DIR, file)) |
| 620 | if err != nil { |
| 621 | continue |
| 622 | } |
| 623 | if info.IsDir() { |
| 624 | err := filepath.Walk(filepath.Join(SHARE_DIR, file), func(path string, info os.FileInfo, err error) error { |
| 625 | if err != nil { |
| 626 | return err |
| 627 | } |
| 628 | if (strings.Contains(strings.ToLower(filepath.Base(path)), strings.ToLower(selected_file.Target))) { |
| 629 | dict := make(map[string]string) |
| 630 | relative_path, err := filepath.Rel(selected_file.CurrentDir, path) |
| 631 | if err != nil { |
| 632 | relative_path = path |
| 633 | } |
| 634 | dict["Path"] = relative_path |
| 635 | ans = append(ans, dict) |
| 636 | } |
| 637 | if !IsBinaryFile(path) { |
| 638 | results, _ := FindStringWithContext(path, selected_file.Target) |
| 639 | if len(results) != 0 { |
| 640 | dict := make(map[string]string) |
| 641 | relative_path, err := filepath.Rel(selected_file.CurrentDir, path) |
| 642 | if err != nil { |
| 643 | relative_path = path |
| 644 | } |
| 645 | dict["Path"] = relative_path |
| 646 | dict["Description"] = "" |
| 647 | for _, res := range results { |
| 648 | dict["Description"] = dict["Description"] + "[-- " + res + " --] " |
| 649 | } |
| 650 | ans = append(ans, dict) |
| 651 | } |
| 652 | } |
| 653 | return nil |
| 654 | }) |
| 655 | if err != nil { |
| 656 | continue |
| 657 | } |
| 658 | } else { |
| 659 | if (strings.Contains(strings.ToLower(info.Name()), strings.ToLower(selected_file.Target))) { |
| 660 | dict := make(map[string]string) |
| 661 | dict["Path"] = info.Name() |
| 662 | ans = append(ans, dict) |
| 663 | } |
| 664 | if !IsBinaryFile(filepath.Join(SHARE_DIR, file)) { |
| 665 | results, err := FindStringWithContext(filepath.Join(SHARE_DIR, file), selected_file.Target) |
| 666 | if err != nil { |
| 667 | continue |
| 668 | } |
| 669 | if len(results) == 0 { |
| 670 | continue |
no test coverage detected