Engine → Core → file_system.h
vfs::file_system
| Type | Class |
| Namespace | conjure::core::vfs |
| Include File Path | engine/include/conjure/core/vfs/file_system.h |
| Source File Path | engine/src/core/vfs/file_system.cpp |
| API ↗ | Files and the virtual file system |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | file_system(); |
Important
Additional constructor overloads have been deleted.
Destructors
| Access | Signature | Description |
|---|---|---|
| public | virtual ~file_system(); |
Functions
Public
create_directories
create_directories[[nodiscard]] virtual result<void> create_directories(
std::string_view path) = 0;Creates a directory and every missing parent; an existing directory is not an error. ALREADY_EXISTS when a file occupies the path, IO_FAILURE when a file occupies one of the parents, INVALID_ARGUMENT when a segment of the path is not a portable name (header comment).
enumerate
enumerate[[nodiscard]] virtual result<void> enumerate(
std::string_view directory,
enumerate_flags flags,
const enumerate_callback &callback) = 0;Lists the entries of a directory in ascending path order, each as a path relative to the backend root ("dir/sub/file.txt"). NOT_FOUND when the directory is missing, INVALID_ARGUMENT when the path names a file.
exists
exists[[nodiscard]] virtual bool exists(
std::string_view path);True when stat succeeds.
is_read_only
is_read_only[[nodiscard]] virtual bool is_read_only() const noexcept;True when every mutating operation fails with PERMISSION_DENIED.
open_read
open_readOpens a file for random-access reads. NOT_FOUND when missing, INVALID_ARGUMENT for a directory.
read_file
read_file[[nodiscard]] virtual result<std::vector<std::byte>> read_file(
std::string_view path) = 0;Reads a whole file. NOT_FOUND when missing, INVALID_ARGUMENT for a directory.
read_text_file
read_text_file[[nodiscard]] virtual result<std::string> read_text_file(
std::string_view path);Reads a whole file as text. A leading UTF-8 byte order mark is dropped; nothing else is transcoded. Implemented on top of read_file.
remove
remove[[nodiscard]] virtual result<void> remove(
std::string_view path) = 0;Deletes a file or an empty directory. INVALID_STATE for a non-empty directory, INVALID_ARGUMENT for the root, NOT_FOUND when missing.
remove_all
remove_all[[nodiscard]] virtual result<void> remove_all(
std::string_view path);Deletes a file or a directory with everything inside it. INVALID_ARGUMENT for the root, NOT_FOUND when missing. The default walks the tree with enumerate and remove.
rename
rename[[nodiscard]] virtual result<void> rename(
std::string_view from,
std::string_view to) = 0;Moves a file or directory. An existing file at to is replaced (even while a reader holds it open); an existing directory there is ALREADY_EXISTS. The parent of to must exist (NOT_FOUND). Renaming an entry onto itself succeeds and changes nothing; renaming it onto another spelling of itself on a case-insensitive volume changes the case. to is a name this call creates, so it must be portable (header comment, INVALID_ARGUMENT, checked before from is looked up); from may be any name that exists.
stat
statDescribes an entry. "" describes the root. NOT_FOUND when missing.
write_file
write_file[[nodiscard]] virtual result<void> write_file(
std::string_view path,
std::span<const std::byte> data) = 0;Creates or truncates a file and writes data. Missing parent directories are created. INVALID_ARGUMENT when a directory occupies the path or a segment of it is not a portable name (header comment), IO_FAILURE when a file occupies one of the parents.
write_file_atomic
write_file_atomic[[nodiscard]] virtual result<void> write_file_atomic(
std::string_view path,
std::span<const std::byte> data) = 0;Like write_file, but the path never holds a partial file, for a concurrent reader or after a crash: the data goes to a temporary sibling ("<path>.tmp-<uuid>") that then replaces the target in one step. A backend that stores on a device flushes the temporary to it before the swap, so after a power cut the path holds the old contents or the new ones, never a torn file (the swap itself may be lost, which leaves the old contents and possibly the temporary). Two limits: a volume whose driver has no flush at all still takes the write, without this guarantee, and logs one warning per process; on macOS the flush is fsync, which hands the data to the drive without waiting for the drive's own write cache, so the guarantee there is only as strong as that cache. That flush costs milliseconds per call on an idle volume and far more on a busy one (on Linux ext4 each flush waits for a whole journal commit, other programs' data included): use write_file for output that can be regenerated.
write_text_file
write_text_file[[nodiscard]] result<void> write_text_file(
std::string_view path,
std::string_view text);Writes UTF-8 text with write_file.