From 6b9f68f0607f2b6c7a94b6b7c96d7188eeb0f8ef Mon Sep 17 00:00:00 2001 From: hackyminer Date: Sat, 22 Sep 2018 05:38:31 +0900 Subject: [PATCH 1/4] node: use APPDATA env to support cygwin/msys correctly --- node/defaults.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/defaults.go b/node/defaults.go index c1376dba0f33..8e0655848b61 100644 --- a/node/defaults.go +++ b/node/defaults.go @@ -59,7 +59,7 @@ func DefaultDataDir() string { if runtime.GOOS == "darwin" { return filepath.Join(home, "Library", "Ethereum") } else if runtime.GOOS == "windows" { - return filepath.Join(home, "AppData", "Roaming", "Ethereum") + return filepath.Join(os.Getenv("APPDATA"), "Ethereum") } else { return filepath.Join(home, ".ethereum") } From c5549ae256605671815be64e2656f0aa46844949 Mon Sep 17 00:00:00 2001 From: hackyminer Date: Sun, 21 Oct 2018 19:06:58 +0900 Subject: [PATCH 2/4] cmd, node: use APPDATA env if it available --- cmd/clef/main.go | 7 ++++++- node/defaults.go | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/clef/main.go b/cmd/clef/main.go index c060285be604..b5451a9b4f29 100644 --- a/cmd/clef/main.go +++ b/cmd/clef/main.go @@ -494,7 +494,12 @@ func DefaultConfigDir() string { if runtime.GOOS == "darwin" { return filepath.Join(home, "Library", "Signer") } else if runtime.GOOS == "windows" { - return filepath.Join(home, "AppData", "Roaming", "Signer") + appdata := os.Getenv("APPDATA") + if appdata != "" { + return filepath.Join(appdata, "Signer") + } else { + return filepath.Join(home, "AppData", "Roaming", "Signer") + } } else { return filepath.Join(home, ".clef") } diff --git a/node/defaults.go b/node/defaults.go index 8e0655848b61..350e3dcd8e93 100644 --- a/node/defaults.go +++ b/node/defaults.go @@ -59,7 +59,12 @@ func DefaultDataDir() string { if runtime.GOOS == "darwin" { return filepath.Join(home, "Library", "Ethereum") } else if runtime.GOOS == "windows" { - return filepath.Join(os.Getenv("APPDATA"), "Ethereum") + appdata := os.Getenv("APPDATA") + if appdata != "" { + return filepath.Join(appdata, "Ethereum") + } else { + return filepath.Join(home, "AppData", "Roaming", "Ethereum") + } } else { return filepath.Join(home, ".ethereum") } From e7bb3468d3e32f79b4a40e63040c344abc1f9062 Mon Sep 17 00:00:00 2001 From: hackyminer Date: Sun, 21 Oct 2018 19:31:18 +0900 Subject: [PATCH 3/4] eth: use LOCALAPPDATA env variable for the Ethash cache dir. --- eth/config.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/eth/config.go b/eth/config.go index efbaafb6a2d3..de7558a0de71 100644 --- a/eth/config.go +++ b/eth/config.go @@ -67,8 +67,15 @@ func init() { home = user.HomeDir } } - if runtime.GOOS == "windows" { - DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Ethash") + if runtime.GOOS == "darwin" { + DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash") + } else if runtime.GOOS == "windows" { + localappdata := os.Getenv("LOCALAPPDATA") + if localappdata != "" { + DefaultConfig.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash") + } else { + DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash") + } } else { DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash") } From 3ef8310edbceca297214bbabc332ed62e378f12e Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 11 Feb 2019 12:30:24 +0100 Subject: [PATCH 4/4] node: check for previous default datadir --- node/defaults.go | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/node/defaults.go b/node/defaults.go index 350e3dcd8e93..95cf8c2ca5e9 100644 --- a/node/defaults.go +++ b/node/defaults.go @@ -56,16 +56,20 @@ func DefaultDataDir() string { // Try to place the data folder in the user's home dir home := homeDir() if home != "" { - if runtime.GOOS == "darwin" { + switch runtime.GOOS { + case "darwin": return filepath.Join(home, "Library", "Ethereum") - } else if runtime.GOOS == "windows" { - appdata := os.Getenv("APPDATA") - if appdata != "" { - return filepath.Join(appdata, "Ethereum") - } else { - return filepath.Join(home, "AppData", "Roaming", "Ethereum") + case "windows": + // We used to put everything in %HOME%\AppData\Roaming, but this caused + // problems with non-typical setups. If this fallback location exists and + // is non-empty, use it, otherwise DTRT and check %LOCALAPPDATA%. + fallback := filepath.Join(home, "AppData", "Roaming", "Ethereum") + appdata := windowsAppData() + if appdata == "" || isNonEmptyDir(fallback) { + return fallback } - } else { + return filepath.Join(appdata, "Ethereum") + default: return filepath.Join(home, ".ethereum") } } @@ -73,6 +77,26 @@ func DefaultDataDir() string { return "" } +func windowsAppData() string { + if v := os.Getenv("LOCALAPPDATA"); v != "" { + return v // Vista+ + } + if v := os.Getenv("APPDATA"); v != "" { + return filepath.Join(v, "Local") + } + return "" +} + +func isNonEmptyDir(dir string) bool { + f, err := os.Open(dir) + if err != nil { + return false + } + names, _ := f.Readdir(1) + f.Close() + return len(names) > 0 +} + func homeDir() string { if home := os.Getenv("HOME"); home != "" { return home