Skip to content

Commit

Permalink
Check env HOME before calling user.Current() (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
҈҈҈Luiz Branco authored Nov 15, 2017
1 parent 3c33a3a commit ee15c01
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

## [0.10.1] - 2017-11-15

### Fixed

- `os/user.Current` when cgo is disabled

## [0.10.0] - 2017-11-03

### Added
Expand Down
26 changes: 19 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,11 @@ func checkPermissions(path string) error {

// RCPath returns the absolute path to the ~/.manifoldrc file
func RCPath() (string, error) {
u, err := user.Current()
home, err := UserHome()
if err != nil {
return "", err
}

if u.HomeDir == "" {
return "", ErrMissingHomeDir
}

return path.Join(u.HomeDir, rcFilename), nil
return path.Join(home, rcFilename), nil
}

// Config represents the configuration which is stored inside a ~/.manifoldrc
Expand Down Expand Up @@ -334,3 +329,20 @@ func isSystemRoot(path string) bool {

return os.PathSeparator == path[rootPathLength-1]
}

func UserHome() (string, error) {
home := os.Getenv("HOME")
if home != "" {
return home, nil
}
u, err := user.Current()
if err != nil {
return "", err
}

if u.HomeDir == "" {
return "", ErrMissingHomeDir
}

return u.HomeDir, nil
}
13 changes: 2 additions & 11 deletions plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/url"
"os"
"os/exec"
"os/user"
"path"
"runtime"
"strings"
Expand All @@ -27,24 +26,16 @@ const (
// ErrFailedToRead is returned when you the plugins directory cannot be read
var ErrFailedToRead = errors.New("Failed to read plugins directory")

// ErrMissingHomeDir represents an error when a home directory could not be found
var ErrMissingHomeDir = errors.New("Could not find Home Directory")

// ErrBadPluginRepository represents an error when the plugin url is invalidu
var ErrBadPluginRepository = errors.New("Invalid repository URL")

// Path returns the plugin directory's path
func Path() (string, error) {
u, err := user.Current()
home, err := config.UserHome()
if err != nil {
return "", err
}

if u.HomeDir == "" {
return "", ErrMissingHomeDir
}

return path.Join(u.HomeDir, directory), nil
return path.Join(home, directory), nil
}

// Executable returns the executable path
Expand Down

0 comments on commit ee15c01

Please sign in to comment.