-
Notifications
You must be signed in to change notification settings - Fork 20.2k
Commit
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
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,18 +58,47 @@ 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") | ||
} | ||
} | ||
// As we cannot guess a stable location, return empty and handle later | ||
return "" | ||
} | ||
|
||
func windowsAppData() string { | ||
if v := os.Getenv("LOCALAPPDATA"); v != "" { | ||
return v // Vista+ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
MicahZoltu
Contributor
|
||
} | ||
if v := os.Getenv("APPDATA"); v != "" { | ||
This comment has been minimized.
Sorry, something went wrong.
MicahZoltu
Contributor
|
||
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 | ||
|
I believe Windows 7 had
LocalAppData
environment variable, I'm not sure how far back you have to go before it wasn't available, but it is a long way.