filehash

package
v0.22.5 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeFileHash

func ComputeFileHash(file *os.File) (string, error)

ComputeFileHashAtPath attempts to calculate the sha256 hash of a file (the file must already be opened).

func ComputeFileHashAtPath

func ComputeFileHashAtPath(path string) (string, error)

ComputeFileHashAtPath attempts to open a file at a path and calculate its sha256 hash.

func WithDevice

func WithDevice(device uint32) func(*Key)

WithDevice adds a device to the key.

func WithDigest

func WithDigest(digest string) func(*Key)

With digest associates the key to a specific container digest, or to host.

func WithInode

func WithInode(ino uint64, ctime int64) func(*Key)

WithInode adds inode information to the key.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache(mode config.CalcHashesOption, resolver pathResolver) (*Cache, error)

NewCache creates a new cache for storing sha256 hashes with associated files. In order to meet multiple performance and correctness needs, the cache can operate in multiple modes.

  • inode: recalculates the file hash if the inode's creation time (ctime) differs. The option is performant, but not necessarily correct.
  • dev-inode: generally offers better performance compared to the inode option, as it bypasses the need for recalculation by associating the creation time (ctime) with the device (dev) and inode pair. It's recommended if correctnes is preferred over performance without container enrichment.
  • digest-inode: is the most efficient, as it keys the hash to a pair consisting of the container image digest and inode. This approach, however, necessitates container enrichment.

func (*Cache) Get

func (c *Cache) Get(k *Key) (string, error)

Get returns a hash from the cache. It attempts to retrieve info from the key based on the mode initially given to the cache.

type Key

type Key struct {
	// contains filtered or unexported fields
}

func NewKey

func NewKey(filepath string, mountNS int, opts ...func(*Key)) Key

NewKey creates a base key for usage with the file hash cache. It requires a filepath and mountns for the key as base information. Further information must be added through options.

func (*Key) DeviceKey

func (k *Key) DeviceKey() string

DeviceKey returns a string key for the file's device and inode. Format is "device:ctime:inode".

func (*Key) DigestKey

func (k *Key) DigestKey() string

DigestKey returns a string key based on the file container origin(digest or host), and it's inode key. Format is "digest:ctime:inode".

func (*Key) InodeKey

func (k *Key) InodeKey() string

InodeKey returns a string key based on the file inode Format is "ctime:inode"

func (*Key) MountNS

func (k *Key) MountNS() int

Pathname returns the file's mount namespace associated to the key.

func (*Key) Pathname

func (k *Key) Pathname() string

Pathname returns the file's pathname associated to the key.

Jump to

Keyboard shortcuts

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