You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.5 KiB
1.5 KiB
Checking if a Package is Provided by Another Package
Using FindDBSatisfier
The FindDBSatisfier method in the handle finds a package that satisfies a given dependency string across sync databases. It automatically resolves Provides relationships.
Basic Usage
// Given a package name "foo", find which package provides it
h := dyalpm.NewHandle(...)
dbs := h.SyncDBS()
// This finds ANY package that satisfies "foo" - including via Provides
provider := h.FindDBSatisfier(dbs, "foo")
if provider != nil {
// The package "foo" is provided by provider.Name()
}
How It Works
When you search for a package "foo", ALPM will find packages that:
- Are named "foo"
- Have
Provides: fooin their metadata
Full Example
h, err := dyalpm.NewHandle(rootDir, cacheDir, dyalpm.ArchLinux)
if err != nil {
// handle error
}
syncDBs, err := h.SyncDBS()
if err != nil {
// handle error
}
// Search for "foo" package (may be provided by another package)
targetName := "foo"
provider := h.FindDBSatisfier(syncDBs, targetName)
if provider != nil {
fmt.Printf("%s is provided by: %s\n", targetName, provider.Name())
fmt.Printf("Version: %s\n", provider.Version())
} else {
fmt.Printf("No package found providing: %s\n", targetName)
}
Related Functions
FindSatisfier(pkgs []Package, depstring)- Same concept but for an in-memory package listPackageIterator.FindSatisfier(depstring)- Works on iterator results fromdb.Search()pkg.Provides() []Depend- Get what a package provides (seepackage.go:144)