diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-09-06 16:45:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-06 16:45:25 +0200 |
commit | 575ffee2f05dc607d32da2d0bfd1b82f47aab8bb (patch) | |
tree | 1808f264855e5277034a2da4ac79a0bc2f278d9f /libpod/util.go | |
parent | 88980859eccacf7a5752952b4dfba6d25374ec2d (diff) | |
parent | b2b284111e49d3d953f71a794f25aa9ddfbb8568 (diff) | |
download | podman-575ffee2f05dc607d32da2d0bfd1b82f47aab8bb.tar.gz podman-575ffee2f05dc607d32da2d0bfd1b82f47aab8bb.tar.bz2 podman-575ffee2f05dc607d32da2d0bfd1b82f47aab8bb.zip |
Merge pull request #3918 from rhatdan/info
Return information about mount_program (fuse-overlayfs)
Diffstat (limited to 'libpod/util.go')
-rw-r--r-- | libpod/util.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libpod/util.go b/libpod/util.go index 164800af4..84fd490bf 100644 --- a/libpod/util.go +++ b/libpod/util.go @@ -3,6 +3,7 @@ package libpod import ( "fmt" "os" + "os/exec" "path/filepath" "sort" "strconv" @@ -10,6 +11,7 @@ import ( "time" "github.com/containers/libpod/libpod/define" + "github.com/containers/libpod/utils" "github.com/fsnotify/fsnotify" spec "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" @@ -20,6 +22,8 @@ const ( // DefaultTransport is a prefix that we apply to an image name // to check docker hub first for the image DefaultTransport = "docker://" + + unknownPackage = "Unknown" ) // FuncTimer helps measure the execution time of a function @@ -152,3 +156,36 @@ func JSONDeepCopy(from, to interface{}) error { } return json.Unmarshal(tmp, to) } + +func dpkgVersion(path string) string { + output := unknownPackage + cmd := exec.Command("/usr/bin/dpkg", "-S", path) + if outp, err := cmd.Output(); err == nil { + output = string(outp) + } + return strings.Trim(output, "\n") +} + +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") +} + +func packageVersion(program string) string { + if out := rpmVersion(program); out != unknownPackage { + return out + } + return dpkgVersion(program) +} + +func programVersion(mountProgram string) (string, error) { + output, err := utils.ExecCmd(mountProgram, "--version") + if err != nil { + return "", err + } + return strings.TrimSuffix(output, "\n"), nil +} |