Skip to main content

load_config

Function load_config 

Source
pub fn load_config(path: &Path) -> Result<Config, ConfigError>
Expand description

Load config from a file path.

Opens the file once and uses the same file descriptor for both the size check and the read, eliminating the TOCTOU race that exists when metadata() and read_to_string() open the file separately.

On Unix, O_NOFOLLOW rejects symlinks at the final path component, and O_NONBLOCK prevents open() from blocking on a named pipe with no writer. Non-regular files (device nodes, FIFOs) can bypass the size guard by reporting len() == 0, so they are rejected via is_file() immediately after open.