Skip to content

Commit

Permalink
get rid of global file cache
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
  • Loading branch information
erizocosmico committed Jan 30, 2018
1 parent 259fe0a commit ca5e3a5
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"strings"
)

var fileCache = make(map[string]struct{})

func trimBOM(line string) string {
l := len(line)
if l >= 3 {
Expand Down Expand Up @@ -38,7 +36,7 @@ func containComments(line, commentStart, commentEnd string) bool {
return inComments != 0
}

func checkMD5Sum(path string) (ignore bool) {
func checkMD5Sum(path string, fileCache map[string]struct{}) (ignore bool) {
content, err := ioutil.ReadFile(path)
if err != nil {
return true
Expand Down Expand Up @@ -71,6 +69,7 @@ func isVCSDir(path string) bool {
// getAllFiles return all of the files to be analyzed in paths.
func getAllFiles(paths []string, languages *DefinedLanguages, opts *ClocOptions) (result map[string]*Language, err error) {
result = make(map[string]*Language, 0)
fileCache := make(map[string]struct{})

for _, root := range paths {
vcsInRoot := isVCSDir(root)
Expand Down Expand Up @@ -109,7 +108,7 @@ func getAllFiles(paths []string, languages *DefinedLanguages, opts *ClocOptions)
}

if !opts.SkipDuplicated {
ignore := checkMD5Sum(path)
ignore := checkMD5Sum(path, fileCache)
if ignore {
if opts.Debug {
fmt.Printf("[ignore=%v] find same md5\n", path)
Expand Down

0 comments on commit ca5e3a5

Please sign in to comment.