Minga.Session.Swap.Recovery (Minga v0.1.0)

Copy Markdown View Source

Scans the swap directory for orphaned swap files and determines which ones are recoverable.

A swap file is recoverable when:

  • It parses correctly (valid MINGA_SWAP_V1 header)
  • The OS PID that wrote it is no longer alive (kill -0 check)
  • The original file still exists on disk

Swap files written by a still-running Minga instance are left alone. Corrupt swap files are cleaned up automatically.

Summary

Types

A recoverable swap file entry.

Options for scan and recovery operations.

Functions

Deletes a swap file (user declined recovery).

Recovers content from a swap file.

Scans the swap directory and returns a list of recoverable entries.

Types

entry()

@type entry() :: %{path: String.t(), swap_path: String.t(), swap_mtime: integer()}

A recoverable swap file entry.

option()

@type option() :: {:swap_dir, String.t()} | {:pid_alive?, (integer() -> boolean())}

Options for scan and recovery operations.

Functions

discard(swap_path)

@spec discard(String.t()) :: :ok

Deletes a swap file (user declined recovery).

recover(swap_path)

@spec recover(String.t()) :: {:ok, String.t(), binary()} | {:error, term()}

Recovers content from a swap file.

Returns {:ok, file_path, content} where content is the unsaved buffer text. The caller is responsible for opening a buffer with this content and marking it as dirty. The swap file is deleted after successful recovery.

scan(opts \\ [])

@spec scan([option()]) :: [entry()]

Scans the swap directory and returns a list of recoverable entries.

Each entry contains the original file path, the swap file path, and the swap file's mtime. The caller decides what to do with them (show a recovery prompt, auto-recover, etc.).

Options

  • :swap_dir - override the default swap directory (for testing)
  • :pid_alive? - override the PID liveness check (for testing)