Fil.AlreadyExistsError exception (Fil v0.2.0)

Copy Markdown View Source

A write, a copy or a move with if_exists: :error found a file already there. Read that file and decide again.

For a copy or a move, :path is the destination, and neither file changed: a move leaves the source where it was. Fil.LiveView returns it with reason: :before_upload when the file at the path of a direct upload is older than its upload URL, so the upload didn't write it (see Direct uploads).

iex> disk = Fil.disk(adapter: Fil.Adapter.Memory)
iex> Fil.write!(disk, "once.txt", "first")
iex> {:error, %Fil.AlreadyExistsError{}} = Fil.write(disk, "once.txt", "second", if_exists: :error)
iex> Fil.write!(disk, "draft.txt", "second")
iex> {:error, %Fil.AlreadyExistsError{path: "once.txt"}} =
...>   Fil.rename(disk, "draft.txt", "once.txt", if_exists: :error)
iex> Fil.read(disk, "draft.txt")
{:ok, "second"}

Summary

Types

t()

@type t() :: %Fil.AlreadyExistsError{
  __exception__: term(),
  disk: Fil.Disk.t() | nil,
  op: Fil.Op.name() | nil,
  path: String.t() | nil,
  reason: term()
}