mirror of
https://github.com/containers/podman.git
synced 2025-08-06 11:32:07 +08:00
Merge pull request #4389 from TomSweeneyRedHat/dev/tsweeney/contextdir
Validate contextdir on build
This commit is contained in:
@ -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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user