File tree Expand file tree Collapse file tree 3 files changed +14
-12
lines changed Expand file tree Collapse file tree 3 files changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -37,3 +37,14 @@ func AbsolutePath(datadir string, filename string) string {
3737 }
3838 return filepath .Join (datadir , filename )
3939}
40+
41+ // IsNonEmptyDir checks if a directory exists and is non-empty.
42+ func IsNonEmptyDir (dir string ) bool {
43+ f , err := os .Open (dir )
44+ if err != nil {
45+ return false
46+ }
47+ defer f .Close ()
48+ names , _ := f .Readdirnames (1 )
49+ return len (names ) > 0
50+ }
Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ func resolveChainFreezerDir(ancient string) string {
177177 // - chain freezer exists in legacy location (root ancient folder)
178178 freezer := filepath .Join (ancient , ChainFreezerName )
179179 if ! common .FileExist (freezer ) {
180- if ! common .FileExist (ancient ) {
180+ if ! common .FileExist (ancient ) || ! common . IsNonEmptyDir ( ancient ) {
181181 // The entire ancient store is not initialized, still use the sub
182182 // folder for initialization.
183183 } else {
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import (
2222 "path/filepath"
2323 "runtime"
2424
25+ "github.com/ethereum/go-ethereum/common"
2526 "github.com/ethereum/go-ethereum/p2p"
2627 "github.com/ethereum/go-ethereum/p2p/nat"
2728 "github.com/ethereum/go-ethereum/rpc"
@@ -90,7 +91,7 @@ func DefaultDataDir() string {
9091 // is non-empty, use it, otherwise DTRT and check %LOCALAPPDATA%.
9192 fallback := filepath .Join (home , "AppData" , "Roaming" , "Ethereum" )
9293 appdata := windowsAppData ()
93- if appdata == "" || isNonEmptyDir (fallback ) {
94+ if appdata == "" || common . IsNonEmptyDir (fallback ) {
9495 return fallback
9596 }
9697 return filepath .Join (appdata , "Ethereum" )
@@ -113,16 +114,6 @@ func windowsAppData() string {
113114 return v
114115}
115116
116- func isNonEmptyDir (dir string ) bool {
117- f , err := os .Open (dir )
118- if err != nil {
119- return false
120- }
121- names , _ := f .Readdir (1 )
122- f .Close ()
123- return len (names ) > 0
124- }
125-
126117func homeDir () string {
127118 if home := os .Getenv ("HOME" ); home != "" {
128119 return home
You can’t perform that action at this time.
0 commit comments