z_config_files (zotonic_core v1.0.0-rc.14)

Generic support for finding and parsing config files.

Link to this section 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

Link to this section Functions

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

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

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

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

  1. Linux: $HOME/.cache/zotonic/
  2. macOS: $HOME/Library/Caches/zotonic/
-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 zotonic_config_dir
  2. The environment variable ZOTONIC_CONFIG_DIR
  3. The directory $HOME/.zotonic
  4. The directory /etc/zotonic (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: $HOME/.config/zotonic/config/1/
  2. macOS: $HOME/Library/Application Support/zotonic/config/1/
Link to this function

config_dir(Node)

-spec config_dir(node()) -> {ok, file:filename_all()} | {error, term()}.
-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.
-spec data_dir() -> {ok, file:filename_all()} | {error, term()}.

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

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

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

  1. Linux: $HOME/.local/share/zotonic/
  2. macOS: $HOME/Library/Application Support/zotonic/
-spec files(file:filename_all()) -> [file:filename_all()].
List all (regular) files in a directory, skip hidden and temp files.
Link to this function

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.
-spec log_dir() -> {ok, file:filename_all()} | {error, term()}.

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

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

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

  1. Linux: $HOME/.cache/zotonic/log/
  2. macOS: $HOME/Library/Logs/zotonic//
-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 ZOTONIC_SECURITY_DIR
  2. The directory $HOME/.zotonic/security
  3. The directory /etc/zotonic/security (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 security is used:

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