diff options
author | xatier <xatierlike@gmail.com> | 2020-12-16 04:07:46 -0800 |
---|---|---|
committer | xatier <xatierlike@gmail.com> | 2020-12-16 12:38:46 -0800 |
commit | b6f5163460b7cd6ca26c49e00da99d3d8d5831e2 (patch) | |
tree | 8804cc2b442aa38712fd013e8775b37b595c6190 /libpod | |
parent | 3ac83bf611ecf54d3608255ac70fc58d40764a11 (diff) | |
download | podman-b6f5163460b7cd6ca26c49e00da99d3d8d5831e2.tar.gz podman-b6f5163460b7cd6ca26c49e00da99d3d8d5831e2.tar.bz2 podman-b6f5163460b7cd6ca26c49e00da99d3d8d5831e2.zip |
Add support for pacman package version query
- refactor package query logic to be package manager agnostic.
- `pacman -Qo` is the equivalent to `rpm -qf` [1].
[1] https://wiki.archlinux.org/index.php/Pacman/Rosetta#Querying_specific_packages
Signed-off-by: xatier <xatierlike@gmail.com>
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/util.go | 30 |
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) { |