Protect against panic in finding go executable and finding resources (#5548)

Fixes: #5131
Fixes: #5016
This commit is contained in:
Paul Stack 2020-10-11 07:13:54 +01:00 committed by GitHub
parent af9f636eef
commit 64577f5b10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View file

@ -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 {

View file

@ -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
}