Skip to content

Commit

Permalink
Fix block log when files do not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed Oct 28, 2016
1 parent 94efcb6 commit 5284404
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions libraries/chain/block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ namespace steemit { namespace chain {
my->block_file = file;
my->index_file = fc::path( file.generic_string() + ".index" );

my->block_stream.open( my->block_file.generic_string().c_str(), LOG_READ );
my->index_stream.open( my->index_file.generic_string().c_str(), LOG_READ );
my->block_stream.open( my->block_file.generic_string().c_str(), LOG_WRITE );
my->index_stream.open( my->index_file.generic_string().c_str(), LOG_WRITE );
my->block_write = true;
my->index_write = true;

/* On startup of the block log, there are several states the log file and the index file can be
* in relation to eachother.
Expand Down Expand Up @@ -115,6 +117,9 @@ namespace steemit { namespace chain {

if( index_size )
{
my->check_block_read();
my->check_index_read();

ilog( "Index is nonempty" );
uint64_t block_pos;
my->block_stream.seekg( -sizeof( uint64_t), std::ios::end );
Expand All @@ -129,6 +134,8 @@ namespace steemit { namespace chain {
ilog( "block_pos < index_pos, close and reopen index_stream" );
my->index_stream.close();
fc::remove_all( my->index_file );
my->index_stream.open( my->index_file.generic_string().c_str(), LOG_WRITE );
my->index_write = true;
construct_index( 0 );
}
else if( block_pos > index_pos )
Expand All @@ -147,7 +154,8 @@ namespace steemit { namespace chain {
ilog( "Index is nonempty, remove and recreate it" );
my->index_stream.close();
fc::remove_all( my->index_file );
my->index_stream.open( my->index_file.generic_string().c_str(), LOG_READ );
my->index_stream.open( my->index_file.generic_string().c_str(), LOG_WRITE );
my->index_write = true;
}
}

Expand Down

0 comments on commit 5284404

Please sign in to comment.