Lets embedder code override how database files are probed and deleted. Pass an instance to the sqlite::connection constructor to intercept filesystem operations (e.g., implementing a virtual FS or sandbox checks).

Use cases

  • Use it to veto destructive opens: deny open_mode::always_create outside a whitelist.
  • Bridge SQLite to non-standard storage (encrypted volumes, cloud buckets) by mapping the DB path to your abstraction before SQLite touches the disk.
  • Return precise std::error_code values so callers can distinguish between “file missing” and “permission denied”.

Example usage

class sandbox_fs : public sqlite::filesystem_adapter {
public:
    explicit sandbox_fs(std::filesystem::path root) : root_(std::move(root)) {}

    filesystem_entry status(std::filesystem::path const & path) const override {
        auto real = root_ / sanitize(path);
        std::error_code ec;
        auto stat = std::filesystem::symlink_status(real, ec);
        if (!ec && !within_root(real)) {
            ec = make_error_code(std::errc::permission_denied);
        }
        return {stat, ec};
    }

    bool remove(std::filesystem::path const & path, std::error_code & ec) const override {
        auto real = root_ / sanitize(path);
        if (!within_root(real)) {
            ec = make_error_code(std::errc::permission_denied);
            return false;
        }
        return std::filesystem::remove(real, ec);
    }
private:
    // ...
};

sqlite::connection db{"tenant.db",
                      sqlite::open_mode::open_or_create,
                      std::make_shared<sandbox_fs>("/srv/tenants/acme")};

The adapter sits in a shared_ptr, so you can hand the same policy object to every connection without worrying about lifetimes.

Types

TypeDescription
struct filesystem_entryHolds std::filesystem::file_status status and std::error_code error results.
struct filesystem_adapterAbstract base with status() and remove() pure virtuals.
class default_filesystem_adapterConcrete implementation that defers to std::filesystem.
using filesystem_adapter_ptr = std::shared_ptr<filesystem_adapter>Shared pointer alias used by connection.

Interface

MemberDescription
virtual filesystem_entry status(std::filesystem::path const& target) const = 0Return file metadata plus an error code if the probe failed.
virtual bool remove(std::filesystem::path const& target, std::error_code& ec) const = 0Attempt to remove target; set ec to describe failures.
filesystem_entry default_filesystem_adapter::status(...)Calls std::filesystem::symlink_status.
bool default_filesystem_adapter::remove(...)Calls std::filesystem::remove.