William A. Kennington III | aa4fcfc | 2022-08-23 16:35:10 -0700 | [diff] [blame] | 1 | #pragma once |
William A. Kennington III | aa4fcfc | 2022-08-23 16:35:10 -0700 | [diff] [blame] | 2 | #include <stdplus/fd/managed.hpp> |
Patrick Williams | d1984dd | 2023-05-10 16:12:44 -0500 | [diff] [blame] | 3 | |
| 4 | #include <filesystem> |
William A. Kennington III | aa4fcfc | 2022-08-23 16:35:10 -0700 | [diff] [blame] | 5 | #include <string> |
| 6 | #include <string_view> |
| 7 | |
| 8 | namespace stdplus |
| 9 | { |
| 10 | namespace fd |
| 11 | { |
| 12 | |
| 13 | class 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 |