z_config_files (zotonic_core v1.0.0-rc.17)

Generic support for finding and parsing config files.

Summary

Functions

Find the default directory for cache files. Checks the following locations

Find the directory with the configuration files. Defaults to the OS specific directory for all configurations. This checks a list of possible locations

Read a config file, return a list of the contents. The file can be in erlang, yaml, or json format.

Find the default directory for data files. Checks the following locations

List all (regular) files in a directory, skip hidden and temp files.

List all (regular) files in a directory, skip hidden and temp files. Ensures the list of files is sorted in a consistent way.

Find the default directory for log files. Checks the following locations

Find the default directory for certificates and other secrets. Checks the following locations

List all zotonic config files in the zotonic config directory and the "config.d" subdirectory for the current node. Zotonic config files are "zotonic.*" files in the root of the config directory and all files the 'config.d' subdirectory.

List all zotonic config files in the zotonic config directory and the "config.d" subdirectory. Zotonic config files are "zotonic.*" files in the root of the config directory and all files the 'config.d' subdirectory.

Functions

cache_dir()

-spec cache_dir() -> {ok, file:filename_all()} | {error, term()}.

Find the default directory for cache files. Checks the following locations:

  1. The environment variable <tt>ZOTONIC_CACHE_DIR</tt>
  2. Local working directory <tt>caches</tt>
  3. The OS specific directory for application cache files

If no directory is found then the OS specific directory is used:

  1. Linux: <tt>$HOME/.cache/zotonic/</tt>
  2. macOS: <tt>$HOME/Library/Caches/zotonic/</tt>

config_dir()

-spec config_dir() -> {ok, file:filename_all()} | {error, term()}.

Find the directory with the configuration files. Defaults to the OS specific directory for all configurations. This checks a list of possible locations:

  1. The init argument <tt>zotonic_config_dir</tt>
  2. The environment variable <tt>ZOTONIC_CONFIG_DIR</tt>
  3. The directory <tt>$HOME/.zotonic</tt>
  4. The directory <tt>/etc/zotonic</tt> (only on Unix)
  5. The OS specific directory for application config files

In the last three cases subdirectories are also checked, in the following order:

  1. The complete Erlang node name
  2. The short node name without the server address
  3. The complete Zotonic version (eg. 1.2.3)
  4. The minor Zotonic version (eg. 1.2)
  5. The major Zotonic version (eg. 1)
  6. The directory itself, without any version

If no directory is found then the OS specific directory with the the major Zotonic version is used. Examples:

  1. Linux: <tt>$HOME/.config/zotonic/config/1/</tt>
  2. macOS: <tt>$HOME/Library/Application Support/zotonic/config/1/</tt>

config_dir(Node)

-spec config_dir(node()) -> {ok, file:filename_all()} | {error, term()}.

consult(File)

-spec consult(file:filename_all()) -> {ok, [map() | proplists:proplist()]} | {error, term()}.

Read a config file, return a list of the contents. The file can be in erlang, yaml, or json format.

data_dir()

-spec data_dir() -> {ok, file:filename_all()} | {error, term()}.

Find the default directory for data files. Checks the following locations:

  1. The environment variable <tt>ZOTONIC_DATA_DIR</tt>
  2. Local working directory <tt>data</tt>
  3. The OS specific directory for application data files

If no directory is found then the OS specific directory is used:

  1. Linux: <tt>$HOME/.local/share/zotonic/</tt>
  2. macOS: <tt>$HOME/Library/Application Support/zotonic/</tt>

files(Dir)

-spec files(file:filename_all()) -> [file:filename_all()].

List all (regular) files in a directory, skip hidden and temp files.

files(Dir, Wildcard)

-spec files(file:filename_all(), string()) -> [file:filename_all()].

List all (regular) files in a directory, skip hidden and temp files. Ensures the list of files is sorted in a consistent way.

log_dir()

-spec log_dir() -> {ok, file:filename_all()} | {error, term()}.

Find the default directory for log files. Checks the following locations:

  1. The environment variable <tt>ZOTONIC_LOG_DIR</tt>
  2. Local working directory <tt>logs</tt>
  3. The OS specific directory for application log files

If no directory is found then the OS specific directory is used:

  1. Linux: <tt>$HOME/.cache/zotonic/log/</tt>
  2. macOS: <tt>$HOME/Library/Logs/zotonic//</tt>

security_dir()

-spec security_dir() -> {ok, file:filename_all()} | {error, term()}.

Find the default directory for certificates and other secrets. Checks the following locations:

  1. The environment variable <tt>ZOTONIC_SECURITY_DIR</tt>
  2. The directory <tt>$HOME/.zotonic/security</tt>
  3. The directory <tt>/etc/zotonic/security</tt> (only on Unix)
  4. The OS specific directory for application config files

If no directory is found then the OS specific directory with the the subdirectory <tt>security</tt> is used:

  1. Linux: <tt>$HOME/.config/zotonic/security/</tt>
  2. macOS: <tt>$HOME/Library/Application Support/zotonic/security/</tt>

zotonic_config_files()

-spec zotonic_config_files() -> [file:filename()].

List all zotonic config files in the zotonic config directory and the "config.d" subdirectory for the current node. Zotonic config files are "zotonic.*" files in the root of the config directory and all files the 'config.d' subdirectory.

zotonic_config_files(Node)

-spec zotonic_config_files(node()) -> [file:filename()].

List all zotonic config files in the zotonic config directory and the "config.d" subdirectory. Zotonic config files are "zotonic.*" files in the root of the config directory and all files the 'config.d' subdirectory.