package fsutil

import (
	
	
	
	

	
)

// CurrentUser allows for unit test error injection.
var CurrentUser func() (*user.User, error) = user.Current

// GetHome finds the home directory of a specified user. When given an empty
// string, it finds the home directory of the current user.
func ( string) (string, error) {
	if  == "" {
		// Use $HOME as override if we are looking for the home of the current
		// variable.
		 := os.Getenv(env.HOME)
		if  != "" {
			return strings.TrimRight(, pathSep), nil
		}
	}

	// Look up the user.
	var  *user.User
	var  error
	if  == "" {
		,  = CurrentUser()
	} else {
		,  = user.Lookup()
	}
	if  != nil {
		return "", fmt.Errorf("can't resolve ~%s: %s", , .Error())
	}
	return strings.TrimRight(.HomeDir, "/"), nil
}