aboutsummaryrefslogtreecommitdiff
path: root/internal/cond/eval.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 21:40:12 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 21:40:12 +0200
commit360591d6e18d8676a2f86185ed42f46852387f85 (patch)
tree31043c351f6cb2c95c6b6a26d0c69dcb47ab1e3f /internal/cond/eval.go
parente0dddff176a01d410904b6750b3395de4f7e54db (diff)
downloadkrino-360591d6e18d8676a2f86185ed42f46852387f85.tar.gz
krino-360591d6e18d8676a2f86185ed42f46852387f85.zip
plan 9: content excludes fail closed; krino.conf excludes checked without directories
Diffstat (limited to 'internal/cond/eval.go')
-rw-r--r--internal/cond/eval.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/internal/cond/eval.go b/internal/cond/eval.go
index 3cec110..b0ee828 100644
--- a/internal/cond/eval.go
+++ b/internal/cond/eval.go
@@ -33,6 +33,11 @@ type Result struct {
Captures []string // submatches of the first true, non-negated name test: [0] whole match, [1:] groups
Reasons []string // what made it true, e.g. `type pdf`, `content "acme ltd"`, `name "\bacme\b"`
Warnings []string // e.g. `content unreadable: needs pdftotext, not installed`
+
+ // Unreadable is true when evaluation reached a content test that could
+ // not read the file. The test counts as false; an exclude uses this to
+ // hold anyway (review M11).
+ Unreadable bool
}
// Trace is the full evaluation of every node, for krino explain.
@@ -47,9 +52,10 @@ type Trace struct {
// first true, non-negated name test, and warnings de-duplicated in
// first-seen order.
type evalCtx struct {
- captures []string
- warned map[string]bool
- warnings []string
+ captures []string
+ warned map[string]bool
+ warnings []string
+ unreadable bool
}
// warn records msg unless it has already been recorded.
@@ -75,7 +81,7 @@ func (c *Cond) Eval(f Facts) Result {
}
ctx := &evalCtx{}
match, reasons := c.eval(c.root, f, ctx, false)
- return Result{Match: match, Captures: ctx.captures, Reasons: reasons, Warnings: ctx.warnings}
+ return Result{Match: match, Captures: ctx.captures, Reasons: reasons, Warnings: ctx.warnings, Unreadable: ctx.unreadable}
}
// eval evaluates one node against f, short-circuiting and/or in child
@@ -122,6 +128,9 @@ func (c *Cond) eval(n *node, f Facts, ctx *evalCtx, negated bool) (bool, []strin
ok, reason, warn, caps := c.evalLeaf(n, f)
if warn != "" {
ctx.warn(warn)
+ if n.kind == kContent {
+ ctx.unreadable = true
+ }
}
if !ok {
return false, nil