Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d2374aaf authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "PDL: let ‘find_binary’ helper return a ‘Result’"

parents 14836669 5b6bbcce
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -8,18 +8,23 @@ use tempfile::NamedTempFile;

/// Search for a binary in `$PATH` or as a sibling to the current
/// executable (typically the test binary).
fn find_binary(name: &str) -> Option<std::path::PathBuf> {
fn find_binary(name: &str) -> Result<std::path::PathBuf, String> {
    let mut current_exe = std::env::current_exe().unwrap();
    current_exe.pop();
    let paths = std::env::var_os("PATH").unwrap();
    for mut path in std::iter::once(current_exe).chain(std::env::split_paths(&paths)) {
    for mut path in std::iter::once(current_exe.clone()).chain(std::env::split_paths(&paths)) {
        path.push(name);
        if path.exists() {
            return Some(path);
            return Ok(path);
        }
    }

    None
    Err(format!(
        "could not find '{}' in the directory of the binary ({}) or in $PATH ({})",
        name,
        current_exe.to_string_lossy(),
        paths.to_string_lossy(),
    ))
}

/// Parse a string fragment as a PDL file.