From c2028e38d2d92ebad25b9d41b3bc8eb50f2718ab Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 30 Jun 2017 14:52:58 +0200 Subject: pkg/report: change arg of ExtractGuiltyFile to []byte We usually store reports as []byte, not as string. They can be large. So change arg type to []byte. Also rename it from log to report. In our terminology log is not symblized/processed crash output. What this function wants is called report in manager. --- pkg/report/guilty.go | 11 ++++++----- pkg/report/guilty_test.go | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'pkg') diff --git a/pkg/report/guilty.go b/pkg/report/guilty.go index 272f63063..41dc65cbd 100644 --- a/pkg/report/guilty.go +++ b/pkg/report/guilty.go @@ -4,6 +4,7 @@ package report import ( + "bytes" "net/mail" "regexp" "strings" @@ -34,17 +35,17 @@ var ( } ) -func extractFiles(log string) []string { - matches := filename.FindAllString(log, -1) +func extractFiles(report []byte) []string { + matches := filename.FindAll(report, -1) var files []string for _, match := range matches { - files = append(files, strings.Split(match, ":")[0]) + files = append(files, string(bytes.Split(match, []byte{':'})[0])) } return files } -func ExtractGuiltyFile(log string) string { - files := extractFiles(log) +func ExtractGuiltyFile(report []byte) string { + files := extractFiles(report) nextFile: for _, file := range files { for _, re := range blacklist { diff --git a/pkg/report/guilty_test.go b/pkg/report/guilty_test.go index 2f4b9c244..1138f7a6c 100644 --- a/pkg/report/guilty_test.go +++ b/pkg/report/guilty_test.go @@ -703,10 +703,10 @@ Call Trace: [] nf_sockopt net/netfilter/nf_sockopt.c:105 [inline] `: `net/netfilter/x_tables.c`, } - for log, guilty0 := range tests { - if guilty := ExtractGuiltyFile(log); guilty != guilty0 { - t.Logf("log:\n%s", log) - t.Logf("extracted files:\n%s", extractFiles(log)) + for report, guilty0 := range tests { + if guilty := ExtractGuiltyFile([]byte(report)); guilty != guilty0 { + t.Logf("log:\n%s", report) + t.Logf("extracted files:\n%s", extractFiles([]byte(report))) t.Logf("want guilty:\n%s", guilty0) t.Logf("got guilty:\n%s", guilty) t.Fatalf("couldn't extract guilty file") -- cgit mrf-deployment