From 0b5d0eb92c5be2f0ddb2fa73990f31e5654e57fe Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Mon, 14 Sep 2026 15:16:55 +0200 Subject: krino: 0.0.5 — keyword cache, t and d in review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/extract/extract.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'internal/extract/extract.go') 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 { -- cgit v1.3