Ferricstore.FS (ferricstore v0.3.3)

Copy Markdown View Source

Thin Elixir wrapper over Ferricstore.Bitcask.NIF.fs_* that:

  • Preserves bang-style raise semantics (touch!, mkdir_p!, rm!, rm_rf!) matching File.* call sites we're replacing.
  • Keeps the non-bang variants returning :ok | {:error, {kind, msg}} so callers using with / case can pattern-match on the stable atom kinds.

All ops run on BEAM's Normal scheduler via a Rust NIF — NOT on the :prim_file async-thread pool. This keeps dirty-scheduler accounting out of our crash dumps and makes scheduler-utilization observable.

For potentially long operations (rm_rf of a large tree), the caller owns the waiting: fs_rm_rf_async returns immediately and delivers a :tokio_complete message. The rm_rf!/1 helper here blocks the calling process until the message arrives — keeping the call-site shape compatible with File.rm_rf!/1.

Summary

Types

err_kind()

@type err_kind() ::
  :not_found
  | :already_exists
  | :permission_denied
  | :not_a_directory
  | :is_a_directory
  | :directory_not_empty
  | :invalid_path
  | :other

fs_error()

@type fs_error() :: {:error, {err_kind(), binary()}}

Functions

dir?(path)

@spec dir?(binary()) :: boolean()

exists?(path)

@spec exists?(binary()) :: boolean()

ls(path)

@spec ls(binary()) :: {:ok, [binary()]} | fs_error()

ls!(path)

@spec ls!(binary()) :: [binary()]

mkdir_p(path)

@spec mkdir_p(binary()) :: :ok | fs_error()

mkdir_p!(path)

@spec mkdir_p!(binary()) :: :ok

rename(old_path, new_path)

@spec rename(binary(), binary()) :: :ok | fs_error()

rename!(old_path, new_path)

@spec rename!(binary(), binary()) :: :ok

rm(path)

@spec rm(binary()) :: :ok | fs_error()

rm!(path)

@spec rm!(binary()) :: :ok

rm_rf(path)

@spec rm_rf(binary()) :: :ok | fs_error()

Recursive remove, blocking the caller until the async NIF completes.

Idempotent: removing a non-existent path is :ok. Never raises for missing paths — matches File.rm_rf/1 (returns {:ok, []} there).

rm_rf!(path)

@spec rm_rf!(binary()) :: :ok

touch(path)

@spec touch(binary()) :: :ok | fs_error()

touch!(path)

@spec touch!(binary()) :: :ok