Crate liboverdrop

source ·
Expand description

Simple library to handle configuration fragments.

This crate provides helpers to scan configuration fragments on disk. The goal is to help in writing Linux services which are shipped as part of a Reproducible OS. Its name derives from overlays and dropins (base directories and configuration fragments).

The main entrypoint is scan. It scans for configuration fragments across multiple directories (with increasing priority), following these rules:

  • fragments are identified by unique filenames, lexicographically (e.g. 50-default-limits.conf).
  • in case of name duplication, last directory wins (e.g. /etc/svc/custom.conf can override /usr/lib/svc/custom.conf).
  • a fragment symlinked to /dev/null is used to ignore any previous fragment with the same filename.

Example

// Scan for fragments under:
//  * /usr/lib/my-crate/config.d/*.toml
//  * /run/my-crate/config.d/*.toml
//  * /etc/my-crate/config.d/*.toml

let base_dirs = [
    "/usr/lib",
    "/run",
    "/etc",
];
let fragments = liboverdrop::scan(&base_dirs, "my-crate/config.d", &["toml"], false);

for (filename, filepath) in fragments {
    println!("fragment '{}' located at '{}'", filename.to_string_lossy(), filepath.display());
}

Migrating from liboverdrop 0.0.x

The signature changed from

let base_dirs: Vec<String> = vec![/**/];
let shared_path: &str = "config.d";
let allowed_extensions: Vec<String> = vec![/**/];
for (basename, filepath) in FragmentScanner::new(
                                base_dirs, shared_path, false, allowed_extensions).scan() {
    // basename: String
    // filepath: PathBuf
}

to

let base_dirs: IntoIterator<Item = AsRef<Path>> = /* could be anything */;
let shared_path: AsRef<Path> = /* ... */;
let allowed_extensions: &[AsRef<OsStr>] = &[/* ... */];
for (basename, filepath) in liboverdrop::scan(
                                base_dirs, shared_path, allowed_extensions, false) {
    // basename: OsString
    // filepath: PathBuf
}

When updating, re-consider if you need to allocate any argument now, since they can all be literals or borrowed.

Functions

Scan unique configuration fragments from the configuration directories specified.