aboutsummaryrefslogtreecommitdiffstats
path: root/node/defaults.go
diff options
context:
space:
mode:
authorHackyMiner <hackyminer@gmail.com>2019-02-19 19:15:15 +0800
committerFelix Lange <fjl@users.noreply.github.com>2019-02-19 19:15:15 +0800
commitf7f6a46029c23d2c1b5a5293d470becbdb4e3366 (patch)
treebfe3e6fa048e8bdc0d16357156909e079fc24413 /node/defaults.go
parentd2256244c4f6dbb7312fa280b5523c544d8c10af (diff)
downloadgo-tangerine-f7f6a46029c23d2c1b5a5293d470becbdb4e3366.tar
go-tangerine-f7f6a46029c23d2c1b5a5293d470becbdb4e3366.tar.gz
go-tangerine-f7f6a46029c23d2c1b5a5293d470becbdb4e3366.tar.bz2
go-tangerine-f7f6a46029c23d2c1b5a5293d470becbdb4e3366.tar.lz
go-tangerine-f7f6a46029c23d2c1b5a5293d470becbdb4e3366.tar.xz
go-tangerine-f7f6a46029c23d2c1b5a5293d470becbdb4e3366.tar.zst
go-tangerine-f7f6a46029c23d2c1b5a5293d470becbdb4e3366.zip
eth, node: use APPDATA env to support cygwin/msys correctly (#17786)
This changes default location of the data directory to use the LOCALAPPDATA environment variable, resolving issues with remote home directories an improving compatibility with Cygwin. Fixes #2239 Fixes #2237 Fixes #16437
Diffstat (limited to 'node/defaults.go')
-rw-r--r--node/defaults.go37
1 files changed, 33 insertions, 4 deletions
diff --git a/node/defaults.go b/node/defaults.go
index cea4997cb..73b262429 100644
--- a/node/defaults.go
+++ b/node/defaults.go
@@ -58,11 +58,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" {
- return filepath.Join(home, "AppData", "Roaming", "Ethereum")
- } else {
+ 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
+ }
+ return filepath.Join(appdata, "Ethereum")
+ default:
return filepath.Join(home, ".ethereum")
}
}
@@ -70,6 +79,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