Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ func FullProfilePath(dir string) string {
// defaultProfilePath retrieves the default path of the TSH profile.
func defaultProfilePath() string {
home := os.TempDir()
if u, err := user.Current(); err == nil && u.HomeDir != "" {
home = u.HomeDir
if dirname, err := os.UserHomeDir(); err == nil && dirname != "" {
home = dirname
}
return filepath.Join(home, profileDir)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/client/db/mysql/optionfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ type OptionFile struct {
// Load loads MySQL option file from the default location.
func Load() (*OptionFile, error) {
// Default location is .my.cnf file in the user's home directory.
user, err := user.Current()
homeDir, err := os.UserHomeDir()
if err != nil {
return nil, trace.ConvertSystemError(err)
}
return LoadFromPath(filepath.Join(user.HomeDir, mysqlOptionFile))
return LoadFromPath(filepath.Join(homeDir, mysqlOptionFile))
}

// LoadFromPath loads MySQL option file from the specified path.
Expand Down
4 changes: 2 additions & 2 deletions lib/client/db/postgres/servicefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ type ServiceFile struct {
func Load() (*ServiceFile, error) {
// Default location is .pg_service.conf file in the user's home directory.
// TODO(r0mant): Check PGSERVICEFILE and PGSYSCONFDIR env vars as well.
user, err := user.Current()
homeDir, err := os.UserHomeDir()
if err != nil {
return nil, trace.ConvertSystemError(err)
}
return LoadFromPath(filepath.Join(user.HomeDir, pgServiceFile))
return LoadFromPath(filepath.Join(homeDir, pgServiceFile))
}

// LoadFromPath loads Posrtgres connection service file from the specified path.
Expand Down
11 changes: 8 additions & 3 deletions tool/teleport/common/teleport.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,25 +549,30 @@ func onSCP(scpFlags *scp.Flags) (err error) {
}

// get user's home dir (it serves as a default destination)
user, err := user.Current()
userHomeDir, err := os.UserHomeDir()
if err != nil {
return trace.Wrap(err)
}

// see if the target is absolute. if not, use user's homedir to make
// it absolute (and if the user doesn't have a homedir, use "/")
target := scpFlags.Target[0]
if !filepath.IsAbs(target) {
if !utils.IsDir(user.HomeDir) {
if !utils.IsDir(userHomeDir) {
slash := string(filepath.Separator)
scpFlags.Target[0] = slash + target
} else {
scpFlags.Target[0] = filepath.Join(user.HomeDir, target)
scpFlags.Target[0] = filepath.Join(userHomeDir, target)
}
}
if !scpFlags.Source && !scpFlags.Sink {
return trace.Errorf("remote mode is not supported")
}

user, err := user.Current()
if err != nil {
return trace.Wrap(err)
}
scpCfg := scp.Config{
Flags: *scpFlags,
User: user.Username,
Expand Down