miden-node-utils 0.14.7

Miden node's shared utilities
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
use std::path::Path;

/// Validates that a directory either does not exist (and creates it) or exists and is empty.
pub fn ensure_empty_directory(directory: &Path) -> anyhow::Result<()> {
    if fs_err::exists(directory)? {
        let is_empty = fs_err::read_dir(directory)?.next().is_none();
        anyhow::ensure!(is_empty, "{} exists but is not empty", directory.display());
    } else {
        fs_err::create_dir(directory)?;
    }
    Ok(())
}