blob: 904e7063ec0a661a8bf598cfc793b6751901548e [file] [log] [blame]
#pragma once
#include <filesystem>
#include <stdplus/fd/managed.hpp>
#include <string>
#include <string_view>
namespace stdplus
{
namespace fd
{
class AtomicWriter : public stdplus::FdImpl
{
public:
AtomicWriter(const std::filesystem::path& filename, int mode,
std::string_view tmpl = {});
AtomicWriter(AtomicWriter&& other);
AtomicWriter& operator=(AtomicWriter&& other);
~AtomicWriter();
void commit(bool allow_copy = false);
inline const std::string& getTmpname() const
{
return tmpname;
}
int get() const override;
private:
std::filesystem::path filename;
int mode;
std::string tmpname;
ManagedFd fd;
void cleanup() noexcept;
};
} // namespace fd
} // namespace stdplus