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 ¶
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.
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.
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.
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 ¶
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 ¶
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 ¶
IsInstalled reports whether the named package is registered in the RPM DB.
func (*DB) ListInstalled ¶
ListInstalled returns all installed package names. Useful for bulk diffs.
func (*DB) ListInstalledProvides ¶
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
OpenLegacy returns a LegacyDB if a BerkeleyDB Packages database exists at a known path, or ErrNoBDB.
func OpenLegacyAt ¶ added in v2.3.3
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
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
ListInstalled returns all installed package names.
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 ¶
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.