26 #include <boost/iostreams/device/file_descriptor.hpp> 27 #include <boost/iostreams/stream.hpp> 32 #define DBG_FS LOG_STREAM(debug, log_filesystem) 33 #define LOG_FS LOG_STREAM(info, log_filesystem) 34 #define WRN_FS LOG_STREAM(warn, log_filesystem) 35 #define ERR_FS LOG_STREAM(err, log_filesystem) 43 inline void atomic_fail(
const std::string& step_description)
45 const std::string errno_desc = std::strerror(errno);
46 ERR_FS <<
"Atomic commit failed (" << step_description <<
"): " 47 << errno_desc <<
'\n';
59 int get_stream_file_descriptor(std::ostream& os)
63 typedef boost::iostreams::stream<boost::iostreams::file_descriptor_sink> fd_stream_type;
64 fd_stream_type*
const real =
dynamic_cast<fd_stream_type*
>(&os);
65 return real ? (*real)->handle() : 0;
73 : temp_name_(filename +
".new")
74 , dest_name_(filename)
77 , outfd_(
filesystem::get_stream_file_descriptor(*out_))
104 atomic_fail(
"remove");
108 atomic_fail(
"fsync");
113 atomic_fail(
"rename");
void remove()
Removes a tip.
atomic_commit(const std::string &filename)
Constructor.
static bool file_exists(const bfs::path &fpath)
void commit()
Commits the new file contents to disk atomically.
static lg::log_domain log_filesystem("filesystem")
Atomic filesystem commit functions.
An exception object used when an IO error occurs.
Standard logging facilities (interface).
filesystem::scoped_ostream ostream_file(const std::string &fname, bool create_directory)