25#include <seastar/core/future.hh>
26#include <seastar/core/file.hh>
27#include <seastar/core/thread.hh>
28#include <seastar/util/std-compat.hh>
32const std::filesystem::path& default_tmpdir();
33void set_default_tmpdir(std::filesystem::path);
36 std::filesystem::path _path;
38 bool _is_open =
false;
40 static_assert(std::is_nothrow_constructible_v<std::filesystem::path>,
41 "filesystem::path's constructor must not throw");
42 static_assert(std::is_nothrow_move_constructible_v<std::filesystem::path>,
43 "filesystem::path's move constructor must not throw");
53 future<> open(std::filesystem::path path_template = default_tmpdir(),
59 template <
typename Func>
60 static future<> do_with(std::filesystem::path path_template, Func&& func,
63 static_assert(std::is_nothrow_move_constructible_v<Func>,
64 "Func's move constructor must not throw");
65 return seastar::do_with(
tmp_file(), [func = std::move(func), path_template = std::move(path_template), oflags, options = std::move(options)] (
tmp_file& t)
mutable {
66 return t.open(std::move(path_template), oflags, std::move(options)).then([&t, func = std::move(func)] ()
mutable {
76 template <
typename Func>
77 static future<> do_with(Func&& func)
noexcept {
78 return do_with(default_tmpdir(), std::move(func));
81 bool has_path()
const {
82 return !_path.empty();
85 bool is_open()
const {
89 const std::filesystem::path& get_path()
const {
120 std::filesystem::path _path;
131 future<> create(std::filesystem::path path_template = default_tmpdir(),
132 file_permissions create_permissions = file_permissions::default_dir_permissions)
noexcept;
135 template <
typename Func>
136 requires std::is_nothrow_move_constructible_v<Func>
137 static future<> do_with(std::filesystem::path path_template, Func&& func,
138 file_permissions create_permissions = file_permissions::default_dir_permissions)
noexcept {
139 static_assert(std::is_nothrow_move_constructible_v<Func>,
140 "Func's move constructor must not throw");
142 return t.create(std::move(path_template), create_permissions).then([&t, func = std::move(func)] ()
mutable {
150 template <
typename Func>
151 static future<> do_with(Func&& func)
noexcept {
152 return do_with(default_tmpdir(), std::move(func));
155 template <
typename Func>
156 requires std::is_nothrow_move_constructible_v<Func>
157 static future<> do_with_thread(Func&& func)
noexcept {
158 static_assert(std::is_nothrow_move_constructible_v<Func>,
159 "Func's move constructor must not throw");
160 return async([func = std::move(func)] ()
mutable {
163 futurize_invoke(func, t).finally([&t] {
169 bool has_path()
const {
170 return !_path.empty();
173 const std::filesystem::path& get_path()
const {
196 file_permissions create_permissions = file_permissions::default_dir_permissions)
noexcept;
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
future< T > finally(Func &&func) noexcept
Definition: future.hh:1640
Definition: tmp_file.hh:119
Definition: tmp_file.hh:35
open_flags
Definition: file-types.hh:41
auto do_with(T1 &&rv1, T2 &&rv2, More &&... more) noexcept
Definition: do_with.hh:135
futurize_t< std::invoke_result_t< Func, Args... > > async(thread_attributes attr, Func &&func, Args &&... args) noexcept
Definition: thread.hh:245
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
future< tmp_dir > make_tmp_dir(std::filesystem::path path_template=default_tmpdir(), file_permissions create_permissions=file_permissions::default_dir_permissions) noexcept
future< tmp_file > make_tmp_file(std::filesystem::path path_template=default_tmpdir(), open_flags oflags=open_flags::rw, file_open_options options={}) noexcept