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