Util (fnord v0.7.24)

View Source

Summary

Functions

Filters an enumerable asynchronously using the provided function. The function should return true for items to keep and false for items to discard. The result is a stream of items that passed the filter.

Convenience wrapper for Task.async_stream/3 with the default options for concurrency and timeout set to Application.get_env(:fnord, :workers) and :infinity, respectively.

Expands a given path to its absolute form, expanding . and ... If a root directory is provided, it will expand the path relative to that root. If no root is provided, it will expand the path relative to the current working directory. The root directory is expanded first, if provided (see Path.expand/2).

Shortcut for find_file_within_root(path, <cwd>). Returns {:error, :enoent} if the current working directory cannot be determined.

Finds a file within the specified root directory. It resolves symlinks for both the file path and the root directory. If the resolved file path is within the root directory, it returns {:ok, resolved_path}, otherwise {:error, :enoent}.

Returns true if the given path is within the specified root directory, false otherwise. Expands both the path and the root to their absolute forms, resolving symlinks, before performing the check.

Resolves a symlink to its final target. If the path is relative, it will first be expanded relative to the given root. If root is not provided, it will expand relative to the current working directory. If a circular symlink is detected, it returns {:error, :circular_symlink}. Otherwise, it returns the absolute, resolved path or the error tuple originating from File.lstat/1.

Converts all string keys in a map to atoms, recursively.

Types

async_cb()

@type async_cb() :: (async_item() -> any())

async_item()

@type async_item() :: {:ok, any()} | {:error, any()} | {:error, {any(), any()}}

Functions

async_filter(enumerable, fun)

Filters an enumerable asynchronously using the provided function. The function should return true for items to keep and false for items to discard. The result is a stream of items that passed the filter.

async_stream(enumerable, fun, options \\ [])

@spec async_stream(Enumerable.t(), async_cb(), Keyword.t()) :: Enumerable.t()

Convenience wrapper for Task.async_stream/3 with the default options for concurrency and timeout set to Application.get_env(:fnord, :workers) and :infinity, respectively.

expand_path(path, root \\ nil)

Expands a given path to its absolute form, expanding . and ... If a root directory is provided, it will expand the path relative to that root. If no root is provided, it will expand the path relative to the current working directory. The root directory is expanded first, if provided (see Path.expand/2).

find_file(path)

@spec find_file(binary()) :: {:ok, binary()} | {:error, :enoent}

Shortcut for find_file_within_root(path, <cwd>). Returns {:error, :enoent} if the current working directory cannot be determined.

find_file_within_root(path, root)

@spec find_file_within_root(binary(), binary()) :: {:ok, binary()} | {:error, :enoent}

Finds a file within the specified root directory. It resolves symlinks for both the file path and the root directory. If the resolved file path is within the root directory, it returns {:ok, resolved_path}, otherwise {:error, :enoent}.

format_number(int)

get_latest_version()

get_running_version()

path_within_root?(path, root)

@spec path_within_root?(binary(), binary()) :: boolean()

Returns true if the given path is within the specified root directory, false otherwise. Expands both the path and the root to their absolute forms, resolving symlinks, before performing the check.

resolve_symlink(path, root \\ nil)

@spec resolve_symlink(binary(), binary() | nil) ::
  {:ok, binary()} | {:error, :circular_symlink} | {:error, File.posix()}

Resolves a symlink to its final target. If the path is relative, it will first be expanded relative to the given root. If root is not provided, it will expand relative to the current working directory. If a circular symlink is detected, it returns {:error, :circular_symlink}. Otherwise, it returns the absolute, resolved path or the error tuple originating from File.lstat/1.

string_keys_to_atoms(list)

Converts all string keys in a map to atoms, recursively.