Skip to content
Merged
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
5 changes: 2 additions & 3 deletions components/playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
_ "net/http/pprof"
"os"
"os/signal"
"os/user"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -546,11 +545,11 @@ func getAbsolutePath(path string) (string, error) {
}

if strings.HasPrefix(path, "~/") {
usr, err := user.Current()
homedir, err := os.UserHomeDir()
if err != nil {
return "", errors.Annotatef(err, "retrieve user home failed")
}
path = filepath.Join(usr.HomeDir, path[2:])
path = filepath.Join(homedir, path[2:])
}

absPath, err := filepath.Abs(path)
Expand Down
5 changes: 2 additions & 3 deletions components/playground/playground_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package main

import (
"os"
"os/user"
"path/filepath"
"testing"

Expand All @@ -34,11 +33,11 @@ func TestPlaygroundAbsDir(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, "/b", b)

u, err := user.Current()
h, err := os.UserHomeDir()
assert.Nil(t, err)
c, err := getAbsolutePath("~/c/d/e")
assert.Nil(t, err)
assert.Equal(t, filepath.Join(u.HomeDir, "c/d/e"), c)
assert.Equal(t, filepath.Join(h, "c/d/e"), c)
}

func TestParseMysqlCommand(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions pkg/cluster/spec/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package spec

import (
"os"
"os/user"
"path"
"path/filepath"

Expand Down Expand Up @@ -43,11 +42,11 @@ var profileDir string
// getHomeDir get the home directory of current user (if they have one).
// The result path might be empty.
func getHomeDir() (string, error) {
u, err := user.Current()
homedir, err := os.UserHomeDir()
if err != nil {
return "", errors.Trace(err)
}
return u.HomeDir, nil
return homedir, nil
}

var initialized = false
Expand Down
5 changes: 2 additions & 3 deletions pkg/localdata/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"net/http"
"os"
"os/exec"
"os/user"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -54,11 +53,11 @@ func InitProfile() *Profile {
case DefaultTiUPHome != "":
profileDir = DefaultTiUPHome
default:
u, err := user.Current()
homedir, err := os.UserHomeDir()
if err != nil {
panic("cannot get current user information: " + err.Error())
}
profileDir = filepath.Join(u.HomeDir, ProfileDirName)
profileDir = filepath.Join(homedir, ProfileDirName)
}

cfg, err := InitConfig(profileDir)
Expand Down
Loading