From 7651dc2a05c0bdb48de69adb9fb1bda7304b2e30 Mon Sep 17 00:00:00 2001 From: JanHoefelmeyer Date: Wed, 23 Aug 2023 11:40:37 +0200 Subject: [PATCH 1/5] Sort missing files into errors --- cmd/csaf_checker/processor.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cmd/csaf_checker/processor.go b/cmd/csaf_checker/processor.go index eef6f3d..3802f2d 100644 --- a/cmd/csaf_checker/processor.go +++ b/cmd/csaf_checker/processor.go @@ -24,6 +24,7 @@ import ( "net/url" "path/filepath" "regexp" + "slices" "sort" "strconv" "strings" @@ -1115,6 +1116,8 @@ func (p *processor) checkMissing(string) error { for _, f := range files { v := p.alreadyChecked[f] var where []string + // mistake contains which requirements are broken + var mistake []string for mask := rolieMask; mask <= listingMask; mask <<= 1 { if maxMask&mask == mask { var in string @@ -1122,11 +1125,27 @@ func (p *processor) checkMissing(string) error { in = "in" } else { in = "not in" + // Which file is missing entries? + mistake = append(mistake, mask.String()) } where = append(where, in+" "+mask.String()) } } - p.badIntegrities.error("%s %s", f, strings.Join(where, ", ")) + // List error in all appropriate categories + if slices.Contains(mistake, "ROLIE") { + p.badROLIEFeed.error("%s %s", f, strings.Join(where, ", ")) + } + if slices.Contains(mistake, "index.txt") { + p.badIndices.error("%s %s", f, strings.Join(where, ", ")) + } + if slices.Contains(mistake, "changes.csv") { + p.badChanges.error("%s %s", f, strings.Join(where, ", ")) + } + if slices.Contains(mistake, "directory listing") { + p.badDirListings.error("%s %s", f, strings.Join(where, ", ")) + } + // reset mistake + mistake = nil } return nil } From 4b56f3e83714ddd4da97d77edc8c9f38dad41c6a Mon Sep 17 00:00:00 2001 From: JanHoefelmeyer Date: Wed, 23 Aug 2023 12:29:05 +0200 Subject: [PATCH 2/5] Exchange slice with util.set for mistakes in checkMissing --- cmd/csaf_checker/processor.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/csaf_checker/processor.go b/cmd/csaf_checker/processor.go index 3802f2d..0b976f6 100644 --- a/cmd/csaf_checker/processor.go +++ b/cmd/csaf_checker/processor.go @@ -24,7 +24,6 @@ import ( "net/url" "path/filepath" "regexp" - "slices" "sort" "strconv" "strings" @@ -1117,7 +1116,7 @@ func (p *processor) checkMissing(string) error { v := p.alreadyChecked[f] var where []string // mistake contains which requirements are broken - var mistake []string + mistake := util.Set[whereType]{} for mask := rolieMask; mask <= listingMask; mask <<= 1 { if maxMask&mask == mask { var in string @@ -1126,22 +1125,22 @@ func (p *processor) checkMissing(string) error { } else { in = "not in" // Which file is missing entries? - mistake = append(mistake, mask.String()) + mistake.Add(mask) } where = append(where, in+" "+mask.String()) } } // List error in all appropriate categories - if slices.Contains(mistake, "ROLIE") { + if mistake.Contains(rolieMask) { p.badROLIEFeed.error("%s %s", f, strings.Join(where, ", ")) } - if slices.Contains(mistake, "index.txt") { + if mistake.Contains(indexMask) { p.badIndices.error("%s %s", f, strings.Join(where, ", ")) } - if slices.Contains(mistake, "changes.csv") { + if mistake.Contains(changesMask) { p.badChanges.error("%s %s", f, strings.Join(where, ", ")) } - if slices.Contains(mistake, "directory listing") { + if mistake.Contains(listingMask) { p.badDirListings.error("%s %s", f, strings.Join(where, ", ")) } // reset mistake From 8d51577e499b4560ff548866a3f3a3c7afaf4280 Mon Sep 17 00:00:00 2001 From: JanHoefelmeyer Date: Wed, 23 Aug 2023 12:58:40 +0200 Subject: [PATCH 3/5] Use whereType for mistake --- cmd/csaf_checker/processor.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/csaf_checker/processor.go b/cmd/csaf_checker/processor.go index 0b976f6..ef9cbdd 100644 --- a/cmd/csaf_checker/processor.go +++ b/cmd/csaf_checker/processor.go @@ -1116,7 +1116,7 @@ func (p *processor) checkMissing(string) error { v := p.alreadyChecked[f] var where []string // mistake contains which requirements are broken - mistake := util.Set[whereType]{} + var mistake whereType for mask := rolieMask; mask <= listingMask; mask <<= 1 { if maxMask&mask == mask { var in string @@ -1125,26 +1125,29 @@ func (p *processor) checkMissing(string) error { } else { in = "not in" // Which file is missing entries? - mistake.Add(mask) + mistake |= mask } where = append(where, in+" "+mask.String()) } } // List error in all appropriate categories - if mistake.Contains(rolieMask) { + if mistake&rolieMask != 0 { p.badROLIEFeed.error("%s %s", f, strings.Join(where, ", ")) } - if mistake.Contains(indexMask) { + if mistake&indexMask != 0 { p.badIndices.error("%s %s", f, strings.Join(where, ", ")) } - if mistake.Contains(changesMask) { + if mistake&changesMask != 0 { p.badChanges.error("%s %s", f, strings.Join(where, ", ")) } - if mistake.Contains(listingMask) { + if mistake&listingMask != 0 { p.badDirListings.error("%s %s", f, strings.Join(where, ", ")) } // reset mistake - mistake = nil + mistake &= rolieMask + mistake &= indexMask + mistake &= changesMask + mistake &= listingMask } return nil } From 12815430ec7f4bd8628b3ffd6a544958834be0cf Mon Sep 17 00:00:00 2001 From: JanHoefelmeyer Date: Wed, 23 Aug 2023 13:22:28 +0200 Subject: [PATCH 4/5] Remove superflous reset of temporary variable --- cmd/csaf_checker/processor.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cmd/csaf_checker/processor.go b/cmd/csaf_checker/processor.go index ef9cbdd..b4fc79b 100644 --- a/cmd/csaf_checker/processor.go +++ b/cmd/csaf_checker/processor.go @@ -1143,11 +1143,6 @@ func (p *processor) checkMissing(string) error { if mistake&listingMask != 0 { p.badDirListings.error("%s %s", f, strings.Join(where, ", ")) } - // reset mistake - mistake &= rolieMask - mistake &= indexMask - mistake &= changesMask - mistake &= listingMask } return nil } From 4dfa2dd552a5cbbaaf028b4709aff068a3c8cb76 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Wed, 23 Aug 2023 17:14:49 +0200 Subject: [PATCH 5/5] Dedup code a bit --- cmd/csaf_checker/processor.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd/csaf_checker/processor.go b/cmd/csaf_checker/processor.go index b4fc79b..5c1ea61 100644 --- a/cmd/csaf_checker/processor.go +++ b/cmd/csaf_checker/processor.go @@ -1131,18 +1131,19 @@ func (p *processor) checkMissing(string) error { } } // List error in all appropriate categories - if mistake&rolieMask != 0 { - p.badROLIEFeed.error("%s %s", f, strings.Join(where, ", ")) + if mistake&(rolieMask|indexMask|changesMask|listingMask) == 0 { + continue } - if mistake&indexMask != 0 { - p.badIndices.error("%s %s", f, strings.Join(where, ", ")) - } - if mistake&changesMask != 0 { - p.badChanges.error("%s %s", f, strings.Join(where, ", ")) - } - if mistake&listingMask != 0 { - p.badDirListings.error("%s %s", f, strings.Join(where, ", ")) + joined := strings.Join(where, ", ") + report := func(mask whereType, msgs *topicMessages) { + if mistake&mask != 0 { + msgs.error("%s %s", f, joined) + } } + report(rolieMask, &p.badROLIEFeed) + report(indexMask, &p.badIndices) + report(changesMask, &p.badChanges) + report(listingMask, &p.badDirListings) } return nil }