diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 15:16:55 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 15:16:55 +0200 |
| commit | 0b5d0eb92c5be2f0ddb2fa73990f31e5654e57fe (patch) | |
| tree | 358e331945b8206ed4a72703e3aedfe8ea7cdcdb /internal/extract/extract.go | |
| parent | 1d3f2d1e4c59867024470d3444e12698b7ebb22e (diff) | |
| download | krino-0.0.5.tar.gz krino-0.0.5.zip | |
krino: 0.0.5 — keyword cache, t and d in reviewv0.0.5
Diffstat (limited to 'internal/extract/extract.go')
| -rw-r--r-- | internal/extract/extract.go | 26 |
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 { |
