summaryrefslogtreecommitdiff
path: root/vendor/github.com/containers/buildah/util/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/containers/buildah/util/util.go')
-rw-r--r--vendor/github.com/containers/buildah/util/util.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/vendor/github.com/containers/buildah/util/util.go b/vendor/github.com/containers/buildah/util/util.go
index ac5a0f30c..05d661b58 100644
--- a/vendor/github.com/containers/buildah/util/util.go
+++ b/vendor/github.com/containers/buildah/util/util.go
@@ -10,6 +10,7 @@ import (
"sync"
"syscall"
+ "github.com/containers/common/pkg/config"
"github.com/containers/image/v5/docker/reference"
"github.com/containers/image/v5/pkg/sysregistriesv2"
"github.com/containers/image/v5/signature"
@@ -432,3 +433,33 @@ var (
isUnified bool
isUnifiedErr error
)
+
+// fileExistsAndNotADir - Check to see if a file exists
+// and that it is not a directory.
+func fileExistsAndNotADir(path string) bool {
+ file, err := os.Stat(path)
+
+ if file == nil || err != nil || os.IsNotExist(err) {
+ return false
+ }
+ return !file.IsDir()
+}
+
+// FindLocalRuntime find the local runtime of the
+// system searching through the config file for
+// possible locations.
+func FindLocalRuntime(runtime string) string {
+ var localRuntime string
+ conf, err := config.Default()
+ if err != nil {
+ logrus.Debugf("Error loading container config when searching for local runtime.")
+ return localRuntime
+ }
+ for _, val := range conf.Libpod.OCIRuntimes[runtime] {
+ if fileExistsAndNotADir(val) {
+ localRuntime = val
+ break
+ }
+ }
+ return localRuntime
+}