forked from cerc-io/plugeth
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
This commit is contained in:
parent
d2256244c4
commit
f7f6a46029
@ -533,7 +533,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")
|
||||
}
|
||||
|
@ -68,8 +68,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")
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user