blob: 389c5ac60ed18fdf12726f0386caef364b4e0c49 [file] [log] [blame]
William A. Kennington IIIaa4fcfc2022-08-23 16:35:10 -07001#pragma once
William A. Kennington IIIaa4fcfc2022-08-23 16:35:10 -07002#include <stdplus/fd/managed.hpp>
Patrick Williamsd1984dd2023-05-10 16:12:44 -05003
4#include <filesystem>
William A. Kennington IIIaa4fcfc2022-08-23 16:35:10 -07005#include <string>
6#include <string_view>
7
8namespace stdplus
9{
10namespace fd
11{
12
13class AtomicWriter : public stdplus::FdImpl
14{
15 public:
16 AtomicWriter(const std::filesystem::path& filename, int mode,
17 std::string_view tmpl = {});
18 AtomicWriter(AtomicWriter&& other);
19 AtomicWriter& operator=(AtomicWriter&& other);
20 ~AtomicWriter();
21
22 void commit(bool allow_copy = false);
23
24 inline const std::string& getTmpname() const
25 {
26 return tmpname;
27 }
28
29 int get() const override;
30
31 private:
32 std::filesystem::path filename;
33 int mode;
34 std::string tmpname;
35 ManagedFd fd;
36
37 void cleanup() noexcept;
38};
39
40} // namespace fd
41} // namespace stdplus