Protect against panic in finding go executable and finding resources (#5548)
Fixes: #5131 Fixes: #5016
This commit is contained in:
parent
af9f636eef
commit
64577f5b10
|
@ -79,9 +79,12 @@ func UnprotectResource(_ *deploy.Snapshot, res *resource.State) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// LocateResource returns all resources in the given shapshot that have the given URN.
|
||||
// LocateResource returns all resources in the given snapshot that have the given URN.
|
||||
func LocateResource(snap *deploy.Snapshot, urn resource.URN) []*resource.State {
|
||||
contract.Require(snap != nil, "snap")
|
||||
// If there is no snapshot then return no resources
|
||||
if snap == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var resources []*resource.State
|
||||
for _, res := range snap.Resources {
|
||||
|
|
|
@ -35,7 +35,13 @@ func FindExecutable(program string) (string, error) {
|
|||
// look in $GOPATH/bin
|
||||
if goPath := os.Getenv("GOPATH"); len(goPath) > 0 {
|
||||
goPathProgram := filepath.Join(goPath, "bin", program)
|
||||
if fileInfo, err := os.Stat(goPathProgram); !os.IsNotExist(err) && !fileInfo.Mode().IsDir() {
|
||||
fileInfo, err := os.Stat(goPathProgram)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return "", errors.Wrapf(err, "unable to find program in %q", goPathProgram)
|
||||
}
|
||||
}
|
||||
if fileInfo != nil && !fileInfo.Mode().IsDir() {
|
||||
logging.V(5).Infof("program %s found in $GOPATH/bin", program)
|
||||
return goPathProgram, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue