Module z_config_files

Generic support for finding and parsing config files.

Copyright © 2019-2021 Marc Worrell

Authors: Marc Worrell (marc@worrell.nl).

Description

Generic support for finding and parsing config files.

Function Index

cache_dir/0Find the default directory for cache files.
config_dir/0Find the directory with the configuration files.
config_dir/1
consult/1Read a config file, return a list of the contents.
data_dir/0Find the default directory for data files.
files/1List all (regular) files in a directory, skip hidden and temp files.
files/2List all (regular) files in a directory, skip hidden and temp files.
log_dir/0Find the default directory for log files.
security_dir/0Find the default directory for certificates and other secrets.

Function Details

cache_dir/0

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/

config_dir/0

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/

config_dir/1

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

consult/1

consult(File::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/0

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/

files/1

files(Dir::file:filename_all()) -> [file:filename_all()]

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

files/2

files(Dir::file:filename_all(), Wildcard::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/0

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//

security_dir/0

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/


Generated by EDoc