Skip to content

Commit

Permalink
Change to use os.UserHomeDir(), fixes #3084 (#3313)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed Oct 18, 2021
1 parent bfedeae commit 42adca2
Show file tree
Hide file tree
Showing 64 changed files with 114 additions and 3,187 deletions.
3 changes: 1 addition & 2 deletions cmd/ddev/cmd/auth-ssh.go
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/drud/ddev/pkg/nodeps"
"github.com/drud/ddev/pkg/util"
"github.com/drud/ddev/pkg/version"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"os"
"path/filepath"
Expand All @@ -32,7 +31,7 @@ var AuthSSHCommand = &cobra.Command{
uidStr, _, _ := util.GetContainerUIDGid()

if sshKeyPath == "" {
homeDir, err := homedir.Dir()
homeDir, err := os.UserHomeDir()
if err != nil {
util.Failed("Unable to determine home directory: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/ddev/cmd/config.go
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/drud/ddev/pkg/globalconfig"
"github.com/drud/ddev/pkg/nodeps"
"github.com/mitchellh/go-homedir"
"os"
"strings"

Expand Down Expand Up @@ -167,7 +166,7 @@ func handleConfigRun(cmd *cobra.Command, args []string) {
util.Failed(err.Error())
}

homeDir, _ := homedir.Dir()
homeDir, _ := os.UserHomeDir()
if app.AppRoot == filepath.Dir(globalconfig.GetGlobalDdevDir()) || app.AppRoot == homeDir {
util.Failed("Please do not use `ddev config` in your home directory")
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/ddev/cmd/config_test.go
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/drud/ddev/pkg/fileutil"
"github.com/drud/ddev/pkg/nodeps"
"github.com/drud/ddev/pkg/version"
"github.com/mitchellh/go-homedir"
"github.com/stretchr/testify/require"
"testing"

Expand Down Expand Up @@ -378,7 +377,7 @@ func TestCmdDisasterConfig(t *testing.T) {

testDir, _ := os.Getwd()
// Make sure we're not allowed to config in home directory.
home, _ := homedir.Dir()
home, _ := os.UserHomeDir()
err = os.Chdir(home)
assert.NoError(err)
out, err := exec.RunCommand(DdevBin, []string{"config", "--project-type=php"})
Expand Down
3 changes: 1 addition & 2 deletions cmd/ddev/cmd/import_test.go
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/drud/ddev/pkg/exec"
"github.com/drud/ddev/pkg/fileutil"
gohomedir "github.com/mitchellh/go-homedir"
asrt "github.com/stretchr/testify/assert"
)

Expand All @@ -18,7 +17,7 @@ func TestImportTilde(t *testing.T) {

site := TestSites[0]

homedir, err := gohomedir.Dir()
homedir, err := os.UserHomeDir()
assert.NoError(err)
cwd, _ := os.Getwd()
testFile := filepath.Join(homedir, "testfile.tar.gz")
Expand Down
68 changes: 51 additions & 17 deletions go.mod
@@ -1,48 +1,82 @@
module github.com/drud/ddev

require (
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.1.1
github.com/Masterminds/sprig v2.15.0+incompatible
github.com/Microsoft/hcsshim v0.9.0 // indirect
github.com/aokoli/goutils v1.0.1 // indirect
github.com/cheggaaa/pb v1.0.25
github.com/containerd/cgroups v1.0.2 // indirect
github.com/containerd/continuity v0.2.0 // indirect
github.com/denisbrodbeck/machineid v1.0.1
github.com/docker/docker v20.10.8+incompatible
github.com/fsouza/go-dockerclient v1.7.4
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-github v0.0.0-20180716180158-c0b63e2f9bb1
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 // indirect
github.com/google/uuid v1.3.0
github.com/huandu/xstrings v1.0.0 // indirect
github.com/jedib0t/go-pretty/v6 v6.2.4
github.com/lextoumbourou/goodhosts v2.1.0+incompatible
github.com/lunixbochs/vtclean v1.0.0 // indirect
github.com/manifoldco/promptui v0.8.0
github.com/mattn/go-isatty v0.0.4
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1
github.com/rogpeppe/go-internal v1.3.0
github.com/segmentio/backo-go v0.0.0-20200129164019-23eae7c10bd3 // indirect
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.1.1
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.0
github.com/stretchr/testify v1.7.0
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b
golang.org/x/text v0.3.7
gopkg.in/segmentio/analytics-go.v3 v3.1.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/Microsoft/hcsshim v0.9.0 // indirect
github.com/aokoli/goutils v1.0.1 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/containerd/cgroups v1.0.2 // indirect
github.com/containerd/containerd v1.5.7 // indirect
github.com/containerd/continuity v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/xstrings v1.0.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect
github.com/lunixbochs/vtclean v1.0.0 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/moby/sys/mount v0.2.0 // indirect
github.com/moby/sys/mountinfo v0.4.1 // indirect
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/runc v1.0.2 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/segmentio/backo-go v0.0.0-20200129164019-23eae7c10bd3 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b
golang.org/x/text v0.3.7
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.26 // indirect
gopkg.in/segmentio/analytics-go.v3 v3.1.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)

go 1.16
go 1.17
4 changes: 2 additions & 2 deletions pkg/appimport/appimport.go
Expand Up @@ -9,7 +9,7 @@ import (

"path/filepath"

gohomedir "github.com/mitchellh/go-homedir"
homedir "github.com/mitchellh/go-homedir"
)

// ValidateAsset determines if a given asset matches the required criteria for a given asset type
Expand All @@ -19,7 +19,7 @@ func ValidateAsset(unexpandedAssetPath string, assetType string) (string, bool,
extensions := []string{"tar", "gz", "tgz", "zip"}

// Input provided via prompt or "--flag=value" is not expanded by shell. This will help ensure ~ is expanded to the user home directory.
assetPath, err := gohomedir.Expand(unexpandedAssetPath)
assetPath, err := homedir.Expand(unexpandedAssetPath)
if err != nil {
return "", false, fmt.Errorf(invalidAssetError, err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/appimport/appimport_test.go
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/drud/ddev/pkg/appimport"
"github.com/drud/ddev/pkg/util"
gohomedir "github.com/mitchellh/go-homedir"
asrt "github.com/stretchr/testify/assert"
)

Expand All @@ -25,7 +24,7 @@ func TestValidateAsset(t *testing.T) {
testdata := filepath.Join(cwd, "testdata")

// test tilde expansion
userDir, err := gohomedir.Dir()
userDir, err := os.UserHomeDir()
testDirName := "tmp.ddev.testpath-" + util.RandString(4)
testDir := filepath.Join(userDir, testDirName)
assert.NoError(err)
Expand Down
3 changes: 1 addition & 2 deletions pkg/ddevapp/config.go
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/Masterminds/sprig"
"github.com/drud/ddev/pkg/dockerutil"
"github.com/drud/ddev/pkg/nodeps"
"github.com/mitchellh/go-homedir"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -60,7 +59,7 @@ func NewApp(appRoot string, includeOverrides bool) (*DdevApp, error) {
app.AppRoot = appRoot
}

homeDir, _ := homedir.Dir()
homeDir, _ := os.UserHomeDir()
if appRoot == filepath.Dir(globalconfig.GetGlobalDdevDir()) || app.AppRoot == homeDir {
return nil, fmt.Errorf("ddev config is not useful in your home directory (%s)", homeDir)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/ddevapp/config_test.go
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"github.com/drud/ddev/pkg/exec"
"github.com/drud/ddev/pkg/nodeps"
"github.com/mitchellh/go-homedir"
"github.com/stretchr/testify/require"
"os"
"path/filepath"
Expand Down Expand Up @@ -72,7 +71,7 @@ func TestDisasterConfig(t *testing.T) {
pwd, _ := os.Getwd()

// Make sure we're not allowed to config in home directory.
tmpDir, _ := homedir.Dir()
tmpDir, _ := os.UserHomeDir()
_, err := NewApp(tmpDir, false)
assert.Error(err)
assert.Contains(err.Error(), "ddev config is not useful")
Expand Down
3 changes: 1 addition & 2 deletions pkg/ddevapp/utils.go
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/drud/ddev/pkg/fileutil"
"github.com/drud/ddev/pkg/output"
"github.com/drud/ddev/pkg/util"
gohomedir "github.com/mitchellh/go-homedir"
)

// GetActiveProjects returns an array of ddev projects
Expand Down Expand Up @@ -57,7 +56,7 @@ func GetActiveProjects() []*DdevApp {

// RenderHomeRootedDir shortens a directory name to replace homedir with ~
func RenderHomeRootedDir(path string) string {
userDir, err := gohomedir.Dir()
userDir, err := os.UserHomeDir()
util.CheckErr(err)
result := strings.Replace(path, userDir, "~", 1)
result = strings.Replace(result, "\\", "/", -1)
Expand Down
3 changes: 1 addition & 2 deletions pkg/globalconfig/global_config.go
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"github.com/drud/ddev/pkg/nodeps"
"github.com/drud/ddev/pkg/output"
"github.com/mitchellh/go-homedir"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
"net"
Expand Down Expand Up @@ -260,7 +259,7 @@ func WriteGlobalConfig(config GlobalConfig) error {

// GetGlobalDdevDir returns ~/.ddev, the global caching directory
func GetGlobalDdevDir() string {
userHome, err := homedir.Dir()
userHome, err := os.UserHomeDir()
if err != nil {
logrus.Fatal("could not get home directory for current user. is it set?")
}
Expand Down
5 changes: 0 additions & 5 deletions vendor/github.com/Azure/go-ansiterm/go.mod

This file was deleted.

2 changes: 0 additions & 2 deletions vendor/github.com/Azure/go-ansiterm/go.sum

This file was deleted.

3 changes: 0 additions & 3 deletions vendor/github.com/Masterminds/semver/v3/go.mod

This file was deleted.

9 changes: 0 additions & 9 deletions vendor/github.com/Microsoft/go-winio/go.mod

This file was deleted.

14 changes: 0 additions & 14 deletions vendor/github.com/Microsoft/go-winio/go.sum

This file was deleted.

38 changes: 0 additions & 38 deletions vendor/github.com/Microsoft/hcsshim/go.mod

This file was deleted.

0 comments on commit 42adca2

Please sign in to comment.