aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorwarptangent <warptangent@inbox.com>2015-08-14 12:45:12 -0700
committerwarptangent <warptangent@inbox.com>2015-08-14 12:46:08 -0700
commit97c5faa0b6acdea7d114ec928bccec325873d2e3 (patch)
treeb844f17e1ca206e06f8cca880033f744d7918614 /src
parentMerge pull request #372 (diff)
downloadmonero-97c5faa0b6acdea7d114ec928bccec325873d2e3.tar.xz
blockchain_export: Add --output-file argument
This option will export to the specified file path. The default file path remains <data-dir>/export/blockchain.raw
Diffstat (limited to 'src')
-rw-r--r--src/blockchain_utilities/blockchain_export.cpp15
-rw-r--r--src/blockchain_utilities/bootstrap_file.cpp16
-rw-r--r--src/blockchain_utilities/bootstrap_file.h6
3 files changed, 21 insertions, 16 deletions
diff --git a/src/blockchain_utilities/blockchain_export.cpp b/src/blockchain_utilities/blockchain_export.cpp
index ec885ea98..8db8b7cdb 100644
--- a/src/blockchain_utilities/blockchain_export.cpp
+++ b/src/blockchain_utilities/blockchain_export.cpp
@@ -39,13 +39,14 @@ int main(int argc, char* argv[])
{
uint32_t log_level = 0;
uint64_t block_stop = 0;
- std::string import_filename = BLOCKCHAIN_RAW;
boost::filesystem::path default_data_path {tools::get_default_data_dir()};
boost::filesystem::path default_testnet_data_path {default_data_path / "testnet"};
+ boost::filesystem::path output_file_path;
po::options_description desc_cmd_only("Command line options");
po::options_description desc_cmd_sett("Command line options and settings options");
+ const command_line::arg_descriptor<std::string> arg_output_file = {"output-file", "Specify output file", "", true};
const command_line::arg_descriptor<uint32_t> arg_log_level = {"log-level", "", log_level};
const command_line::arg_descriptor<uint64_t> arg_block_stop = {"block-stop", "Stop at block number", block_stop};
const command_line::arg_descriptor<bool> arg_testnet_on = {
@@ -57,6 +58,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_cmd_sett, command_line::arg_data_dir, default_data_path.string());
command_line::add_arg(desc_cmd_sett, command_line::arg_testnet_data_dir, default_testnet_data_path.string());
+ command_line::add_arg(desc_cmd_sett, arg_output_file);
command_line::add_arg(desc_cmd_sett, arg_testnet_on);
command_line::add_arg(desc_cmd_sett, arg_log_level);
command_line::add_arg(desc_cmd_sett, arg_block_stop);
@@ -97,9 +99,12 @@ int main(int argc, char* argv[])
auto data_dir_arg = opt_testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;
m_config_folder = command_line::get_arg(vm, data_dir_arg);
- boost::filesystem::path output_dir {m_config_folder};
- output_dir /= "export";
- LOG_PRINT_L0("Export directory: " << output_dir.string());
+
+ if (command_line::has_arg(vm, arg_output_file))
+ output_file_path = boost::filesystem::path(command_line::get_arg(vm, arg_output_file));
+ else
+ output_file_path = boost::filesystem::path(m_config_folder) / "export" / BLOCKCHAIN_RAW;
+ LOG_PRINT_L0("Export output file: " << output_file_path.string());
// If we wanted to use the memory pool, we would set up a fake_core.
@@ -151,7 +156,7 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Exporting blockchain raw data...");
BootstrapFile bootstrap;
- r = bootstrap.store_blockchain_raw(core_storage, NULL, output_dir, block_stop);
+ r = bootstrap.store_blockchain_raw(core_storage, NULL, output_file_path, block_stop);
CHECK_AND_ASSERT_MES(r, false, "Failed to export blockchain raw data");
LOG_PRINT_L0("Blockchain raw data exported OK");
}
diff --git a/src/blockchain_utilities/bootstrap_file.cpp b/src/blockchain_utilities/bootstrap_file.cpp
index 573cb1572..ab841c8c6 100644
--- a/src/blockchain_utilities/bootstrap_file.cpp
+++ b/src/blockchain_utilities/bootstrap_file.cpp
@@ -50,8 +50,9 @@ namespace
-bool BootstrapFile::open_writer(const boost::filesystem::path& dir_path)
+bool BootstrapFile::open_writer(const boost::filesystem::path& file_path)
{
+ const boost::filesystem::path dir_path = file_path.parent_path();
if (boost::filesystem::exists(dir_path))
{
if (!boost::filesystem::is_directory(dir_path))
@@ -69,7 +70,6 @@ bool BootstrapFile::open_writer(const boost::filesystem::path& dir_path)
}
}
- std::string file_path = (dir_path / BLOCKCHAIN_RAW).string();
m_raw_data_file = new std::ofstream();
bool do_initialize_file = false;
@@ -83,15 +83,15 @@ bool BootstrapFile::open_writer(const boost::filesystem::path& dir_path)
}
else
{
- num_blocks = count_blocks(file_path);
+ num_blocks = count_blocks(file_path.string());
LOG_PRINT_L0("appending to existing file with height: " << num_blocks-1 << " total blocks: " << num_blocks);
}
m_height = num_blocks;
if (do_initialize_file)
- m_raw_data_file->open(file_path, std::ios_base::binary | std::ios_base::out | std::ios::trunc);
+ m_raw_data_file->open(file_path.string(), std::ios_base::binary | std::ios_base::out | std::ios::trunc);
else
- m_raw_data_file->open(file_path, std::ios_base::binary | std::ios_base::out | std::ios::app | std::ios::ate);
+ m_raw_data_file->open(file_path.string(), std::ios_base::binary | std::ios_base::out | std::ios::app | std::ios::ate);
if (m_raw_data_file->fail())
return false;
@@ -286,9 +286,9 @@ bool BootstrapFile::close()
#if SOURCE_DB == DB_MEMORY
-bool BootstrapFile::store_blockchain_raw(blockchain_storage* _blockchain_storage, tx_memory_pool* _tx_pool, boost::filesystem::path& output_dir, uint64_t requested_block_stop)
+bool BootstrapFile::store_blockchain_raw(blockchain_storage* _blockchain_storage, tx_memory_pool* _tx_pool, boost::filesystem::path& output_file, uint64_t requested_block_stop)
#else
-bool BootstrapFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_memory_pool* _tx_pool, boost::filesystem::path& output_dir, uint64_t requested_block_stop)
+bool BootstrapFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_memory_pool* _tx_pool, boost::filesystem::path& output_file, uint64_t requested_block_stop)
#endif
{
uint64_t num_blocks_written = 0;
@@ -297,7 +297,7 @@ bool BootstrapFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_mem
m_tx_pool = _tx_pool;
uint64_t progress_interval = 100;
LOG_PRINT_L0("Storing blocks raw data...");
- if (!BootstrapFile::open_writer(output_dir))
+ if (!BootstrapFile::open_writer(output_file))
{
LOG_PRINT_RED_L0("failed to open raw file for write");
return false;
diff --git a/src/blockchain_utilities/bootstrap_file.h b/src/blockchain_utilities/bootstrap_file.h
index 5fb8a1d4a..fcf89d1ac 100644
--- a/src/blockchain_utilities/bootstrap_file.h
+++ b/src/blockchain_utilities/bootstrap_file.h
@@ -81,10 +81,10 @@ public:
#if SOURCE_DB == DB_MEMORY
bool store_blockchain_raw(cryptonote::blockchain_storage* cs, cryptonote::tx_memory_pool* txp,
- boost::filesystem::path& output_dir, uint64_t use_block_height=0);
+ boost::filesystem::path& output_file, uint64_t use_block_height=0);
#else
bool store_blockchain_raw(cryptonote::Blockchain* cs, cryptonote::tx_memory_pool* txp,
- boost::filesystem::path& output_dir, uint64_t use_block_height=0);
+ boost::filesystem::path& output_file, uint64_t use_block_height=0);
#endif
protected:
@@ -102,7 +102,7 @@ protected:
boost::iostreams::stream<boost::iostreams::back_insert_device<buffer_type>>* m_output_stream;
// open export file for write
- bool open_writer(const boost::filesystem::path& dir_path);
+ bool open_writer(const boost::filesystem::path& file_path);
bool initialize_file();
bool close();
void write_block(block& block);