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 ¶
- type Cache
- func (c *Cache) GetBinaryControl(relPath string) (deb.Stanza, error)
- func (c *Cache) GetChecksums(relPath string) (utils.ChecksumInfo, error)
- func (c *Cache) ParseBinary(relPath string) (*deb.Package, error)
- func (c *Cache) ParseSource(relPath string, verifier *debext.Verifier) (*deb.Package, error)
- func (c *Cache) StoreBinaryControl(relPath string, stanza deb.Stanza) error
- type FileChecksums
- type FileMetadata
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 ¶
New returns a Cache that mirrors trustedDir under cacheDir. Returns nil if cacheDir is empty.
func (*Cache) GetBinaryControl ¶
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 ¶
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 ¶
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 ¶
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.