summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-12-16 22:28:22 +0000
committerGitHub <noreply@github.com>2020-12-16 22:28:22 +0000
commite75dc3d536a9f8f457dfc35482ff61efc80cbb09 (patch)
tree7f9b7ffa1f1e3f19445d5fe298fb11f6af67bea5 /libpod
parent2a21dcda8e949c5546c9281ca4b900910c6c42e8 (diff)
parentb6f5163460b7cd6ca26c49e00da99d3d8d5831e2 (diff)
downloadpodman-e75dc3d536a9f8f457dfc35482ff61efc80cbb09.tar.gz
podman-e75dc3d536a9f8f457dfc35482ff61efc80cbb09.tar.bz2
podman-e75dc3d536a9f8f457dfc35482ff61efc80cbb09.zip
Merge pull request #8738 from xatier/master
Add support for pacman package version query
Diffstat (limited to 'libpod')
-rw-r--r--libpod/util.go30
1 files changed, 19 insertions, 11 deletions
diff --git a/libpod/util.go b/libpod/util.go
index c26039c50..ae9ef7172 100644
--- a/libpod/util.go
+++ b/libpod/util.go
@@ -142,29 +142,37 @@ func JSONDeepCopy(from, to interface{}) error {
return json.Unmarshal(tmp, to)
}
-func dpkgVersion(path string) string {
+func queryPackageVersion(cmdArg ...string) string {
output := unknownPackage
- cmd := exec.Command("/usr/bin/dpkg", "-S", path)
- if outp, err := cmd.Output(); err == nil {
- output = string(outp)
+ if 1 < len(cmdArg) {
+ cmd := exec.Command(cmdArg[0], cmdArg[1:]...)
+ if outp, err := cmd.Output(); err == nil {
+ output = string(outp)
+ }
}
return strings.Trim(output, "\n")
}
+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 {
- output := unknownPackage
- cmd := exec.Command("/usr/bin/rpm", "-q", "-f", path)
- if outp, err := cmd.Output(); err == nil {
- output = string(outp)
- }
- return strings.Trim(output, "\n")
+ return queryPackageVersion("/usr/bin/rpm", "-q", "-f", path)
}
func packageVersion(program string) string {
if out := rpmVersion(program); out != unknownPackage {
return out
}
- return dpkgVersion(program)
+ if out := dpkgVersion(program); out != unknownPackage {
+ return out
+ }
+ return pacmanVersion(program)
}
func programVersion(mountProgram string) (string, error) {