Skip to content

Engine → Core → file_system.h

vfs::file_system

Syntax

class CONJURE_API file_system

Constructors

AccessSignatureDescription
publicfile_system();

Important

Additional constructor overloads have been deleted.

Destructors

AccessSignatureDescription
publicvirtual ~file_system();

Functions

Public

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

[[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

[[nodiscard]] virtual bool exists(
    std::string_view path);

True when stat succeeds.

is_read_only

[[nodiscard]] virtual bool is_read_only() const noexcept;

True when every mutating operation fails with PERMISSION_DENIED.

open_read

[[nodiscard]] virtual result<std::unique_ptr<file>> open_read(
    std::string_view path) = 0;

Opens a file for random-access reads. NOT_FOUND when missing, INVALID_ARGUMENT for a directory.

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

[[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

[[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

[[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

[[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

[[nodiscard]] virtual result<file_stat> stat(
    std::string_view path) = 0;

Describes an entry. "" describes the root. NOT_FOUND when missing.

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

[[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

[[nodiscard]] result<void> write_text_file(
    std::string_view path,
    std::string_view text);

Writes UTF-8 text with write_file.