Behaviour and dispatcher for pluggable filesystem implementations.
The filesystem is stored in session state as a {module, config} tuple. Every
filesystem callback takes config as the first argument. This module provides
convenience functions that unwrap the tuple and dispatch to the appropriate
implementation.
Default
When no filesystem option is provided, sessions use
{Bash.Filesystem.LocalDisk, nil} which passes through to Elixir's File
and Erlang's :file modules.
Custom Implementations
Implement the Bash.Filesystem behaviour to provide a virtual filesystem:
defmodule MyVFS do
@behaviour Bash.Filesystem
@impl true
def exists?(config, path), do: ...
# ... implement all required callbacks
end
{:ok, session} = Bash.Session.new(filesystem: {MyVFS, my_config})
Summary
Types
Callbacks
@callback lstat(config :: term(), path :: String.t()) :: {:ok, File.Stat.t()} | {:error, term()}
@callback stat(config :: term(), path :: String.t()) :: {:ok, File.Stat.t()} | {:error, term()}
Functions
@spec lstat(t(), String.t()) :: {:ok, File.Stat.t()} | {:error, term()}
@spec stat(t(), String.t()) :: {:ok, File.Stat.t()} | {:error, term()}