Bash.Filesystem.ETS (Bash v0.6.0)

Copy Markdown View Source

In-memory filesystem implementation backed by an ETS table.

Implements Bash.Filesystem using ETS for fast, concurrent reads. Each entry in the table is a 4-tuple:

{path :: String.t(), type :: :file | :dir, content :: binary() | nil, stat :: File.Stat.t()}

Usage

# Create with POSIX skeleton directories pre-seeded
tid = Bash.Filesystem.ETS.new()
{:ok, session} = Bash.Session.new(filesystem: {Bash.Filesystem.ETS, tid})

# Create with custom seed files and directories
tid =
  Bash.Filesystem.ETS.new(%{
    "/home/user/.bashrc" => "export PATH=/usr/bin:\$PATH",
    "/usr/local/bin/myscript" => %{content: "#!/bin/bash\necho hi", mode: 0o755},
    "/var/data" => {:dir, nil}
  })

{:ok, session} = Bash.Session.new(filesystem: {Bash.Filesystem.ETS, tid})

Magic device paths

/dev/null, /dev/stdin, /dev/stdout, and /dev/stderr are intercepted at the callback level and never stored in the ETS table. /dev/null is readable (returns ""), while /dev/stdout and /dev/stderr return {:error, :eacces} on read.

ETS table lifecycle

The caller owns the ETS table and is responsible for deleting it via :ets.delete/1 when it is no longer needed.

Summary

Functions

Creates a new ETS table seeded with the POSIX skeleton directories.

Creates a new ETS table seeded with POSIX skeleton dirs plus the given seed map.

Functions

new()

@spec new() :: :ets.tid()

Creates a new ETS table seeded with the POSIX skeleton directories.

The table is created with :public access and {:keypos, 1} so the path string is the lookup key.

new(seed)

@spec new(seed :: map()) :: :ets.tid()

Creates a new ETS table seeded with POSIX skeleton dirs plus the given seed map.

Seed value forms:

  • "content" — a regular file with mode 0o644
  • %{content: "...", mode: 0o755} — a regular file with explicit mode (defaults to 0o644)
  • {:dir, nil} — an empty directory with mode 0o755

Parent directories are auto-created for all seeded paths.