mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-11 02:26:38 +00:00
core: refine condition for using legacy chain freezer directory (#33032)
This commit is contained in:
parent
33dbd64a23
commit
b1db341f7e
3 changed files with 14 additions and 12 deletions
|
|
@ -37,3 +37,14 @@ func AbsolutePath(datadir string, filename string) string {
|
||||||
}
|
}
|
||||||
return filepath.Join(datadir, filename)
|
return filepath.Join(datadir, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNonEmptyDir checks if a directory exists and is non-empty.
|
||||||
|
func IsNonEmptyDir(dir string) bool {
|
||||||
|
f, err := os.Open(dir)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
names, _ := f.Readdirnames(1)
|
||||||
|
return len(names) > 0
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ func resolveChainFreezerDir(ancient string) string {
|
||||||
// - chain freezer exists in legacy location (root ancient folder)
|
// - chain freezer exists in legacy location (root ancient folder)
|
||||||
freezer := filepath.Join(ancient, ChainFreezerName)
|
freezer := filepath.Join(ancient, ChainFreezerName)
|
||||||
if !common.FileExist(freezer) {
|
if !common.FileExist(freezer) {
|
||||||
if !common.FileExist(ancient) {
|
if !common.FileExist(ancient) || !common.IsNonEmptyDir(ancient) {
|
||||||
// The entire ancient store is not initialized, still use the sub
|
// The entire ancient store is not initialized, still use the sub
|
||||||
// folder for initialization.
|
// folder for initialization.
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/p2p/nat"
|
"github.com/ethereum/go-ethereum/p2p/nat"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
|
@ -90,7 +91,7 @@ func DefaultDataDir() string {
|
||||||
// is non-empty, use it, otherwise DTRT and check %LOCALAPPDATA%.
|
// is non-empty, use it, otherwise DTRT and check %LOCALAPPDATA%.
|
||||||
fallback := filepath.Join(home, "AppData", "Roaming", "Ethereum")
|
fallback := filepath.Join(home, "AppData", "Roaming", "Ethereum")
|
||||||
appdata := windowsAppData()
|
appdata := windowsAppData()
|
||||||
if appdata == "" || isNonEmptyDir(fallback) {
|
if appdata == "" || common.IsNonEmptyDir(fallback) {
|
||||||
return fallback
|
return fallback
|
||||||
}
|
}
|
||||||
return filepath.Join(appdata, "Ethereum")
|
return filepath.Join(appdata, "Ethereum")
|
||||||
|
|
@ -113,16 +114,6 @@ func windowsAppData() string {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
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 a new issue