forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce GetUniquePath(base) helper method to replace boost::filesys…
…tem::unique_path() which is not available in std::filesystem.
- Loading branch information
Showing
6 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <random.h> | ||
#include <fs.h> | ||
#include <util/strencodings.h> | ||
|
||
fs::path GetUniquePath(const fs::path& base) | ||
{ | ||
FastRandomContext rnd; | ||
fs::path tmpFile = base / HexStr(rnd.randbytes(8)); | ||
return tmpFile; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) 2021 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_UTIL_GETUNIQUEPATH_H | ||
#define BITCOIN_UTIL_GETUNIQUEPATH_H | ||
|
||
#include <fs.h> | ||
|
||
/** | ||
* Helper function for getting a unique path | ||
* | ||
* @param[in] base Base path | ||
* @returns base joined with a random 8-character long string. | ||
* @post Returned path is unique with high probability. | ||
*/ | ||
fs::path GetUniquePath(const fs::path& base); | ||
|
||
#endif // BITCOIN_UTIL_GETUNIQUEPATH_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters