Skip to content

Commit 4144457

Browse files
Merge pull request containers#1578 from afbjorklund/dlocate
Use dlocate where available, instead of dpkg search
2 parents 018fec6 + b9e5854 commit 4144457

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pkg/util/util.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@ func queryPackageVersion(cmdArg ...string) string {
2727
cmd := exec.Command(cmdArg[0], cmdArg[1:]...)
2828
if outp, err := cmd.Output(); err == nil {
2929
output = string(outp)
30-
if cmdArg[0] == "/usr/bin/dpkg" {
30+
deb := false
31+
if cmdArg[0] == "/usr/bin/dlocate" {
32+
// can return multiple matches
33+
l := strings.Split(output, "\n")
34+
output = l[0]
35+
deb = true
36+
} else if cmdArg[0] == "/usr/bin/dpkg" {
37+
deb = true
38+
}
39+
if deb {
3140
r := strings.Split(output, ": ")
3241
queryFormat := `${Package}_${Version}_${Architecture}`
3342
cmd = exec.Command("/usr/bin/dpkg-query", "-f", queryFormat, "-W", r[0])
@@ -47,9 +56,14 @@ func queryPackageVersion(cmdArg ...string) string {
4756
// Note: This function is copied from containers/podman libpod/util.go
4857
// Please see https://github.com/containers/common/pull/1460
4958
func PackageVersion(program string) string { // program is full path
59+
_, err := os.Stat(program)
60+
if err != nil {
61+
return UnknownPackage
62+
}
5063
packagers := [][]string{
5164
{"/usr/bin/rpm", "-q", "-f"},
52-
{"/usr/bin/dpkg", "-S"}, // Debian, Ubuntu
65+
{"/usr/bin/dlocate", "-F"}, // Debian, Ubuntu (quick)
66+
{"/usr/bin/dpkg", "-S"}, // Debian, Ubuntu (slow)
5367
{"/usr/bin/pacman", "-Qo"}, // Arch
5468
{"/usr/bin/qfile", "-qv"}, // Gentoo (quick)
5569
{"/usr/bin/equery", "b"}, // Gentoo (slow)

0 commit comments

Comments
 (0)