mirror of
https://github.com/containers/podman
synced 2024-10-19 16:54:07 +00:00
Merge pull request #4389 from TomSweeneyRedHat/dev/tsweeney/contextdir
Validate contextdir on build
This commit is contained in:
commit
8e5aad97dd
|
@ -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"))
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue