aboutsummaryrefslogtreecommitdiff
path: root/internal/plan/json.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 23:47:15 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 23:47:15 +0200
commit89c1fcd8fae93a64d304251a35a65763818aa8b1 (patch)
treec695ff9c729a12eeab63d8a7743a6d789f64de27 /internal/plan/json.go
parent97c8164bc81e0a438dab92d7244485005dac4ff2 (diff)
downloadkrino-89c1fcd8fae93a64d304251a35a65763818aa8b1.tar.gz
krino-89c1fcd8fae93a64d304251a35a65763818aa8b1.zip
--json carries exclusions and matching warnings
Diffstat (limited to 'internal/plan/json.go')
-rw-r--r--internal/plan/json.go49
1 files changed, 39 insertions, 10 deletions
diff --git a/internal/plan/json.go b/internal/plan/json.go
index 0b4f1bc..04b96ac 100644
--- a/internal/plan/json.go
+++ b/internal/plan/json.go
@@ -2,7 +2,12 @@
package plan
-import "time"
+import (
+ "sort"
+ "time"
+
+ "krino/internal/scan"
+)
// jsonNote is carried in every JSON document, warning readers that the
// shape is not yet stable.
@@ -18,10 +23,14 @@ type JSON struct {
// JSONDir is one directory's plan.
type JSONDir struct {
- Name string `json:"name"`
- Root string `json:"root"`
- Files []JSONFile `json:"files"`
- Warnings []string `json:"warnings,omitempty"`
+ Name string `json:"name"`
+ Root string `json:"root"`
+ Files []JSONFile `json:"files"`
+ // Unmatched holds the files no rule matched that still raised a
+ // warning (a content test that could not read them), as the text
+ // plan's warnings list does; other unmatched files are left out.
+ Unmatched []JSONFile `json:"unmatched,omitempty"`
+ Warnings []string `json:"warnings,omitempty"`
}
// JSONFile is one file's chain.
@@ -29,8 +38,16 @@ type JSONFile struct {
Rel string `json:"rel"`
Size int64 `json:"size"`
ModTime time.Time `json:"mtime"`
+ Excluded string `json:"excluded,omitempty"` // the exclude form that set the file aside
Steps []JSONStep `json:"steps"`
- Warnings []string `json:"warnings,omitempty"`
+ Warnings []string `json:"warnings,omitempty"` // raised while matching, then while planning
+}
+
+// FileNotes is what matching found about one file besides its chain.
+type FileNotes struct {
+ File scan.File
+ Excluded string
+ Warnings []string
}
// JSONStep is one step of a chain. D14: Reason is carried because the text
@@ -69,10 +86,14 @@ func NewJSON(dirs []JSONDir) JSON {
return JSON{Version: 1, Note: jsonNote, Dirs: dirs}
}
-// NewJSONDir converts one directory's chains.
-func NewJSONDir(name, root string, chains []Chain, warnings []string) JSONDir {
+// NewJSONDir converts one directory's chains. notes are matching's findings
+// by Rel, for files with a chain and for unmatched files alike (triage 28h).
+func NewJSONDir(name, root string, chains []Chain, notes map[string]FileNotes, warnings []string) JSONDir {
files := make([]JSONFile, 0, len(chains))
+ inPlan := make(map[string]bool, len(chains))
for _, ch := range chains {
+ inPlan[ch.File.Rel] = true
+ note := notes[ch.File.Rel]
steps := make([]JSONStep, 0, len(ch.Steps))
for _, s := range ch.Steps {
steps = append(steps, JSONStep{
@@ -89,9 +110,17 @@ func NewJSONDir(name, root string, chains []Chain, warnings []string) JSONDir {
Rel: ch.File.Rel,
Size: ch.File.Size,
ModTime: ch.File.ModTime,
+ Excluded: note.Excluded,
Steps: steps,
- Warnings: ch.Warnings,
+ Warnings: append(append([]string(nil), note.Warnings...), ch.Warnings...),
})
}
- return JSONDir{Name: name, Root: root, Files: files, Warnings: warnings}
+ var unmatched []JSONFile
+ for rel, note := range notes {
+ if !inPlan[rel] && len(note.Warnings) > 0 {
+ unmatched = append(unmatched, JSONFile{Rel: rel, Size: note.File.Size, ModTime: note.File.ModTime, Steps: []JSONStep{}, Warnings: note.Warnings})
+ }
+ }
+ sort.Slice(unmatched, func(i, j int) bool { return unmatched[i].Rel < unmatched[j].Rel })
+ return JSONDir{Name: name, Root: root, Files: files, Unmatched: unmatched, Warnings: warnings}
}