Roux.Sources (roux v0.2.2)

Copy Markdown View Source

Files as inputs: sync/5 brings an input keyed by file up to date with what is on disk, reading only what may have changed.

A file whose size and modification time match the last run's (the metadata a session's manifest holds, Roux.Session) is not read — the staleness check Mix makes. Anything else is read and hashed, and set as the input: Roux.Input.set/5's own equality check absorbs a file rewritten with the same content, so a touch or a byte-identical rebuild changes nothing downstream. A file written within the last recent: seconds is always read: a modification time has one-second granularity, and a quick edit-and-rerun can rewrite a file in the same second with the same size.

Keys whose files are gone are removed from the input (Roux.GC.mark_input_removed/3).

Summary

Types

What sync/5 keeps of a file: the prefilter's stamp and the content's hash.

What a sync did: the metadata to keep for the next (%{path => meta}), the keys whose input changed, and the keys removed.

Functions

Syncs input with the files of files (%{key => path}), given the metadata the last sync returned (prior).

Types

meta()

@type meta() :: %{mtime: integer(), size: non_neg_integer(), hash: term()}

What sync/5 keeps of a file: the prefilter's stamp and the content's hash.

result()

@type result() :: %{
  meta: %{optional(Path.t()) => meta()},
  changed: [term()],
  removed: [term()]
}

What a sync did: the metadata to keep for the next (%{path => meta}), the keys whose input changed, and the keys removed.

Functions

sync(db, input, files, prior, opts \\ [])

@spec sync(
  Roux.Database.t(),
  atom(),
  %{optional(term()) => Path.t()},
  map(),
  keyword()
) :: result()

Syncs input with the files of files (%{key => path}), given the metadata the last sync returned (prior).

Options

  • :hash — the hash of a file's content (default :erlang.md5/1): two contents with one hash are one value;
  • :value — the input's value for a file, given %{key: key, path: path, hash: hash, content: content} (default %{path: path, hash: hash});
  • :recent — seconds within which a file is read whatever its stamp (default 2).