Minga.Buffer.SaveState (Minga v0.1.0)

Copy Markdown View Source

Tracks whether a buffer has diverged from its last saved baseline.

This module owns the pure save-point model: mutation versions, the saved version, dirty calculation, and the saved file fingerprint used by persistence conflict checks. It does not read or write files; Minga.Buffer.Persistence still owns storage I/O.

Summary

Functions

Accepts replacement content as a new saved baseline and advances the mutation version once.

Acknowledges the latest disk metadata while preserving the saved content fingerprint.

Returns true when the backing file differs from the saved baseline.

Fingerprints content with the algorithm used to track saved file baselines.

Returns whether the buffer differs from its saved version.

Returns the saved content fingerprint, if one is known.

Returns the saved file size.

Returns a clean save state for content loaded from storage.

Marks the buffer as changed and advances the mutation version.

Records the current version as the saved baseline.

Returns the saved file mtime.

Returns a clean save state for a new buffer with no saved file baseline.

Records a content change that should not by itself make a clean buffer dirty.

Restores the mutation version and recalculates dirty state from the saved version.

Returns a saved-content fingerprint only when a path and concrete mtime make the baseline meaningful.

Returns the saved baseline version.

Returns the current mutation version.

Types

metadata()

@type metadata() :: {mtime :: integer() | nil, size :: non_neg_integer() | nil}

saved_content_status()

@type saved_content_status() :: :same | :changed | :unknown

t()

@opaque t()

Functions

accept_saved_content(save_state, arg, content)

@spec accept_saved_content(t(), metadata(), String.t()) :: t()

Accepts replacement content as a new saved baseline and advances the mutation version once.

acknowledge_disk_metadata(save_state, arg)

@spec acknowledge_disk_metadata(t(), metadata()) :: t()

Acknowledges the latest disk metadata while preserving the saved content fingerprint.

changed_since_saved?(save_state, disk_mtime, disk_size, status)

@spec changed_since_saved?(
  t(),
  integer() | nil,
  non_neg_integer() | nil,
  saved_content_status()
) :: boolean()

Returns true when the backing file differs from the saved baseline.

content_fingerprint(content)

@spec content_fingerprint(String.t()) :: binary()

Fingerprints content with the algorithm used to track saved file baselines.

dirty?(save_state)

@spec dirty?(t()) :: boolean()

Returns whether the buffer differs from its saved version.

file_hash(save_state)

@spec file_hash(t()) :: binary() | nil

Returns the saved content fingerprint, if one is known.

file_size(save_state)

@spec file_size(t()) :: non_neg_integer() | nil

Returns the saved file size.

loaded(path, arg, content)

@spec loaded(String.t() | nil, metadata(), String.t()) :: t()

Returns a clean save state for content loaded from storage.

mark_changed(save_state)

@spec mark_changed(t()) :: t()

Marks the buffer as changed and advances the mutation version.

mark_saved(save_state, arg, content)

@spec mark_saved(t(), metadata(), String.t()) :: t()

Records the current version as the saved baseline.

mtime(save_state)

@spec mtime(t()) :: integer() | nil

Returns the saved file mtime.

new()

@spec new() :: t()

Returns a clean save state for a new buffer with no saved file baseline.

record_clean_change(save_state)

@spec record_clean_change(t()) :: t()

Records a content change that should not by itself make a clean buffer dirty.

restore_version(save_state, version)

@spec restore_version(t(), non_neg_integer()) :: t()

Restores the mutation version and recalculates dirty state from the saved version.

saved_content_fingerprint(path, mtime, content)

@spec saved_content_fingerprint(String.t() | nil, integer() | nil, String.t()) ::
  binary() | nil

Returns a saved-content fingerprint only when a path and concrete mtime make the baseline meaningful.

saved_version(save_state)

@spec saved_version(t()) :: non_neg_integer()

Returns the saved baseline version.

version(save_state)

@spec version(t()) :: non_neg_integer()

Returns the current mutation version.