Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate existing data from ~/RaiBlocks to ~/Nano #1512

Merged
merged 1 commit into from
Dec 29, 2018
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions nano/nano_node/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ int main (int argc, char * const * argv)
}
boost::program_options::notify (vm);
int result (0);

if (!vm.count ("data_path"))
{
std::string error_string;
if (!nano::migrate_working_path (error_string))
{
std::cerr << error_string << std::endl;

return 1;
}
}

boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as<std::string> ()) : nano::working_path ();
auto ec = nano::handle_node_options (vm);

Expand Down
10 changes: 10 additions & 0 deletions nano/nano_wallet/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ int main (int argc, char * const * argv)
boost::program_options::store (boost::program_options::command_line_parser (argc, argv).options (description).allow_unregistered ().run (), vm);
boost::program_options::notify (vm);
int result (0);

if (!vm.count ("data_path"))
{
std::string error_string;
if (!nano::migrate_working_path (error_string))
{
throw std::runtime_error (error_string);
}
}

auto ec = nano::handle_node_options (vm);
if (ec == nano::error_cli::unknown_command)
{
Expand Down
65 changes: 61 additions & 4 deletions nano/secure/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,81 @@

static std::vector<boost::filesystem::path> all_unique_paths;

boost::filesystem::path nano::working_path ()
boost::filesystem::path nano::working_path (bool legacy)
{
auto result (nano::app_path ());
switch (nano::nano_network)
{
case nano::nano_networks::nano_test_network:
result /= "NanoTest";
if (!legacy)
{
result /= "NanoTest";
}
else
{
result /= "RaiBlocksTest";
}
break;
case nano::nano_networks::nano_beta_network:
result /= "NanoBeta";
if (!legacy)
{
result /= "NanoBeta";
}
else
{
result /= "RaiBlocksBeta";
}
break;
case nano::nano_networks::nano_live_network:
result /= "Nano";
if (!legacy)
{
result /= "Nano";
}
else
{
result /= "RaiBlocks";
}
break;
}
return result;
}

bool nano::migrate_working_path (std::string & error_string)
{
bool result (true);
auto old_path (nano::working_path (true));
auto new_path (nano::working_path ());

if (old_path != new_path)
{
boost::system::error_code status_error;

auto old_path_status (boost::filesystem::status (old_path, status_error));
if (status_error == boost::system::errc::success && boost::filesystem::exists (old_path_status) && boost::filesystem::is_directory (old_path_status))
{
auto new_path_status (boost::filesystem::status (new_path, status_error));
if (!boost::filesystem::exists (new_path_status))
{
boost::system::error_code rename_error;

boost::filesystem::rename (old_path, new_path, rename_error);
if (rename_error != boost::system::errc::success)
{
std::stringstream error_string_stream;

error_string_stream << "Unable to migrate data from " << old_path << " to " << new_path;

error_string = error_string_stream.str ();

result = false;
}
}
}
}

return result;
}

boost::filesystem::path nano::unique_path ()
{
auto result (working_path () / boost::filesystem::unique_path ());
Expand Down
4 changes: 3 additions & 1 deletion nano/secure/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ namespace nano
using bufferstream = boost::iostreams::stream_buffer<boost::iostreams::basic_array_source<uint8_t>>;
using vectorstream = boost::iostreams::stream_buffer<boost::iostreams::back_insert_device<std::vector<uint8_t>>>;
// OS-specific way of finding a path to a home directory.
boost::filesystem::path working_path ();
boost::filesystem::path working_path (bool = false);
// Function to migrate working_path() from above from RaiBlocks to Nano
bool migrate_working_path (std::string &);
// Get a unique path within the home directory, used for testing.
// Any directories created at this location will be removed when a test finishes.
boost::filesystem::path unique_path ();
Expand Down