diff options
Diffstat (limited to 'vendor/github.com/containers/buildah/util/util.go')
-rw-r--r-- | vendor/github.com/containers/buildah/util/util.go | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/vendor/github.com/containers/buildah/util/util.go b/vendor/github.com/containers/buildah/util/util.go index ffebd3146..6a9049e68 100644 --- a/vendor/github.com/containers/buildah/util/util.go +++ b/vendor/github.com/containers/buildah/util/util.go @@ -384,13 +384,15 @@ var ( // fileExistsAndNotADir - Check to see if a file exists // and that it is not a directory. -func fileExistsAndNotADir(path string) bool { +func fileExistsAndNotADir(path string) (bool, error) { file, err := os.Stat(path) - - if file == nil || err != nil || os.IsNotExist(err) { - return false + if err != nil { + if errors.Is(err, os.ErrNotExist) { + return false, nil + } + return false, err } - return !file.IsDir() + return !file.IsDir(), nil } // FindLocalRuntime find the local runtime of the @@ -404,7 +406,11 @@ func FindLocalRuntime(runtime string) string { return localRuntime } for _, val := range conf.Engine.OCIRuntimes[runtime] { - if fileExistsAndNotADir(val) { + exists, err := fileExistsAndNotADir(val) + if err != nil { + logrus.Errorf("Failed to determine if file exists and is not a directory: %v", err) + } + if exists { localRuntime = val break } @@ -460,22 +466,3 @@ func VerifyTagName(imageSpec string) (types.ImageReference, error) { } return ref, nil } - -// Cause returns the most underlying error for the provided one. There is a -// maximum error depth of 100 to avoid endless loops. An additional error log -// message will be created if this maximum has reached. -func Cause(err error) (cause error) { - cause = err - - const maxDepth = 100 - for i := 0; i <= maxDepth; i++ { - res := errors.Unwrap(cause) - if res == nil { - return cause - } - cause = res - } - - logrus.Errorf("Max error depth of %d reached, cannot unwrap until root cause: %v", maxDepth, err) - return cause -} |