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" {
|
if runtime.GOOS == "darwin" {
|
||||||
return filepath.Join(home, "Library", "Signer")
|
return filepath.Join(home, "Library", "Signer")
|
||||||
} else if runtime.GOOS == "windows" {
|
} else if runtime.GOOS == "windows" {
|
||||||
|
appdata := os.Getenv("APPDATA")
|
||||||
|
if appdata != "" {
|
||||||
|
return filepath.Join(appdata, "Signer")
|
||||||
|
} else {
|
||||||
return filepath.Join(home, "AppData", "Roaming", "Signer")
|
return filepath.Join(home, "AppData", "Roaming", "Signer")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return filepath.Join(home, ".clef")
|
return filepath.Join(home, ".clef")
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,15 @@ func init() {
|
|||||||
home = user.HomeDir
|
home = user.HomeDir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "darwin" {
|
||||||
DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Ethash")
|
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 {
|
} else {
|
||||||
DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash")
|
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
|
// Try to place the data folder in the user's home dir
|
||||||
home := homeDir()
|
home := homeDir()
|
||||||
if home != "" {
|
if home != "" {
|
||||||
if runtime.GOOS == "darwin" {
|
switch runtime.GOOS {
|
||||||
|
case "darwin":
|
||||||
return filepath.Join(home, "Library", "Ethereum")
|
return filepath.Join(home, "Library", "Ethereum")
|
||||||
} else if runtime.GOOS == "windows" {
|
case "windows":
|
||||||
return filepath.Join(home, "AppData", "Roaming", "Ethereum")
|
// We used to put everything in %HOME%\AppData\Roaming, but this caused
|
||||||
} else {
|
// 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")
|
return filepath.Join(home, ".ethereum")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,6 +79,26 @@ func DefaultDataDir() string {
|
|||||||
return ""
|
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 {
|
func homeDir() string {
|
||||||
if home := os.Getenv("HOME"); home != "" {
|
if home := os.Getenv("HOME"); home != "" {
|
||||||
return home
|
return home
|
||||||
|
Loading…
Reference in New Issue
Block a user