Extract function to create a random filename.
This commit is contained in:
parent
ab093d58d6
commit
d831937f12
2 changed files with 8 additions and 2 deletions
|
|
@ -47,7 +47,7 @@ std::filesystem::path nano::working_path (nano::networks network)
|
|||
return result;
|
||||
}
|
||||
|
||||
std::filesystem::path nano::unique_path (nano::networks network)
|
||||
std::filesystem::path nano::random_filename ()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen (rd ());
|
||||
|
|
@ -61,8 +61,12 @@ std::filesystem::path nano::unique_path (nano::networks network)
|
|||
{
|
||||
random_string += hex_chars[dis (gen)];
|
||||
}
|
||||
return std::filesystem::path{ random_string };
|
||||
}
|
||||
|
||||
auto result = working_path (network) / random_string;
|
||||
std::filesystem::path nano::unique_path (nano::networks network)
|
||||
{
|
||||
auto result = working_path (network) / random_filename ();
|
||||
|
||||
std::filesystem::create_directories (result);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ namespace nano
|
|||
std::filesystem::path app_path ();
|
||||
// OS-specific way of finding a path to a home directory.
|
||||
std::filesystem::path working_path (nano::networks network = nano::network_constants::active_network);
|
||||
// Construct a random filename
|
||||
std::filesystem::path random_filename ();
|
||||
// Get a unique path within the home directory, used for testing.
|
||||
// Any directories created at this location will be removed when a test finishes.
|
||||
std::filesystem::path unique_path (nano::networks network = nano::network_constants::active_network);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue