cache

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package cache provides a lazily-populated, file-level cache for parsed package data.

Cache files are stored under a cache directory that mirrors the structure of the trusted directory. For each cached source file the following sidecar files may exist:

  • <relpath>.metadata.yaml — inode, size and mtime_ns used for freshness checks
  • <relpath>.checksums.yaml — MD5, SHA1, SHA256, SHA512 of the file
  • <relpath>.control — YAML-serialised control stanza (binary packages only)

Freshness is determined entirely by comparing the stored inode, size and mtime_ns against a single os.Stat call — no file content is re-read just to validate the cache. Cache files are written atomically via a temporary file and rename.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache provides a lazily-populated, file-level cache rooted at cacheDir that mirrors the structure of trustedDir.

func New

func New(trustedDir, cacheDir string) *Cache

New returns a Cache that mirrors trustedDir under cacheDir. Returns nil if cacheDir is empty.

func (*Cache) GetBinaryControl

func (c *Cache) GetBinaryControl(relPath string) (deb.Stanza, error)

GetBinaryControl returns the cached control stanza for a .deb file, or nil if not cached. relPath is relative to trustedDir. The returned stanza contains pure control fields only — without Filename, Size or checksum fields, which are added by ParseBinary.

func (*Cache) GetChecksums

func (c *Cache) GetChecksums(relPath string) (utils.ChecksumInfo, error)

GetChecksums returns checksums for relPath (relative to trustedDir), loading from cache when fresh or computing and writing the cache on a miss.

func (*Cache) ParseBinary

func (c *Cache) ParseBinary(relPath string) (*deb.Package, error)

ParseBinary parses a .deb or .ddeb file at relPath (relative to trustedDir) using cached control data and checksums. On a cache miss the control data is extracted from the archive and stored for future runs.

func (*Cache) ParseSource

func (c *Cache) ParseSource(relPath string, verifier *debext.Verifier) (*deb.Package, error)

ParseSource parses a .dsc file at relPath (relative to trustedDir) and returns a source package with complete checksums for all referenced files. The .dsc is parsed and its signature verified on every call (the file is tiny). Checksums for the larger referenced source files (.orig.tar.*, .debian.tar.*, etc.) are obtained from the cache or computed on first encounter and cached for subsequent runs.

func (*Cache) StoreBinaryControl

func (c *Cache) StoreBinaryControl(relPath string, stanza deb.Stanza) error

StoreBinaryControl writes the control stanza cache for a .deb file. relPath is relative to trustedDir. Errors are non-fatal; callers may log or ignore them. The metadata.yaml is written by GetChecksums; StoreBinaryControl only writes .control.

type FileChecksums

type FileChecksums struct {
	MD5    string `yaml:"md5"`
	SHA1   string `yaml:"sha1"`
	SHA256 string `yaml:"sha256"`
	SHA512 string `yaml:"sha512"`
}

FileChecksums stores all checksums of a file.

type FileMetadata

type FileMetadata struct {
	Inode   uint64 `yaml:"inode"`
	Size    int64  `yaml:"size"`
	MtimeNs int64  `yaml:"mtime_ns"`
}

FileMetadata stores stat information used to determine whether a cache entry is still fresh.

Jump to

Keyboard shortcuts

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