fn find_ancestor_file()

in sdk/core/azure_core_test/src/lib.rs [186:206]


fn find_ancestor_file(dir: impl AsRef<Path>, name: &str) -> azure_core::Result<PathBuf> {
    for dir in dir.as_ref().ancestors() {
        let path = dir.join(name);
        if path.exists() {
            return Ok(path);
        }

        // Keep looking until we get to the repo root where `.git` is either a directory (primary repo) or file (worktree).
        let path = dir.join(".git");
        if path.exists() {
            return Err(azure_core::Error::message(
                ErrorKind::Io,
                format!("{name} not found under repo {}", dir.display()),
            ));
        }
    }
    Err(azure_core::Error::new::<std::io::Error>(
        azure_core::error::ErrorKind::Io,
        std::io::ErrorKind::NotFound.into(),
    ))
}