Skip to content

Commit

Permalink
Make CheckFileExists return bool instead of error
Browse files Browse the repository at this point in the history
  • Loading branch information
martina-if committed Apr 26, 2019
1 parent 4da506e commit 9b2762f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/ctl/create/utils.go
Expand Up @@ -81,7 +81,7 @@ func loadSSHKey(ng *api.NodeGroup, clusterName string, provider api.ClusterProvi
logger.Info("using EC2 key pair %q", *sshConfig.PublicKeyName)

// Local ssh key file
case utils.CheckFileExists(*sshConfig.PublicKeyPath) != nil:
case utils.CheckFileExists(*sshConfig.PublicKeyPath):
keyName, err := ssh.LoadKeyFromFile(*sshConfig.PublicKeyPath, clusterName, ng.Name, provider)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/ssh/ssh.go
Expand Up @@ -21,8 +21,8 @@ import (
// LoadKeyFromFile loads and imports a public SSH key from a file provided a path to that file.
// returns the name of the key
func LoadKeyFromFile(filePath, clusterName, ngName string, provider api.ClusterProvider) (string, error) {
if err := utils.CheckFileExists(filePath); err != nil {
return "", errors.Wrap(err, fmt.Sprintf("SSH public key file %q not found", filePath))
if !utils.CheckFileExists(filePath) {
return "", fmt.Errorf("SSH public key file %q not found", filePath)
}

expandedPath := utils.ExpandPath(filePath)
Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/file.go
Expand Up @@ -20,12 +20,12 @@ func FileExists(path string) (bool, error) {
}

// CheckFileExists returns an error if the file doesn't exist
func CheckFileExists(filePath string) error {
func CheckFileExists(filePath string) bool {
extendedPath := ExpandPath(filePath)
if _, err := os.Stat(extendedPath); os.IsNotExist(err) {
return err
return false
}
return nil
return true
}

// ExpandPath expands path with ~ notation
Expand Down

0 comments on commit 9b2762f

Please sign in to comment.