dnfcache

package
v2.1.2 Latest Latest
Warning

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

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

Documentation

Overview

Package dnfcache is an in-memory index of DNF/YUM repository metadata.

It parses /etc/yum.repos.d/*.repo files, fetches repomd.xml from each enabled repository, downloads and parses primary.xml.gz to build a package index, and provides O(1) Lookup, transitive ResolveDeps with virtual-package (Provides) handling, and concurrent SHA256-verified downloads.

Typical use:

if err := dnfcache.Update(ctx); err != nil {
    return err
}
if err := dnfcache.Install(ctx, []string{"gcc", "make"}); err != nil {
    return err
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadRPM

func DownloadRPM(ctx context.Context, pkg *PackageInfo, destDir string) (string, error)

DownloadRPM downloads a single .rpm package to destDir, verifying SHA256 against the cached metadata. Exported wrapper around the internal helper so callers outside the package (e.g. pkg/dnfinstall) can reuse the same download path used by Install.

func Install

func Install(ctx context.Context, names []string) error

Install resolves the transitive closure of names, downloads the .rpm files, and installs them via rpm --install. This replaces "dnf install".

func StripRPMConstraint

func StripRPMConstraint(name string) string

StripRPMConstraint strips RPM version constraint suffixes from a dep name. Examples: "glibc >= 2.17" → "glibc", "libfoo(x86-64)" → "libfoo(x86-64)" (parenthesised capability names are kept as-is).

func Update

func Update(ctx context.Context) error

Update fetches fresh repomd.xml + primary.xml.gz from all enabled repos, writes them to the DNF cache directory, and reloads the in-memory index. This replaces "dnf makecache".

Types

type Cache

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

Cache is an in-memory index of RPM package metadata keyed by package name. The zero value is not usable; call Load or Update.

func Load

func Load() *Cache

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

func Reload

func Reload() *Cache

Reload discards the cached result and re-reads repo metadata from disk. Call this after Update so newly fetched indexes are visible.

func (*Cache) Lookup

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

Lookup returns the PackageInfo for the named package and whether it was found.

func (*Cache) ResolveDeps

func (c *Cache) ResolveDeps(ctx context.Context, seeds []string) ([]*PackageInfo, []string, error)

ResolveDeps performs transitive dependency resolution starting from the given seed package names. Returns packages in dependency order (deps before dependents) and a list of unresolvable names.

Already-installed packages (detected via rpmdb) are skipped but their dependency edges are still walked so transitive-only packages are pulled in.

func (*Cache) ResolveVirtual

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

ResolveVirtual returns the first concrete provider of a virtual package name (capability), or the original name if it is a real package or unknown.

type PackageInfo

type PackageInfo struct {
	// Name is the package name (e.g. "gcc", "glibc-devel").
	Name string
	// Arch is the package architecture (e.g. "x86_64", "noarch").
	Arch string
	// Version is the package version string.
	Version string
	// Release is the package release string.
	Release string
	// Epoch is the package epoch (0 if absent).
	Epoch string
	// LocationHref is the relative path of the .rpm in the repository
	// (e.g. "Packages/g/gcc-12.2.0-1.el8.x86_64.rpm").
	LocationHref string
	// SHA256 is the expected SHA-256 checksum of the .rpm file.
	SHA256 string
	// Size is the expected size of the .rpm file in bytes.
	Size int64
	// BaseURL is the repo base URL where LocationHref is relative to.
	BaseURL string
	// Requires is the list of package names this package depends on.
	Requires []string
	// Provides is the list of capabilities this package provides.
	Provides []string
}

PackageInfo holds the subset of primary.xml fields needed for dep resolution and download.

type RepoEntry

type RepoEntry struct {
	ID         string
	BaseURL    string // first baseurl= line
	MirrorList string // mirrorlist= URL (used when BaseURL is empty)
	Enabled    bool
}

RepoEntry holds a single enabled repository parsed from a .repo file.

func ParseRepoFileContent

func ParseRepoFileContent(content string) []RepoEntry

ParseRepoFileContent parses the INI-style content of a .repo file.

Jump to

Keyboard shortcuts

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