Skip to content

Commit 3d19e41

Browse files
Replace the usage of go-homedir with os.UserHomeDir() (#1521)
* Replace the usage of go-homedir with os.UserHomeDir() Ref: mitchellh/go-homedir#34 * Implement UserHomeDir() based on the archived go-homedir package * chore(cli): address ci linting issue --------- Co-authored-by: Pascal Breuninger <pascal.breuninger@loft.sh>
1 parent dd3c94d commit 3d19e41

File tree

18 files changed

+184
-30
lines changed

18 files changed

+184
-30
lines changed

cmd/agent/workspace/up.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/loft-sh/devpod/pkg/dockercredentials"
2525
"github.com/loft-sh/devpod/pkg/extract"
2626
provider2 "github.com/loft-sh/devpod/pkg/provider"
27+
"github.com/loft-sh/devpod/pkg/util"
2728
"github.com/loft-sh/devpod/scripts"
2829
"github.com/loft-sh/log"
2930
"github.com/pkg/errors"
@@ -451,7 +452,7 @@ func configureDockerDaemon(ctx context.Context, log log.Logger) (err error) {
451452
}
452453
}`)
453454
// Check rootless docker
454-
homeDir, err := os.UserHomeDir()
455+
homeDir, err := util.UserHomeDir()
455456
if err != nil {
456457
return err
457458
}

cmd/pro/start.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/denisbrodbeck/machineid"
2222
jsonpatch "github.com/evanphx/json-patch"
2323
"github.com/mgutz/ansi"
24-
"github.com/mitchellh/go-homedir"
2524
"github.com/skratchdot/open-golang/open"
2625

2726
storagev1 "github.com/loft-sh/api/v4/pkg/apis/storage/v1"
@@ -30,6 +29,7 @@ import (
3029
proflags "github.com/loft-sh/devpod/cmd/pro/flags"
3130
"github.com/loft-sh/devpod/pkg/platform"
3231
"github.com/loft-sh/devpod/pkg/platform/client"
32+
"github.com/loft-sh/devpod/pkg/util"
3333
"github.com/loft-sh/log"
3434
"github.com/loft-sh/log/hash"
3535
"github.com/loft-sh/log/scanner"
@@ -1693,7 +1693,7 @@ func getMachineUID(log log.Logger) string {
16931693
}
16941694
// get $HOME to distinguish two users on the same machine
16951695
// will be hashed later together with the ID
1696-
home, err := homedir.Dir()
1696+
home, err := util.UserHomeDir()
16971697
if err != nil {
16981698
home = "error"
16991699
if log != nil {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ require (
2929
github.com/loft-sh/ssh v0.0.5
3030
github.com/mattn/go-isatty v0.0.20
3131
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
32-
github.com/mitchellh/go-homedir v1.1.0
3332
github.com/moby/buildkit v0.18.0
3433
github.com/onsi/ginkgo/v2 v2.20.2
3534
github.com/onsi/gomega v1.34.2
@@ -160,6 +159,7 @@ require (
160159
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
161160
github.com/mailru/easyjson v0.7.7 // indirect
162161
github.com/mattn/go-localereader v0.0.1 // indirect
162+
github.com/mitchellh/go-homedir v1.1.0 // indirect
163163
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
164164
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
165165
github.com/moby/docker-image-spec v1.3.1 // indirect

pkg/agent/workspace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
"github.com/loft-sh/devpod/pkg/git"
1616
"github.com/loft-sh/devpod/pkg/gitcredentials"
1717
provider2 "github.com/loft-sh/devpod/pkg/provider"
18+
"github.com/loft-sh/devpod/pkg/util"
1819
"github.com/loft-sh/log"
19-
"github.com/mitchellh/go-homedir"
2020
"github.com/moby/patternmatcher/ignorefile"
2121
)
2222

@@ -50,7 +50,7 @@ func findDir(agentFolder string, validate func(path string) bool) string {
5050
}
5151

5252
// check home folder first
53-
homeDir, _ := homedir.Dir()
53+
homeDir, _ := util.UserHomeDir()
5454
if homeDir != "" {
5555
homeDir = filepath.Join(homeDir, ".devpod", "agent")
5656
if validate(homeDir) {

pkg/command/user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package command
33
import (
44
"os/user"
55

6-
"github.com/mitchellh/go-homedir"
6+
"github.com/loft-sh/devpod/pkg/util"
77
)
88

99
func GetHome(userName string) (string, error) {
1010
if userName == "" {
11-
return homedir.Dir()
11+
return util.UserHomeDir()
1212
}
1313

1414
u, err := user.Lookup(userName)

pkg/config/dir.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"os"
55
"path/filepath"
66

7-
homedir "github.com/mitchellh/go-homedir"
7+
"github.com/loft-sh/devpod/pkg/util"
88
)
99

1010
// Override devpod home
@@ -19,7 +19,7 @@ func GetConfigDir() (string, error) {
1919
return homeDir, nil
2020
}
2121

22-
homeDir, err := homedir.Dir()
22+
homeDir, err := util.UserHomeDir()
2323
if err != nil {
2424
return "", err
2525
}

pkg/encoding/encoding.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99

1010
"github.com/denisbrodbeck/machineid"
1111
"github.com/google/uuid"
12+
"github.com/loft-sh/devpod/pkg/util"
1213
"github.com/loft-sh/log"
13-
"github.com/mitchellh/go-homedir"
1414
)
1515

1616
const (
@@ -81,7 +81,7 @@ func GetMachineUID(log log.Logger) string {
8181
}
8282
// get $HOME to distinguish two users on the same machine
8383
// will be hashed later together with the ID
84-
home, err := homedir.Dir()
84+
home, err := util.UserHomeDir()
8585
if err != nil {
8686
home = "error"
8787
if log != nil {

pkg/ide/fleet/fleet.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616
devpodhttp "github.com/loft-sh/devpod/pkg/http"
1717
"github.com/loft-sh/devpod/pkg/ide"
1818
"github.com/loft-sh/devpod/pkg/single"
19+
"github.com/loft-sh/devpod/pkg/util"
1920
"github.com/loft-sh/log"
2021
"github.com/loft-sh/log/scanner"
21-
"github.com/mitchellh/go-homedir"
2222
"github.com/pkg/errors"
2323
)
2424

@@ -215,7 +215,7 @@ func prepareFleetServerLocation(userName string) (string, error) {
215215
if userName != "" {
216216
homeFolder, err = command.GetHome(userName)
217217
} else {
218-
homeFolder, err = homedir.Dir()
218+
homeFolder, err = util.UserHomeDir()
219219
}
220220
if err != nil {
221221
return "", err

pkg/ide/jetbrains/generic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
"github.com/loft-sh/devpod/pkg/extract"
1818
devpodhttp "github.com/loft-sh/devpod/pkg/http"
1919
"github.com/loft-sh/devpod/pkg/ide"
20+
"github.com/loft-sh/devpod/pkg/util"
2021
"github.com/loft-sh/log"
21-
"github.com/mitchellh/go-homedir"
2222
"github.com/pkg/errors"
2323
"github.com/skratchdot/open-golang/open"
2424
)
@@ -134,7 +134,7 @@ func getBaseFolder(userName string) (string, error) {
134134
if userName != "" {
135135
homeFolder, err = command.GetHome(userName)
136136
} else {
137-
homeFolder, err = homedir.Dir()
137+
homeFolder, err = util.UserHomeDir()
138138
}
139139
if err != nil {
140140
return "", err

pkg/ide/openvscode/openvscode.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"github.com/loft-sh/devpod/pkg/ide"
1717
"github.com/loft-sh/devpod/pkg/ide/vscode"
1818
"github.com/loft-sh/devpod/pkg/single"
19+
"github.com/loft-sh/devpod/pkg/util"
1920
"github.com/loft-sh/log"
20-
"github.com/mitchellh/go-homedir"
2121
"github.com/pkg/errors"
2222
"github.com/sirupsen/logrus"
2323
)
@@ -280,7 +280,7 @@ func prepareOpenVSCodeServerLocation(userName string) (string, error) {
280280
if userName != "" {
281281
homeFolder, err = command.GetHome(userName)
282282
} else {
283-
homeFolder, err = homedir.Dir()
283+
homeFolder, err = util.UserHomeDir()
284284
}
285285
if err != nil {
286286
return "", err

0 commit comments

Comments
 (0)