@ -198,60 +198,73 @@ WARNING: This is a low-level operation which may cause database corruption!`,
func removeDB ( ctx * cli . Context ) error {
func removeDB ( ctx * cli . Context ) error {
stack , config := makeConfigNode ( ctx )
stack , config := makeConfigNode ( ctx )
// Remove the full node state database
// Resolve folder paths.
path := stack . ResolvePath ( "chaindata" )
var (
if common . FileExist ( path ) {
rootDir = stack . ResolvePath ( "chaindata" )
confirmAndRemoveDB ( path , "full node state database" )
ancientDir = config . Eth . DatabaseFreezer
} else {
)
log . Info ( "Full node state database missing" , "path" , path )
}
// Remove the full node ancient database
path = config . Eth . DatabaseFreezer
switch {
switch {
case path == "" :
case ancientDir == "" :
path = filepath . Join ( stack . ResolvePath ( "chaindata" ) , "ancient" )
ancientDir = filepath . Join ( stack . ResolvePath ( "chaindata" ) , "ancient" )
case ! filepath . IsAbs ( path ) :
case ! filepath . IsAbs ( ancientDir ) :
path = config . Node . ResolvePath ( path )
ancientDir = config . Node . ResolvePath ( ancientDir )
}
}
if common . FileExist ( path ) {
// Delete state data
confirmAndRemoveDB ( path , "full node ancient database" )
statePaths := [ ] string { rootDir , filepath . Join ( ancientDir , rawdb . StateFreezerName ) }
} else {
confirmAndRemoveDB ( statePaths , "state data" )
log . Info ( "Full node ancient database missing" , "path" , path )
}
// Delete ancient chain
// Remove the light node database
chainPaths := [ ] string { filepath . Join ( ancientDir , rawdb . ChainFreezerName ) }
path = stack . ResolvePath ( "lightchaindata" )
confirmAndRemoveDB ( chainPaths , "ancient chain" )
if common . FileExist ( path ) {
confirmAndRemoveDB ( path , "light node database" )
} else {
log . Info ( "Light node database missing" , "path" , path )
}
return nil
return nil
}
}
// removeFolder deletes all files (not folders) inside the directory 'dir' (but
// not files in subfolders).
func removeFolder ( dir string ) {
filepath . Walk ( dir , func ( path string , info os . FileInfo , err error ) error {
// If we're at the top level folder, recurse into
if path == dir {
return nil
}
// Delete all the files, but not subfolders
if ! info . IsDir ( ) {
os . Remove ( path )
return nil
}
return filepath . SkipDir
} )
}
// confirmAndRemoveDB prompts the user for a last confirmation and removes the
// confirmAndRemoveDB prompts the user for a last confirmation and removes the
// folder if accepted.
// list of folders if accepted.
func confirmAndRemoveDB ( database string , kind string ) {
func confirmAndRemoveDB ( paths [ ] string , kind string ) {
confirm , err := prompt . Stdin . PromptConfirm ( fmt . Sprintf ( "Remove %s (%s)?" , kind , database ) )
msg := fmt . Sprintf ( "Location(s) of '%s': \n" , kind )
for _ , path := range paths {
msg += fmt . Sprintf ( "\t- %s\n" , path )
}
fmt . Println ( msg )
confirm , err := prompt . Stdin . PromptConfirm ( fmt . Sprintf ( "Remove '%s'?" , kind ) )
switch {
switch {
case err != nil :
case err != nil :
utils . Fatalf ( "%v" , err )
utils . Fatalf ( "%v" , err )
case ! confirm :
case ! confirm :
log . Info ( "Database deletion skipped" , "path" , database )
log . Info ( "Database deletion skipped" , "kind" , kind , " paths " , paths )
default :
default :
start := time . Now ( )
var (
filepath . Walk ( database , func ( path string , info os . FileInfo , err error ) error {
deleted [ ] string
// If we're at the top level folder, recurse into
start = time . Now ( )
if path == database {
)
return nil
for _ , path := range paths {
if common . FileExist ( path ) {
removeFolder ( path )
deleted = append ( deleted , path )
} else {
log . Info ( "Folder is not existent" , "path" , path )
}
}
// Delete all the files, but not subfolders
}
if ! info . IsDir ( ) {
log . Info ( "Database successfully deleted" , "kind" , kind , "paths" , deleted , "elapsed" , common . PrettyDuration ( time . Since ( start ) ) )
os . Remove ( path )
return nil
}
return filepath . SkipDir
} )
log . Info ( "Database successfully deleted" , "path" , database , "elapsed" , common . PrettyDuration ( time . Since ( start ) ) )
}
}
}
}