dncurrency/nano/secure/utility.cpp
Wesley Shillingford 0a64feb49e
Various consistency changes (#3058)
* Various consistency changes

* Colin comments
2021-02-17 15:36:27 +00:00

99 lines
1.9 KiB
C++

#include <nano/lib/config.hpp>
#include <nano/secure/utility.hpp>
#include <nano/secure/working.hpp>
#include <boost/filesystem.hpp>
static std::vector<boost::filesystem::path> all_unique_paths;
boost::filesystem::path nano::working_path (bool legacy)
{
static nano::network_constants network_constants;
auto result (nano::app_path ());
switch (network_constants.network ())
{
case nano::nano_networks::nano_dev_network:
if (!legacy)
{
result /= "NanoDev";
}
else
{
result /= "RaiBlocksDev";
}
break;
case nano::nano_networks::nano_beta_network:
if (!legacy)
{
result /= "NanoBeta";
}
else
{
result /= "RaiBlocksBeta";
}
break;
case nano::nano_networks::nano_live_network:
if (!legacy)
{
result /= "Nano";
}
else
{
result /= "RaiBlocks";
}
break;
case nano::nano_networks::nano_test_network:
if (!legacy)
{
result /= "NanoTest";
}
else
{
result /= "RaiBlocksTest";
}
break;
}
return result;
}
boost::filesystem::path nano::unique_path ()
{
auto result (working_path () / boost::filesystem::unique_path ());
all_unique_paths.push_back (result);
return result;
}
void nano::remove_temporary_directories ()
{
for (auto & path : all_unique_paths)
{
boost::system::error_code ec;
boost::filesystem::remove_all (path, ec);
if (ec)
{
std::cerr << "Could not remove temporary directory: " << ec.message () << std::endl;
}
// lmdb creates a -lock suffixed file for its MDB_NOSUBDIR databases
auto lockfile = path;
lockfile += "-lock";
boost::filesystem::remove (lockfile, ec);
if (ec)
{
std::cerr << "Could not remove temporary lock file: " << ec.message () << std::endl;
}
}
}
namespace nano
{
/** A wrapper for handling signals */
std::function<void()> signal_handler_impl;
void signal_handler (int sig)
{
if (signal_handler_impl != nullptr)
{
signal_handler_impl ();
}
}
}