17#include "FileSystem.hpp"
123 fs::path
const &
path() const noexcept;
145 void write(std::byte
const * data, std::size_t len)
146 {
write(std::string_view(
reinterpret_cast<std::string_view::value_type
const *
>(data), len)); }
156 void write(std::span<std::byte const> data)
157 {
write(data.data(), data.size()); }
Macro-based enum <-> string utilities for dfx.
#define DFX_DECLARE_ENUM_STRING_FUNCTIONS(E)
Declare the enum string API (and std::formatter) for enum type E.
Definition EnumString.hpp:327
Macros to implement the Private State (PIMPL-like) idiom with value semantics.
#define DFX_PRIVATE_STATE(Class, logger)
Declare a private implementation state for a class.
Definition PrivateState.hpp:52
#define DFX_PRIVATE_STATE_DECLARE_RULE_OF_5(Class)
Declare Rule-of-5 special member functions using the private state pattern.
Definition PrivateState.hpp:82
Miscellaneous small utility helpers (strings, parsing, formatting).
State state() const noexcept
Returns the current state.
void discard() noexcept
Discard the staged file and release resources.
AtomicFileWriter(fs::path p)
Construct an atomic writer targeting p with default options.
bool isPublished() const noexcept
Convenience: true if the file has been published (atomically visible).
Definition AtomicFileWriter.hpp:132
State
Current lifecycle state of the writer.
Definition AtomicFileWriter.hpp:75
@ Discarded
The writer has been discarded: resources are released and nothing new is published.
Definition AtomicFileWriter.hpp:77
@ Published
The target path has been replaced/created atomically (visible in the filesystem).
Definition AtomicFileWriter.hpp:78
@ Open
The writer is active: data can be written and can be committed or discarded.
Definition AtomicFileWriter.hpp:76
@ Durable
Published + parent directory sync succeeded (when enabled), providing durability for the rename/link.
Definition AtomicFileWriter.hpp:79
void write(std::span< std::byte const > data)
Append raw bytes to the staged file.
Definition AtomicFileWriter.hpp:156
bool isDiscarded() const noexcept
Convenience: true if state() == State::Discarded.
Definition AtomicFileWriter.hpp:130
AtomicFileWriter(fs::path p, Options options)
Construct an atomic writer targeting p with explicit options.
void write(std::string_view data)
Append text/binary data to the staged file.
fs::path const & path() const noexcept
Returns the target path.
void commit()
Publish the staged file to the target path.
Backend
Filesystem operation used to create the temporary file.
Definition AtomicFileWriter.hpp:84
@ Mktemp
Use mkostemp function to create the temporary file.
Definition AtomicFileWriter.hpp:86
@ TmpFile
Use open(O_TMPFILE) preferably (will fallback to Mktemp if EOPNOTSUPP).
Definition AtomicFileWriter.hpp:85
bool isOpen() const noexcept
Convenience: true if state() == State::Open.
Definition AtomicFileWriter.hpp:128
bool isDurable() const noexcept
Convenience: true if the file publish operation is durable.
Definition AtomicFileWriter.hpp:134
void write(std::byte const *data, std::size_t len)
Append raw bytes to the staged file.
Definition AtomicFileWriter.hpp:145
Definition SystemConfigCommandHandler.hpp:15
bool isOneOf(T1 val, std::initializer_list< T2 const > list)
Test whether val is equal to one of the elements in list.
Definition Utility.hpp:116
Definition Message.hpp:21
Options controlling publish permissions and durability.
Definition AtomicFileWriter.hpp:91
mode_t mode
Permissions applied to the published file.
Definition AtomicFileWriter.hpp:95
Backend backend
Backend that will be used to create the temporary file.
Definition AtomicFileWriter.hpp:105
bool fsyncDir
If true, attempt to sync the parent directory after publishing. This is what makes the directory entr...
Definition AtomicFileWriter.hpp:102
bool fsyncFile
If true, sync the staged file contents before publishing.
Definition AtomicFileWriter.hpp:98