rpmdb

package
v2.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: GPL-3.0 Imports: 16 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 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 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