zricethezav 8 лет назад
Родитель
Сommit
f27c0a62c9
2 измененных файлов с 24 добавлено и 25 удалено
  1. 24 24
      leaks.go
  2. 0 1
      main.go

+ 24 - 24
leaks.go

@@ -39,7 +39,6 @@ func start(opts *Options, repoUrl string) {
 
 
 	report := getLeaks(repoName)
 	report := getLeaks(repoName)
 	cleanup(repoName)
 	cleanup(repoName)
-
 	reportJson, _ := json.MarshalIndent(report, "", "\t")
 	reportJson, _ := json.MarshalIndent(report, "", "\t")
 	err = ioutil.WriteFile(fmt.Sprintf("%s_leaks.json", repoName), reportJson, 0644)
 	err = ioutil.WriteFile(fmt.Sprintf("%s_leaks.json", repoName), reportJson, 0644)
 }
 }
@@ -56,29 +55,35 @@ func cleanup(repoName string) {
 
 
 func getLeaks(repoName string) []LeakElem {
 func getLeaks(repoName string) []LeakElem {
 	var (
 	var (
-		out           []byte
-		err           error
-		wg            sync.WaitGroup
-		concurrent    = 100
-		semaphoreChan = make(chan struct{}, concurrent)
-		gitLeaks      = make(chan LeakElem)
+		out               []byte
+		err               error
+		commitWG          sync.WaitGroup
+		gitLeakReceiverWG sync.WaitGroup
+		concurrent        = 100
+		semaphoreChan     = make(chan struct{}, concurrent)
+		gitLeaks          = make(chan LeakElem)
+		report            []LeakElem
 	)
 	)
 
 
+	go func(commitWG *sync.WaitGroup, gitLeakReceiverWG *sync.WaitGroup) {
+		for gitLeak := range gitLeaks {
+			fmt.Println(gitLeak)
+			report = append(report, gitLeak)
+			gitLeakReceiverWG.Done()
+		}
+	}(&commitWG, &gitLeakReceiverWG)
+
 	out, err = exec.Command("git", "rev-list", "--all", "--remotes", "--topo-order").Output()
 	out, err = exec.Command("git", "rev-list", "--all", "--remotes", "--topo-order").Output()
 	if err != nil {
 	if err != nil {
 		log.Fatalf("error retrieving commits%v\n", err)
 		log.Fatalf("error retrieving commits%v\n", err)
 	}
 	}
 
 
 	commits := bytes.Split(out, []byte("\n"))
 	commits := bytes.Split(out, []byte("\n"))
-	for j, currCommitB := range commits {
+	commitWG.Add(len(commits))
+	for _, currCommitB := range commits {
 		currCommit := string(currCommitB)
 		currCommit := string(currCommitB)
-		if j == len(commits)-2 {
-			break
-		}
-
-		wg.Add(1)
-		go func(currCommit string, repoName string) {
-			defer wg.Done()
+		go func(currCommit string, repoName string, commitWG *sync.WaitGroup, gitLeakReceiverWG *sync.WaitGroup) {
+			defer commitWG.Done()
 			var leakPrs bool
 			var leakPrs bool
 
 
 			if err := os.Chdir(fmt.Sprintf("%s/%s", appRoot, repoName)); err != nil {
 			if err := os.Chdir(fmt.Sprintf("%s/%s", appRoot, repoName)); err != nil {
@@ -101,19 +106,14 @@ func getLeaks(repoName string) []LeakElem {
 			for _, line := range lines {
 			for _, line := range lines {
 				leakPrs = checkEntropy(line)
 				leakPrs = checkEntropy(line)
 				if leakPrs {
 				if leakPrs {
+					gitLeakReceiverWG.Add(1)
 					gitLeaks <- LeakElem{line, currCommit}
 					gitLeaks <- LeakElem{line, currCommit}
 				}
 				}
 			}
 			}
-
-		}(currCommit, repoName)
+		}(currCommit, repoName, &commitWG, &gitLeakReceiverWG)
 	}
 	}
-	go func() {
-		for gitLeak := range gitLeaks {
-			fmt.Println(gitLeak)
-			report = append(report, gitLeak)
-		}
-	}()
-	wg.Wait()
 
 
+	commitWG.Wait()
+	gitLeakReceiverWG.Wait()
 	return report
 	return report
 }
 }

+ 0 - 1
main.go

@@ -9,7 +9,6 @@ var (
 	appRoot     string
 	appRoot     string
 	regexes     map[string]*regexp.Regexp
 	regexes     map[string]*regexp.Regexp
 	assignRegex *regexp.Regexp
 	assignRegex *regexp.Regexp
-	report      []LeakElem
 )
 )
 
 
 func init() {
 func init() {