rpmdb

package
v2.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package rpmdb reads the RPM SQLite database used by Fedora 33+, RHEL 9+, Rocky 9+, AlmaLinux 9+, and openSUSE 15.5+.

Open caches one read-only handle for the lifetime of the process and answers installed-package queries via indexed lookups. Legacy BerkeleyDB-based hosts (RHEL 8 and earlier) return ErrLegacyDB; the caller is expected to fall back to `rpm -q`.

Index

Constants

This section is empty.

Variables

View Source
var ErrLegacyDB = errors.New("rpmdb: no SQLite RPM database found (legacy BDB host?)")

ErrLegacyDB is returned when no SQLite database exists at any known path. The caller should fall back to subprocess (rpm -q) for legacy BDB hosts.

View Source
var ErrNoBDB = errors.New("rpmdb: no BerkeleyDB RPM database found")

ErrNoBDB is returned by OpenLegacy when no BerkeleyDB RPM database exists at any known path.

View Source
var ErrPopulated = errors.New("rpmdb: database already populated")

ErrPopulated is returned when attempting to write to a database that already contains installed packages. Only fresh databases are supported in v1.

View Source
var ErrSchemaMismatch = errors.New("rpmdb: schema mismatch")

ErrSchemaMismatch is returned when the database schema doesn't match the expected Fedora rpmdb schema.

Functions

func Close

func Close() error

Close drops the cached DB handle. Tests use this to force a reopen. Production code rarely needs to call Close — the OS will release the FD on exit — but a long-running daemon that detects an rpm DB rotation can invoke Close to force the next Open to re-stat the disk.

Types

type DB

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

DB wraps a read-only handle to the RPM SQLite database. Safe for concurrent use.

func Open

func Open() (*DB, error)

Open returns a process-wide DB handle. The DB is opened in read-only mode and cached. Returns ErrLegacyDB when no SQLite database exists at any known path.

Unlike sync.Once-based singletons, this implementation re-attempts the open on every call when no cached handle is currently valid. A previous "no DB found" result therefore won't poison the process after the host runs `rpm --rebuilddb` and the SQLite file finally appears.

func (*DB) FilterInstalled

func (d *DB) FilterInstalled(ctx context.Context, names []string) []string

FilterInstalled returns the subset of names that are NOT installed. Single DB-open, N indexed queries, much faster than spawning N subprocesses.

func (*DB) IsInstalled

func (d *DB) IsInstalled(ctx context.Context, name string) (bool, error)

IsInstalled reports whether the named package is registered in the RPM DB.

func (*DB) ListInstalled

func (d *DB) ListInstalled(ctx context.Context) ([]string, error)

ListInstalled returns all installed package names. Useful for bulk diffs.

func (*DB) ListInstalledProvides

func (d *DB) ListInstalledProvides(
	ctx context.Context,
) ([]string, error)

ListInstalledProvides returns the set of capabilities (Provides) currently satisfied by installed packages. Includes virtual package names like "coreutils" provided by "coreutils-single" on minimal images.

type InstalledFile

type InstalledFile struct {
	// Path is the absolute path on disk (e.g., "/usr/bin/foo").
	Path string
	// Size is the file size in bytes.
	Size int64
	// Mode is the POSIX file mode (permissions + type bits).
	Mode uint32
	// SHA256 is the file digest in hex format (for digest algo 8).
	SHA256 string
	// LinkTarget is the symlink target if this is a symlink, empty otherwise.
	LinkTarget string
	// User is the file owner username.
	User string
	// Group is the file owner group name.
	Group string
	// MTime is the file modification time.
	MTime time.Time
	// Flags is the RPMFILE_* bitmask (config, doc, ghost, etc.).
	Flags uint32
}

InstalledFile represents a file installed by an RPM package. Used by the Writer to record file metadata in the rpmdb.

type LegacyDB added in v2.3.3

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

LegacyDB reads the BerkeleyDB-format RPM database natively via a pure-Go BDB hash reader — no `rpm` subprocess. It complements DB (the SQLite reader) on hosts that return ErrLegacyDB from Open.

Unlike DB there is no process-wide cache: the BDB file is scanned sequentially per query, which is fine for the install-time call sites (one scan per resolution pass).

func OpenLegacy added in v2.3.3

func OpenLegacy() (*LegacyDB, error)

OpenLegacy returns a LegacyDB if a BerkeleyDB Packages database exists at a known path, or ErrNoBDB.

func OpenLegacyAt added in v2.3.3

func OpenLegacyAt(path string) (*LegacyDB, error)

OpenLegacyAt returns a LegacyDB reading the BerkeleyDB Packages database at an explicit path. Used by tests and tooling; production code goes through OpenLegacy's path discovery.

func (*LegacyDB) FilterInstalled added in v2.3.3

func (d *LegacyDB) FilterInstalled(ctx context.Context, names []string) ([]string, error)

FilterInstalled returns the subset of names that are NOT installed. One sequential DB scan regardless of len(names).

func (*LegacyDB) ListInstalled added in v2.3.3

func (d *LegacyDB) ListInstalled(ctx context.Context) ([]string, error)

ListInstalled returns all installed package names.

func (*LegacyDB) ListInstalledProvides added in v2.3.3

func (d *LegacyDB) ListInstalledProvides(ctx context.Context) ([]string, error)

ListInstalledProvides returns the capabilities (Provides) of all installed packages, including each package's own name.

type Writer

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

Writer extends the rpmdb with insert support for Fedora 38+/RHEL 9+/openSUSE. It is NOT safe for concurrent use; callers must serialize access.

func OpenWriter

func OpenWriter(ctx context.Context, dbPath string) (*Writer, error)

OpenWriter opens a writable handle to the RPM SQLite database at dbPath. It validates the schema and ensures the database is empty (no pre-existing packages). Returns ErrSchemaMismatch if the schema is invalid, ErrPopulated if packages already exist, or a wrapped error for other issues.

The caller must call Close() to release the database handle.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the database handle.

func (*Writer) Install

func (w *Writer) Install(ctx context.Context, rpm *rpmutils.Rpm, files []InstalledFile) error

Install inserts an installed-package record from a parsed *rpmutils.Rpm and the list of files actually placed on disk by the extractor.

The operation is atomic: either all tables are updated or none are. Returns a wrapped error if the operation fails.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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