xrpld
Loading...
Searching...
No Matches
FileUtilities.h
1#pragma once
2
3#include <cstddef>
4#include <filesystem>
5#include <optional>
6#include <string>
7#include <system_error>
8
9namespace xrpl {
10
11std::string
13 std::error_code& ec,
14 std::filesystem::path const& sourcePath,
15 std::optional<std::size_t> maxSize = std::nullopt);
16
17void
19 std::error_code& ec,
20 std::filesystem::path const& destPath,
21 std::string const& contents);
22
31std::filesystem::path
33 std::filesystem::path const& base,
34 std::string const& prefix = "",
35 std::size_t maxAttempts = 100);
36
44{
46
47public:
48#if !GENERATING_DOCS
49 TempDir(TempDir const&) = delete;
50 TempDir&
51 operator=(TempDir const&) = delete;
52#endif
53
57 TempDir();
58
62 ~TempDir();
63
67 [[nodiscard]] std::string
68 path() const;
69
75 [[nodiscard]] std::string
76 file(std::string const& name) const;
77};
78
79} // namespace xrpl
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.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
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)