Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

delete contents inside state directory but not the directory itself #5696

Merged
merged 2 commits into from
Sep 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,17 @@ fc::time_point calculate_genesis_timestamp( string tstr ) {
return genesis_timestamp;
}

void clear_directory_contents( const fc::path& p ) {
using boost::filesystem::directory_iterator;

if( !fc::is_directory( p ) )
return;

for( directory_iterator enditr, itr{p}; itr != enditr; ++itr ) {
fc::remove_all( itr->path() );
}
}

void chain_plugin::plugin_initialize(const variables_map& options) {
ilog("initializing chain plugin");

Expand Down Expand Up @@ -456,11 +467,11 @@ void chain_plugin::plugin_initialize(const variables_map& options) {
ilog( "Deleting state database and blocks" );
if( options.at( "truncate-at-block" ).as<uint32_t>() > 0 )
wlog( "The --truncate-at-block option does not make sense when deleting all blocks." );
fc::remove_all( my->chain_config->state_dir );
clear_directory_contents( my->chain_config->state_dir );
fc::remove_all( my->blocks_dir );
} else if( options.at( "hard-replay-blockchain" ).as<bool>()) {
ilog( "Hard replay requested: deleting state database" );
fc::remove_all( my->chain_config->state_dir );
clear_directory_contents( my->chain_config->state_dir );
auto backup_dir = block_log::repair_log( my->blocks_dir, options.at( "truncate-at-block" ).as<uint32_t>());
if( fc::exists( backup_dir / config::reversible_blocks_dir_name ) ||
options.at( "fix-reversible-blocks" ).as<bool>()) {
Expand All @@ -482,7 +493,7 @@ void chain_plugin::plugin_initialize(const variables_map& options) {
ilog( "Replay requested: deleting state database" );
if( options.at( "truncate-at-block" ).as<uint32_t>() > 0 )
wlog( "The --truncate-at-block option does not work for a regular replay of the blockchain." );
fc::remove_all( my->chain_config->state_dir );
clear_directory_contents( my->chain_config->state_dir );
if( options.at( "fix-reversible-blocks" ).as<bool>()) {
if( !recover_reversible_blocks( my->chain_config->blocks_dir / config::reversible_blocks_dir_name,
my->chain_config->reversible_cache_size )) {
Expand Down