File-system operations inside a sandbox.
The full facade over the toolbox file-system API — writing/reading, directories, metadata, permissions, search, and text replacement:
:ok = ExDaytona.FS.mkdir(sandbox, "/workspace/data")
:ok = ExDaytona.FS.write_file(sandbox, "/workspace/data/hello.txt", "hi")
{:ok, "hi"} = ExDaytona.FS.read_file(sandbox, "/workspace/data/hello.txt")
{:ok, files} = ExDaytona.FS.list_files(sandbox, "/workspace/data")
{:ok, %ExDaytona.Model.FileInfo{}} = ExDaytona.FS.stat(sandbox, "/workspace/data/hello.txt")
{:ok, paths} = ExDaytona.FS.search(sandbox, "/workspace", "*.txt") # glob on names
{:ok, matches} = ExDaytona.FS.grep(sandbox, "/workspace", "TODO") # text in contents
:ok = ExDaytona.FS.move(sandbox, "/workspace/data/hello.txt", "/workspace/hello.txt")
:ok = ExDaytona.FS.delete(sandbox, "/workspace/data", recursive: true)ExDaytona.Sandbox.write_file/3, read_file/2, and list_files/2
delegate here — use whichever module reads better at the call site.
Summary
Functions
Set permissions/ownership on path.
Delete the file or directory at path.
Download the file at remote_path to a local path.
Search file contents under path for pattern. Returns
{:ok, [%ExDaytona.Model.Match{file, line, content}]}.
List files at path (default: the working directory). Returns
{:ok, [%ExDaytona.Model.FileInfo{}]}.
Create a directory (and parents) at path.
Move (or rename) source to destination.
Read the file at path. Returns {:ok, binary}.
Replace pattern with replacement across files. Returns
{:ok, [%ExDaytona.Model.ReplaceResult{file, success, error}]} — a
per-file report, not all-or-nothing.
Find files under path whose names match the glob pattern.
Returns {:ok, [path]}.
File metadata for path as an ExDaytona.Model.FileInfo.
Upload a local file to remote_path inside the sandbox.
Write content to path inside the sandbox (parent directories are
created by the API). Returns :ok.
Write several files in one call: entries is a list of
{path, content} tuples. Stops at the first failure.
Functions
@spec chmod(ExDaytona.Sandbox.t(), String.t(), keyword()) :: :ok | {:error, ExDaytona.Error.t()}
Set permissions/ownership on path.
Options: :mode (e.g. "644"), :owner, :group — at least one is
required.
@spec delete(ExDaytona.Sandbox.t(), String.t(), keyword()) :: :ok | {:error, ExDaytona.Error.t()}
Delete the file or directory at path.
Options: :recursive — required to delete non-empty directories.
@spec download(ExDaytona.Sandbox.t(), String.t(), Path.t()) :: :ok | {:error, ExDaytona.Error.t()}
Download the file at remote_path to a local path.
@spec grep(ExDaytona.Sandbox.t(), String.t(), String.t()) :: {:ok, [ExDaytona.Model.Match.t()]} | {:error, ExDaytona.Error.t()}
Search file contents under path for pattern. Returns
{:ok, [%ExDaytona.Model.Match{file, line, content}]}.
@spec list_files(ExDaytona.Sandbox.t(), String.t() | nil) :: {:ok, [ExDaytona.Model.FileInfo.t()]} | {:error, ExDaytona.Error.t()}
List files at path (default: the working directory). Returns
{:ok, [%ExDaytona.Model.FileInfo{}]}.
@spec mkdir(ExDaytona.Sandbox.t(), String.t(), keyword()) :: :ok | {:error, ExDaytona.Error.t()}
Create a directory (and parents) at path.
Options: :mode — permission string (default "755").
@spec move(ExDaytona.Sandbox.t(), String.t(), String.t()) :: :ok | {:error, ExDaytona.Error.t()}
Move (or rename) source to destination.
@spec read_file(ExDaytona.Sandbox.t(), String.t()) :: {:ok, binary()} | {:error, ExDaytona.Error.t()}
Read the file at path. Returns {:ok, binary}.
@spec replace(ExDaytona.Sandbox.t(), [String.t()], String.t(), String.t()) :: {:ok, [ExDaytona.Model.ReplaceResult.t()]} | {:error, ExDaytona.Error.t()}
Replace pattern with replacement across files. Returns
{:ok, [%ExDaytona.Model.ReplaceResult{file, success, error}]} — a
per-file report, not all-or-nothing.
@spec search(ExDaytona.Sandbox.t(), String.t(), String.t()) :: {:ok, [String.t()]} | {:error, ExDaytona.Error.t()}
Find files under path whose names match the glob pattern.
Returns {:ok, [path]}.
@spec stat(ExDaytona.Sandbox.t(), String.t()) :: {:ok, ExDaytona.Model.FileInfo.t()} | {:error, ExDaytona.Error.t()}
File metadata for path as an ExDaytona.Model.FileInfo.
@spec upload(ExDaytona.Sandbox.t(), Path.t(), String.t()) :: :ok | {:error, ExDaytona.Error.t()}
Upload a local file to remote_path inside the sandbox.
@spec write_file(ExDaytona.Sandbox.t(), String.t(), iodata()) :: :ok | {:error, ExDaytona.Error.t()}
Write content to path inside the sandbox (parent directories are
created by the API). Returns :ok.
@spec write_files(ExDaytona.Sandbox.t(), [{String.t(), iodata()}]) :: :ok | {:error, ExDaytona.Error.t()}
Write several files in one call: entries is a list of
{path, content} tuples. Stops at the first failure.