aboutsummaryrefslogtreecommitdiff
path: root/internal/extract/extract.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/extract/extract.go')
-rw-r--r--internal/extract/extract.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/internal/extract/extract.go b/internal/extract/extract.go
index aa3ae93..9768db1 100644
--- a/internal/extract/extract.go
+++ b/internal/extract/extract.go
@@ -7,12 +7,18 @@ package extract
import (
"context"
"errors"
+ "fmt"
"os"
"path/filepath"
"strings"
"time"
)
+// Version is the version of the text this package extracts. Bump it
+// whenever a change could make any format's text differ, so every keyword
+// cache built from the old text is discarded (Fingerprint).
+const Version = 1
+
var (
// ErrUnsupported is returned when the format carries no text krino
// knows how to extract.
@@ -111,6 +117,26 @@ func newWithPath(path string) *Extractor {
return &Extractor{tools: tools, Timeout: 30 * time.Second}
}
+// Fingerprint identifies what text this Extractor would produce: Version,
+// and each external tool found with its path, size and modification time.
+// A keyword cache built under another fingerprint is discarded, so
+// installing, removing or upgrading a tool invalidates it.
+func (e *Extractor) Fingerprint() string {
+ var b strings.Builder
+ fmt.Fprintf(&b, "v%d", Version)
+ for _, name := range toolNames {
+ p := e.tools[name]
+ if p == "" {
+ continue
+ }
+ fmt.Fprintf(&b, " %s=%s", name, p)
+ if fi, err := os.Stat(p); err == nil {
+ fmt.Fprintf(&b, ":%d:%d", fi.Size(), fi.ModTime().UnixNano())
+ }
+ }
+ return b.String()
+}
+
// Tools reports every external tool Extractor knows about, in a fixed
// order, with the path it was found at or "" if it was not found.
func (e *Extractor) Tools() []Tool {