diff --git a/pkg/server/server.go b/pkg/server/server.go index 736a0d70e..1b44e0203 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -19,7 +19,6 @@ package server import ( "log" "os" - "os/user" "path" "reflect" @@ -29,6 +28,7 @@ import ( mstorage "github.com/minio-io/minio/pkg/storage" "github.com/minio-io/minio/pkg/storage/fs" "github.com/minio-io/minio/pkg/storage/inmemory" + "github.com/minio-io/minio/pkg/utils/helpers" ) type ServerConfig struct { @@ -128,13 +128,9 @@ func getStorageChannels(storageType StorageType) (ctrlChans []chan<- string, sta } case storageType == FileStorage: { - // TODO Replace this with a more configurable and robust version - currentUser, err := user.Current() - if err != nil { - log.Fatal(err) - } - rootPath := path.Join(currentUser.HomeDir, "minio-storage") - _, err = os.Stat(rootPath) + homeDir := helpers.HomeDir() + rootPath := path.Join(homeDir, "minio-storage") + _, err := os.Stat(rootPath) if os.IsNotExist(err) { err = os.Mkdir(rootPath, 0700) } else if err != nil { diff --git a/pkg/utils/helpers.go b/pkg/utils/helpers/common.go similarity index 78% rename from pkg/utils/helpers.go rename to pkg/utils/helpers/common.go index 64534ebad..3b3eee3c6 100644 --- a/pkg/utils/helpers.go +++ b/pkg/utils/helpers/common.go @@ -14,14 +14,27 @@ * limitations under the License. */ -package utils +package helpers import ( "io/ioutil" "log" + "os" + "runtime" "strings" ) +func HomeDir() string { + if runtime.GOOS == "windows" { + home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH") + if home == "" { + home = os.Getenv("USERPROFILE") + } + return home + } + return os.Getenv("HOME") +} + func MakeTempTestDir() (string, error) { return ioutil.TempDir("/tmp", "minio-test-") } diff --git a/pkg/utils/execpipe.go b/pkg/utils/helpers/execpipe.go similarity index 99% rename from pkg/utils/execpipe.go rename to pkg/utils/helpers/execpipe.go index 848abed3d..04dcced7c 100644 --- a/pkg/utils/execpipe.go +++ b/pkg/utils/helpers/execpipe.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package utils +package helpers import ( "bytes" diff --git a/pkg/utils/execpipe_test.go b/pkg/utils/helpers/execpipe_test.go similarity index 98% rename from pkg/utils/execpipe_test.go rename to pkg/utils/helpers/execpipe_test.go index d7eda90eb..2e1bbf90b 100644 --- a/pkg/utils/execpipe_test.go +++ b/pkg/utils/helpers/execpipe_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package utils +package helpers import ( "io/ioutil"