View Source ExWal.FS protocol (ex_wal v0.3.0)

Summary

Types

t()

All the types that implement this protocol.

Functions

Create creates the named file for reading and writing. If a file already exists at the provided name, it's removed first ensuring the resulting file descriptor points to a new inode.

create_link creates a hard link to the file

list lists the files in the given directory.

Lock locks the given file, creating the file if necessary, and truncating the file if it already exists. The lock is an exclusive lock (a write lock), but locked files should neither be read from nor written to. Such files should have zero size and only exist to co-ordinate ownership across processes.

mkdir_all creates a directory and any necessary parents. The permission bits perm have the same semantics as for os.mkdir. If the directory already exists, mkdir_all does nothing.

open opens the named file for reading.

open_dir opens the named directory for syncing

open_read_write opens the named file for reading and writing. If the file does not exist, it is created.

remove a file

remove_all removes all files in a directory

rename renames a file

reuse_for_write attempts to reuse the file with oldname by renaming it to newname and opening it for writing without truncation. It is acceptable for the implementation to choose not to reuse oldname, and simply create the file with newname -- in this case the implementation should delete oldname. If the caller calls this function with an oldname that does not exist, the implementation may return an error.

stat returns the file info for the given file.

Types

@type file() :: ExWal.File.t()
@type t() :: term()

All the types that implement this protocol.

Functions

@spec create(t(), String.t()) :: {:ok, file()} | {:error, reason :: term()}

Create creates the named file for reading and writing. If a file already exists at the provided name, it's removed first ensuring the resulting file descriptor points to a new inode.

Link to this function

link(impl, old_name, new_name)

View Source
@spec link(impl :: t(), old_name :: String.t(), new_name :: String.t()) ::
  :ok | {:error, reason :: term()}

create_link creates a hard link to the file

@spec list(impl :: t(), name :: String.t()) ::
  {:ok, [binary()]} | {:error, reason :: term()}

list lists the files in the given directory.

@spec lock(impl :: t(), name :: String.t()) :: boolean()

Lock locks the given file, creating the file if necessary, and truncating the file if it already exists. The lock is an exclusive lock (a write lock), but locked files should neither be read from nor written to. Such files should have zero size and only exist to co-ordinate ownership across processes.

A nil Closer is returned if an error occurred. Otherwise, close that Closer to release the lock.

On Linux and OSX, a lock has the same semantics as fcntl(2)'s advisory locks. In particular, closing any other file descriptor for the same file will release the lock prematurely.

Attempting to lock a file that is already locked by the current process returns an error and leaves the existing lock untouched.

Lock is not yet implemented on other operating systems, and calling it

@spec mkdir_all(impl :: t(), name :: String.t()) :: :ok | {:error, reason :: term()}

mkdir_all creates a directory and any necessary parents. The permission bits perm have the same semantics as for os.mkdir. If the directory already exists, mkdir_all does nothing.

Link to this function

open(impl, name, opts \\ [])

View Source
@spec open(impl :: t(), name :: String.t(), opts :: Keyword.t()) ::
  {:ok, file()} | {:error, reason :: term()}

open opens the named file for reading.

@spec open_dir(impl :: t(), name :: String.t()) ::
  {:ok, file()} | {:error, reason :: term()}

open_dir opens the named directory for syncing

Link to this function

open_read_write(impl, name, opts \\ [])

View Source
@spec open_read_write(impl :: t(), name :: String.t(), opts :: Keyword.t()) ::
  {:ok, file()} | {:error, reason :: term()}

open_read_write opens the named file for reading and writing. If the file does not exist, it is created.

@spec remove(impl :: t(), name :: String.t()) :: :ok | {:error, reason :: term()}

remove a file

@spec remove_all(impl :: t(), name :: String.t()) :: :ok | {:error, reason :: term()}

remove_all removes all files in a directory

Link to this function

rename(impl, old_name, new_name)

View Source
@spec rename(impl :: t(), old_name :: String.t(), new_name :: String.t()) ::
  :ok | {:error, reason :: term()}

rename renames a file

Link to this function

reuse_for_write(impl, old_name, new_name)

View Source
@spec reuse_for_write(impl :: t(), old_name :: String.t(), new_name :: String.t()) ::
  {:ok, file()} | {:error, reason :: term()}

reuse_for_write attempts to reuse the file with oldname by renaming it to newname and opening it for writing without truncation. It is acceptable for the implementation to choose not to reuse oldname, and simply create the file with newname -- in this case the implementation should delete oldname. If the caller calls this function with an oldname that does not exist, the implementation may return an error.

@spec stat(impl :: t(), name :: String.t()) ::
  {:ok, File.Stat.t()} | {:error, reason :: term()}

stat returns the file info for the given file.