|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
The raw file-I/O primitives morph::journal::FileActionLog and morph::offline::FileOfflineQueue both call, as an injectable strategy. Every member defaults to the real syscall/stdlib call it stands in for, so a default-constructed FileIoOps is byte-for-byte what both classes called directly before this seam existed — no behavior change for a normal caller. More...
#include <file_io_ops.hpp>
Public Attributes | |
| std::function< std::size_t(const void *buffer, std::size_t size, std::FILE *file)> | fwrite |
Writes size bytes from buffer to file. Mirrors std::fwrite. | |
| std::function< int(std::FILE *file)> | fflush = [](std::FILE* file) { return std::fflush(file); } |
Flushes file's stdio buffer. Mirrors std::fflush. | |
| std::function< int(std::FILE *file)> | fsync |
Commits file's contents to durable storage. POSIX fsync / Windows _commit, resolved from file via fileno/_fileno. | |
| std::function< std::FILE *(const std::string &path, const char *mode)> | fopen |
Opens path in mode mode. Mirrors std::fopen. | |
| std::function< bool(const std::filesystem::path &path)> | canOpenForRead |
Reports whether path can be opened for reading right now. Stands in for std::ifstream{path}'s own open-succeeded check (repairTornTail()'s if (!input)) — a fault-injection test has no way to make a real std::ifstream construction fail without actually breaking the filesystem, so this predicate is consulted first; the real default performs the real open std::ifstream itself would. | |
| std::function< void(const std::filesystem::path &path, std::uintmax_t newSize, std::error_code &errorCode)> | resizeFile |
Truncates/extends path to newSize bytes. Mirrors std::filesystem::resize_file. | |
| std::function< int(const std::filesystem::path &dir)> | syncPath |
| Commits a directory's own metadata (new/renamed entries within it) to durable storage. fsync on a file makes only that file's data durable – not the directory entry that names it, so a fresh file's creation or a rename can vanish on power loss even after the file's own contents were fsynced. POSIX: open(dir, O_RDONLY|O_DIRECTORY) + fsync + close. A no-op on Windows, documented as such rather than faked – FlushFileBuffers's semantics for a directory handle differ enough from POSIX fsync that pretending otherwise would be misleading, and this seam's Windows story is already file-fsync-only. | |
The raw file-I/O primitives morph::journal::FileActionLog and morph::offline::FileOfflineQueue both call, as an injectable strategy. Every member defaults to the real syscall/stdlib call it stands in for, so a default-constructed FileIoOps is byte-for-byte what both classes called directly before this seam existed — no behavior change for a normal caller.
Definition at line 74 of file file_io_ops.hpp.
| std::function<std::size_t(const void* buffer, std::size_t size, std::FILE* file)> morph::core::FileIoOps::fwrite |
Writes size bytes from buffer to file. Mirrors std::fwrite.
size on failure. Definition at line 77 of file file_io_ops.hpp.
| std::function<int(std::FILE* file)> morph::core::FileIoOps::fflush = [](std::FILE* file) { return std::fflush(file); } |
Flushes file's stdio buffer. Mirrors std::fflush.
Definition at line 82 of file file_io_ops.hpp.
| std::function<int(std::FILE* file)> morph::core::FileIoOps::fsync |
Commits file's contents to durable storage. POSIX fsync / Windows _commit, resolved from file via fileno/_fileno.
Definition at line 87 of file file_io_ops.hpp.
| std::function<std::FILE*(const std::string& path, const char* mode)> morph::core::FileIoOps::fopen |
Opens path in mode mode. Mirrors std::fopen.
Definition at line 98 of file file_io_ops.hpp.
| std::function<bool(const std::filesystem::path& path)> morph::core::FileIoOps::canOpenForRead |
Reports whether path can be opened for reading right now. Stands in for std::ifstream{path}'s own open-succeeded check (repairTornTail()'s if (!input)) — a fault-injection test has no way to make a real std::ifstream construction fail without actually breaking the filesystem, so this predicate is consulted first; the real default performs the real open std::ifstream itself would.
path is currently readable. Definition at line 112 of file file_io_ops.hpp.
| std::function<void(const std::filesystem::path& path, std::uintmax_t newSize, std::error_code& errorCode)> morph::core::FileIoOps::resizeFile |
Truncates/extends path to newSize bytes. Mirrors std::filesystem::resize_file.
| path | Path to resize. |
| newSize | Target size, in bytes. |
| errorCode | Set on failure, cleared on success — same contract as std::filesystem::resize_file's own error_code overload. |
Definition at line 123 of file file_io_ops.hpp.
| std::function<int(const std::filesystem::path& dir)> morph::core::FileIoOps::syncPath |
Commits a directory's own metadata (new/renamed entries within it) to durable storage. fsync on a file makes only that file's data durable – not the directory entry that names it, so a fresh file's creation or a rename can vanish on power loss even after the file's own contents were fsynced. POSIX: open(dir, O_RDONLY|O_DIRECTORY) + fsync + close. A no-op on Windows, documented as such rather than faked – FlushFileBuffers's semantics for a directory handle differ enough from POSIX fsync that pretending otherwise would be misleading, and this seam's Windows story is already file-fsync-only.
| dir | Directory whose entries were just mutated. A path::parent_path() of a bare relative filename (e.g. "queue.ndjson", with no directory component) is the empty path, not "." – treated here as the current directory, the same resolution the shell and every POSIX call already give an empty path's implicit caller, so a relative, directory-less path still gets its containing directory synced instead of failing open() with ENOENT on every call site that derives dir from parent_path(). |
Definition at line 153 of file file_io_ops.hpp.