mirror of
https://github.com/containers/podman.git
synced 2025-10-19 12:12:36 +08:00
podman info: try qfile before equery
podman info takes >20s on Gentoo, because equery is s..l..o..w. qfile is much faster and, I suspect, present in most Gentoo installations, so let's try it first. And, because packageVersion() was scarily unmaintainable, refactor it. Define a simple (string) list of packaging tools to query (rpm, dpkg, ...) and iterate until we find one that works. IMPORTANT NOTE: the Debian (and, presumably, Ubuntu) query does not include version number! There is no standard way on Debian to get a package version from a file path, you can only do it via pipes of chained commands, and I have no desire to implement that. Signed-off-by: Ed Santiago <santiago@redhat.com>
This commit is contained in:

committed by
Matthew Heon

parent
870576b39e
commit
04e59f11d0
@ -153,33 +153,22 @@ func queryPackageVersion(cmdArg ...string) string {
|
||||
return strings.Trim(output, "\n")
|
||||
}
|
||||
|
||||
func equeryVersion(path string) string {
|
||||
return queryPackageVersion("/usr/bin/equery", "b", path)
|
||||
}
|
||||
|
||||
func pacmanVersion(path string) string {
|
||||
return queryPackageVersion("/usr/bin/pacman", "-Qo", path)
|
||||
}
|
||||
|
||||
func dpkgVersion(path string) string {
|
||||
return queryPackageVersion("/usr/bin/dpkg", "-S", path)
|
||||
}
|
||||
|
||||
func rpmVersion(path string) string {
|
||||
return queryPackageVersion("/usr/bin/rpm", "-q", "-f", path)
|
||||
}
|
||||
|
||||
func packageVersion(program string) string {
|
||||
if out := rpmVersion(program); out != unknownPackage {
|
||||
return out
|
||||
func packageVersion(program string) string { // program is full path
|
||||
packagers := [][]string{
|
||||
{"/usr/bin/rpm", "-q", "-f"},
|
||||
{"/usr/bin/dpkg", "-S"}, // Debian, Ubuntu
|
||||
{"/usr/bin/pacman", "-Qo"}, // Arch
|
||||
{"/usr/bin/qfile", "-qv"}, // Gentoo (quick)
|
||||
{"/usr/bin/equery", "b"}, // Gentoo (slow)
|
||||
}
|
||||
if out := dpkgVersion(program); out != unknownPackage {
|
||||
return out
|
||||
|
||||
for _, cmd := range packagers {
|
||||
cmd = append(cmd, program)
|
||||
if out := queryPackageVersion(cmd...); out != unknownPackage {
|
||||
return out
|
||||
}
|
||||
}
|
||||
if out := pacmanVersion(program); out != unknownPackage {
|
||||
return out
|
||||
}
|
||||
return equeryVersion(program)
|
||||
return unknownPackage
|
||||
}
|
||||
|
||||
func programVersion(mountProgram string) (string, error) {
|
||||
|
@ -33,12 +33,16 @@ cgroupVersion: v[12]
|
||||
expr_nvr="[a-z0-9-]\\\+-[a-z0-9.]\\\+-[a-z0-9]\\\+\."
|
||||
expr_path="/[a-z0-9\\\/.-]\\\+\\\$"
|
||||
|
||||
# FIXME: if we're ever able to get package versions on Debian,
|
||||
# add '-[0-9]' to all '*.package' queries below.
|
||||
tests="
|
||||
host.buildahVersion | [0-9.]
|
||||
host.conmon.path | $expr_path
|
||||
host.conmon.package | .*conmon.*
|
||||
host.cgroupManager | \\\(systemd\\\|cgroupfs\\\)
|
||||
host.cgroupVersion | v[12]
|
||||
host.ociRuntime.path | $expr_path
|
||||
host.ociRuntime.package | .*\\\(crun\\\|runc\\\).*
|
||||
store.configFile | $expr_path
|
||||
store.graphDriverName | [a-z0-9]\\\+\\\$
|
||||
store.graphRoot | $expr_path
|
||||
|
Reference in New Issue
Block a user