INNER CODE UNIT · Rust

Ok

ouch-org/ouch · src/sandbox/mod.rs:89

    if let Ok(c) = std::fs::canonicalize(path) {
        return c;
    }
    if let Some(parent) = path.parent()
        && let Ok(c) = std::fs::canonicalize(parent)
    {
        return c.join(path.file_name().unwrap_or_default());
    }
    path.to_path_buf()
}

/// Returns true if `target` is $HOME itself or an ancestor of it.
pub fn is_home_or_ancestor(target: &Path) -> bool {
    let Some(home) = std::env::var_os("HOME").map(PathBuf::from) else {
        return false;
    };
    let Ok(home) = std::fs::canonicalize(&home) else {
        return false;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…