commit f4e3d78e516f889a0256c6ddf922922ec12bc757 Author: Minghe Huang <h.minghe@gmail.com> Date: Wed Dec 18 21:02:43 2019 +0800 check error when walk directory Signed-off-by: Minghe Huang <h.minghe@gmail.com>
28 lines
489 B
Go
28 lines
489 B
Go
package utils
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// HasDockerfile check if there is Dockerfile in dir
|
|
func HasDockerfile(dir string) bool {
|
|
var dockerfile string
|
|
if err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// nolint
|
|
if info.Mode().IsRegular() && info.Name() == "Dockerfile" {
|
|
dockerfile = path
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
return false
|
|
}
|
|
if dockerfile == "" {
|
|
return false
|
|
}
|
|
return true
|
|
}
|