aptcache

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package aptcache provides a pure-Go reader for apt and dpkg metadata files.

It parses /var/lib/apt/lists/*_Packages (apt package index) and /var/lib/dpkg/status (installed package database) using the deb822 (RFC 822-like) plain-text format, building an in-memory index so that callers can perform O(1) lookups instead of spawning one apt-cache/dpkg subprocess per package.

Typical usage in a cross-compilation context:

cache := aptcache.Load()
info, ok := cache.Lookup("libssl-dev")
if ok && info.ArchitectureAll() { ... }

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 is an in-memory index of package metadata keyed by package name. It merges data from the apt package index and the dpkg status database. The zero value is not usable; call Load.

func Load

func Load() *Cache

Load returns the process-global Cache, loading it on the first call. Subsequent calls return the cached result immediately. The cache is always non-nil; on non-Debian hosts it is simply empty.

func Reload

func Reload() *Cache

Reload discards the cached result and re-reads the apt/dpkg metadata from disk. Call this after running apt-get update so that packages from newly added repositories are visible to subsequent Lookup calls.

func (*Cache) Lookup

func (c *Cache) Lookup(name string) (PackageInfo, bool)

Lookup returns the PackageInfo for the named package and whether it was found. The name must be the bare package name without version constraints or arch qualifiers.

func (*Cache) ResolveVirtual

func (c *Cache) ResolveVirtual(name string) string

ResolveVirtual returns the first concrete provider of a virtual package, or the original name if the package is real (has a candidate) or unknown. This replaces the `apt-cache policy` + `apt-cache showpkg` two-step.

type PackageInfo

type PackageInfo struct {
	// Architecture is the value of the Architecture field (e.g. "amd64", "all", "arm64").
	Architecture string
	// Essential is true when the package carries "Essential: yes".
	Essential bool
	// MultiArch is the value of the Multi-Arch field ("same", "foreign", "allowed", or "").
	MultiArch string
	// Installed is true when the dpkg status database reports the package as
	// "install ok installed".
	Installed bool
	// HasCandidate is true when the package has at least one version in the apt index
	// (i.e. it is a real, installable package — not a pure virtual).
	HasCandidate bool
}

PackageInfo holds the subset of deb822 fields needed for cross-compilation partition decisions and virtual package resolution.

func (PackageInfo) ArchitectureAll

func (p PackageInfo) ArchitectureAll() bool

ArchitectureAll reports whether the package is architecture-independent.

func (PackageInfo) MultiArchForeign

func (p PackageInfo) MultiArchForeign() bool

MultiArchForeign reports whether a single host-arch copy of this package satisfies dependencies from any architecture (Multi-Arch: foreign or allowed). These are tools and daemons that run on the build host — they must NOT be qualified with a target arch during cross-compilation.

Multi-Arch: same (dev libraries) is intentionally excluded: those packages must be installed separately for each architecture.

func (PackageInfo) MultiArchSame

func (p PackageInfo) MultiArchSame() bool

MultiArchSame reports whether this package must be installed separately for each architecture (Multi-Arch: same). These are typically -dev libraries that need to be qualified with the target arch during cross-compilation.

Jump to

Keyboard shortcuts

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