rippled
Loading...
Searching...
No Matches
temp_dir.h
1#pragma once
2
3#include <boost/filesystem.hpp>
4
5#include <string>
6
7namespace beast {
8
15{
16 boost::filesystem::path path_;
17
18public:
19#if !GENERATING_DOCS
20 temp_dir(temp_dir const&) = delete;
22 operator=(temp_dir const&) = delete;
23#endif
24
27 {
28 auto const dir = boost::filesystem::temp_directory_path();
29 do
30 {
31 path_ = dir / boost::filesystem::unique_path();
32 } while (boost::filesystem::exists(path_));
33 boost::filesystem::create_directory(path_);
34 }
35
38 {
39 // use non-throwing calls in the destructor
40 boost::system::error_code ec;
41 boost::filesystem::remove_all(path_, ec);
42 // TODO: warn/notify if ec set ?
43 }
44
47 path() const
48 {
49 return path_.string();
50 }
51
57 file(std::string const& name) const
58 {
59 return (path_ / name).string();
60 }
61};
62
63} // namespace beast
RAII temporary directory.
Definition temp_dir.h:15
std::string path() const
Get the native path for the temporary directory.
Definition temp_dir.h:47
boost::filesystem::path path_
Definition temp_dir.h:16
temp_dir()
Construct a temporary directory.
Definition temp_dir.h:26
~temp_dir()
Destroy a temporary directory.
Definition temp_dir.h:37
std::string file(std::string const &name) const
Get the native path for the a file.
Definition temp_dir.h:57