hashfile

package
v1.229.0-rc.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package hashfile computes a deterministic content+filename hash over a set of file paths, the shared hashing primitive behind pkg/runner/freshness's checksum.changed fact.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashFiles

func HashFiles(paths []string) (string, error)

HashFiles computes a deterministic hash over paths: sorted first (so input order never affects the result), then path+content streamed into one sha256 digest (the path, not just its base name, is included so both a rename and a move between directories that share a filename are detected even when content is unchanged). Each record is length-prefixed (see writeRecord) so no concatenation of two records can ever collide with a different pair of path/content values. Returns the full hex-encoded digest; callers wanting a short prefix (e.g. cache keys) can slice it.

func HashFilesAndRecords

func HashFilesAndRecords(paths []string, records []string) (string, error)

HashFilesAndRecords extends HashFiles with an additional set of opaque string records (e.g. "key=value" facts that should invalidate the digest when they change but have no file backing them); records are sorted before hashing, so callers never need to pre-sort them and the result is stable regardless of the order records are supplied in. Passing a nil or empty records slice produces a digest byte-identical to HashFiles(paths).

func HashNamedFiles

func HashNamedFiles(named map[string]string, records []string) (string, error)

HashNamedFiles computes a deterministic hash over a set of files keyed by a caller-supplied name rather than their filesystem path, so the resulting digest is independent of where the files physically live (e.g. two checkouts of the same component at different absolute paths produce identical digests); named maps each logical name to the path whose content should be read for it; names are sorted before hashing so map iteration order never affects the result. The records parameter behaves exactly as in HashFilesAndRecords.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL