resolve the config file from the sudo user

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2016-02-22 14:48:25 +01:00
parent 049dda3ee7
commit 51359df9fb

View file

@ -29,6 +29,19 @@ func Get() string {
return home return home
} }
// GetWithSudoUser returns the home directory of the user who called sudo (if
// available, retrieved from $SUDO_USER). It fallbacks to Get if any error occurs.
// Returned path should be used with "path/filepath" to form new paths.
func GetWithSudoUser() string {
sudoUser := os.Getenv("SUDO_USER")
if sudoUser != "" {
if user, err := user.LookupUser(sudoUser); err == nil {
return user.Home
}
}
return Get()
}
// GetShortcutString returns the string that is shortcut to user's home directory // GetShortcutString returns the string that is shortcut to user's home directory
// in the native shell of the platform running on. // in the native shell of the platform running on.
func GetShortcutString() string { func GetShortcutString() string {