hash

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package hash implements a concurrent file hasher used by spok to detect when task dependencies have changed.

The hasher opens, reads, hashes contents and filepath, and closes each file with a sha256 digest, these are then collected in an order independent way and summed into an overall sha256 hash sum representing the state of all the hashed files.

The fully qualified filepath is included in each files hash so if any part of this changes this will count as a change as well as any change to file contents.

Index

Constants

View Source
const ALWAYS = "ALWAYS"

ALWAYS is a constant string that is different to the string returned from the AlwaysRun hasher to be used as the cache comparison value so that a task is always re-run regardless of it's dependencies.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlwaysRun

type AlwaysRun struct{}

AlwaysRun is a Hasher that always returns a constant value for the final digest: "DIFFERENT", it is used primarily when forcing tasks to re-run regardless of the state of their dependencies e.g. (spok <tasks...> --force).

func (AlwaysRun) Hash

func (a AlwaysRun) Hash(_ []string) (string, error)

Hash implements Hasher for AlwaysRun and returns the constant string "DIFFERENT" in place of an actual hash digest. Comparing the return of this method to the "ALWAYS" constant will result in the digests never matching and therefore tasks that use this will always run regardless of the state of their dependencies.

type Concurrent

type Concurrent struct{}

Concurrent is primary file hasher used by spok.

func New

func New() Concurrent

New creates and returns a new file hasher.

func (Concurrent) Hash

func (c Concurrent) Hash(files []string) (string, error)

Hash takes a list of absolute filepaths to hash contents and paths for, these are then hashed and combined into an SHA256 digest which is returned as a hex encoded string along with any errors encountered.

type Hasher

type Hasher interface {
	// Hash takes a list of filepaths and returns a hash digest.
	Hash(files []string) (string, error)
}

Hasher is the interface representing something capable of hashing a number of files into a final digest.

Jump to

Keyboard shortcuts

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