LemonCore.Paths (lemon_core v0.1.0)

View Source

Filesystem layout used by lemon_core.

Everything the library reads or writes by convention hangs off two directories: a per-user state directory (~/.lemon) and a per-project one (<project>/.lemon). Both are configurable, and the defaults are the reference runtime's layout, so an application embedding lemon_core can put its state somewhere that is not named after Lemon:

config :lemon_core, :paths,
  state_dir: ".myapp",
  config_file: "config.toml"

Individual locations can also be pinned outright, which wins over the composed default:

config :lemon_core, :paths,
  home_state_dir: "/var/lib/myapp",
  global_config: "/etc/myapp/config.toml"

Every function also accepts the same keys as options, which is how callers (and tests) scope a lookup to a temporary home without touching app env.

Not covered here

The secrets master key file has its own :key_file setting — see LemonCore.Secrets.KeyProvider, which resolves ~ against a caller-supplied home so that a scoped HOME cannot leak into the real key file.

Summary

Functions

Directory holding filesystem-rollback checkpoints.

Name of the config file inside a state directory, config.toml by default.

Global config file, ~/.lemon/config.toml by default.

The user's home directory: the :home_dir option, then $HOME.

A path inside the per-user state directory.

Per-user state directory, ~/.lemon by default.

Project config file for cwd, <cwd>/.lemon/config.toml by default.

A path inside a project's state directory.

Per-project state directory, <cwd>/.lemon by default.

Name of the state directory, .lemon by default.

Types

opts()

@type opts() :: keyword()

Functions

checkpoint_dir(opts \\ [])

@spec checkpoint_dir(opts()) :: String.t()

Directory holding filesystem-rollback checkpoints.

Deliberately under the system temp directory rather than the state directory: checkpoints are short-lived rollback material for an in-flight session, and losing them on reboot is the intended behaviour. Hosts that want them to survive can point :checkpoint_dir at a durable location.

Resolved per call — a module attribute here would freeze the build machine's temp directory into a release.

iex> LemonCore.Paths.checkpoint_dir(checkpoint_dir: "/srv/checkpoints")
"/srv/checkpoints"

config_file_name(opts \\ [])

@spec config_file_name(opts()) :: String.t()

Name of the config file inside a state directory, config.toml by default.

global_config(opts \\ [])

@spec global_config(opts()) :: String.t()

Global config file, ~/.lemon/config.toml by default.

home_dir(opts \\ [])

@spec home_dir(opts()) :: String.t()

The user's home directory: the :home_dir option, then $HOME.

home_path(segments, opts \\ [])

@spec home_path([String.t()] | String.t(), opts()) :: String.t()

A path inside the per-user state directory.

iex> LemonCore.Paths.home_path(["store"], home_dir: "/home/x")
"/home/x/.lemon/store"

home_state_dir(opts \\ [])

@spec home_state_dir(opts()) :: String.t()

Per-user state directory, ~/.lemon by default.

project_config(cwd, opts \\ [])

@spec project_config(Path.t(), opts()) :: String.t()

Project config file for cwd, <cwd>/.lemon/config.toml by default.

project_path(cwd, segments, opts \\ [])

@spec project_path(Path.t(), [String.t()] | String.t(), opts()) :: String.t()

A path inside a project's state directory.

iex> LemonCore.Paths.project_path("/srv/app", ["proofs"])
"/srv/app/.lemon/proofs"

project_state_dir(cwd, opts \\ [])

@spec project_state_dir(Path.t(), opts()) :: String.t()

Per-project state directory, <cwd>/.lemon by default.

state_dir_name(opts \\ [])

@spec state_dir_name(opts()) :: String.t()

Name of the state directory, .lemon by default.