aboutsummaryrefslogtreecommitdiff
path: root/internal/engine/facts.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/engine/facts.go')
-rw-r--r--internal/engine/facts.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/internal/engine/facts.go b/internal/engine/facts.go
index ccdf18d..c510b20 100644
--- a/internal/engine/facts.go
+++ b/internal/engine/facts.go
@@ -118,6 +118,7 @@ type facts struct {
contentDone bool // extraction was attempted
contentErr error // why it failed
+ partialErr error // extract.ErrPartial: a keyword not found may be in the unread part
answers map[string]bool // by cond.KeywordKey, once extracted
}
@@ -171,7 +172,7 @@ func (f *facts) ContentContains(opt cond.Options, keywords []string) (int, error
return i, nil
}
}
- return -1, nil
+ return -1, f.partialErr
}
// extract reads the file's text and answers every keyword of the directory,
@@ -180,6 +181,10 @@ func (f *facts) extract(opt cond.Options, keywords []string) {
f.contentDone = true
text, err := f.run.e.Extract.Text(f.run.ctx, f.file.Path, f.file.Size, f.run.d.Settings.MaxRead)
switch {
+ case errors.Is(err, extract.ErrPartial):
+ // Partly read: the keywords found in it are answered; one not found
+ // is unknown (ContentContains), and nothing is cached (plan 11).
+ f.partialErr = err
case errors.Is(err, extract.ErrUnsupported):
// A format with no text cannot contain a keyword: every answer is
// no, with no warning, and the answers are cached like any other
@@ -203,7 +208,7 @@ func (f *facts) extract(opt cond.Options, keywords []string) {
}
f.answers[k.Key()] = strings.Contains(t, k.Norm)
}
- if id, ok := f.cacheID(); ok {
+ if id, ok := f.cacheID(); ok && f.partialErr == nil {
f.run.cache.Store(id, f.answers)
}
}