summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2019-11-04 10:08:17 -0500
committerGitHub <noreply@github.com>2019-11-04 10:08:17 -0500
commit8e5aad97dda150f8e871c1b394824496f4b849ea (patch)
tree398ca3e287a1b7f0670afa3d280b724bc7c2f96a
parentefc7f1557b4af90263f4f07e5e576b02e839fad1 (diff)
parent677a0e5d60c45711cba56032c23783c1d010a49e (diff)
downloadpodman-8e5aad97dda150f8e871c1b394824496f4b849ea.tar.gz
podman-8e5aad97dda150f8e871c1b394824496f4b849ea.tar.bz2
podman-8e5aad97dda150f8e871c1b394824496f4b849ea.zip
Merge pull request #4389 from TomSweeneyRedHat/dev/tsweeney/contextdir
Validate contextdir on build
-rw-r--r--cmd/podman/build.go3
-rw-r--r--cmd/podman/utils.go10
2 files changed, 13 insertions, 0 deletions
diff --git a/cmd/podman/build.go b/cmd/podman/build.go
index 896d5661a..bbc1d5b5f 100644
--- a/cmd/podman/build.go
+++ b/cmd/podman/build.go
@@ -238,6 +238,9 @@ func buildCmd(c *cliconfig.BuildValues) error {
if contextDir == "" {
return errors.Errorf("no context directory specified, and no containerfile specified")
}
+ if !fileIsDir(contextDir) {
+ return errors.Errorf("context must be a directory: %v", contextDir)
+ }
if len(containerfiles) == 0 {
if checkIfFileExists(filepath.Join(contextDir, "Containerfile")) {
containerfiles = append(containerfiles, filepath.Join(contextDir, "Containerfile"))
diff --git a/cmd/podman/utils.go b/cmd/podman/utils.go
index c19e6391e..21389b43a 100644
--- a/cmd/podman/utils.go
+++ b/cmd/podman/utils.go
@@ -74,3 +74,13 @@ func checkIfFileExists(name string) bool {
}
return !file.IsDir()
}
+
+// Check if a file is or is not a directory
+func fileIsDir(name string) bool {
+ file, err := os.Stat(name)
+ // All errors return file == nil
+ if err != nil {
+ return false
+ }
+ return file.IsDir()
+}