1#include <xrpl/basics/FileUtilities.h>
3#include <xrpl/basics/contract.h>
34 if (maxSize && (
file_size(fullPath, ec) > *maxSize || ec))
67 std::ofstream fileStream(destPath, std::ios::out | std::ios::trunc);
75 fileStream << contents;
91 for (
std::size_t attempt = 0; attempt < maxAttempts; ++attempt)
96 auto candidate = base / oss.
str();
102 "Unable to check path '" + candidate.string() +
"': " + ec.
message());
122 std::cerr <<
"Unable to remove temporary directory '" <<
path_.string()
123 <<
"': " << ec.
message() <<
'\n';
130 return path_.string();
std::filesystem::path path_
TempDir()
Construct a temporary directory.
std::string path() const
Get the native path for the temporary directory.
~TempDir()
Destroy a temporary directory.
std::string file(std::string const &name) const
Get the native path for a file.
T create_directory(T... args)
T generic_category(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::error_code make_error_code(xrpl::TokenCodecErrc e)
std::filesystem::path uniqueRandomPath(std::filesystem::path const &base, std::string const &prefix="", std::size_t maxAttempts=100)
Generate a unique, non-existing path under base whose filename starts with prefix and ends with a ran...
std::string getFileContents(std::error_code &ec, std::filesystem::path const &sourcePath, std::optional< std::size_t > maxSize=std::nullopt)
void writeFileContents(std::error_code &ec, std::filesystem::path const &destPath, std::string const &contents)
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
T temp_directory_path(T... args)