github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/service/common/shell.go (about)

     1  // Copyright 2019 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package common
     5  
     6  import (
     7  	"os"
     8  	"os/exec"
     9  
    10  	"github.com/juju/errors"
    11  )
    12  
    13  // IsCmdNotFoundErr returns true if the provided error indicates that the
    14  // command passed to exec.LookPath or exec.Command was not found.
    15  func IsCmdNotFoundErr(err error) bool {
    16  	err = errors.Cause(err)
    17  	if os.IsNotExist(err) {
    18  		// Executable could not be found, go 1.3 and later
    19  		return true
    20  	}
    21  	if err == exec.ErrNotFound {
    22  		return true
    23  	}
    24  	if execErr, ok := err.(*exec.Error); ok {
    25  		// Executable could not be found, go 1.2
    26  		if os.IsNotExist(execErr.Err) || execErr.Err == exec.ErrNotFound {
    27  			return true
    28  		}
    29  	}
    30  	return false
    31  }