fn wait_for_path(path: &std::path::Path) -> Result<(), anyhow::Error> {
    use {anyhow::format_err, fuchsia_zircon as zx};

    let svc_dir = path.parent().ok_or(format_err!("Invalid service path"))?;
    let svc_name = path.file_name().ok_or(format_err!("Invalid service name"))?;
    match fdio::watch_directory(
        &std::fs::File::open(&svc_dir)
            .map_err(|e| anyhow::format_err!("Failed to open service path: {}", e))?,
        zx::sys::ZX_TIME_INFINITE,
        |_event, found| if found == svc_name { Err(zx::Status::STOP) } else { Ok(()) },
    ) {
        zx::Status::STOP => Ok(()),
        zx::Status::PEER_CLOSED => wait_for_path(svc_dir),
        e => Err(format_err!(
            "Failed to find {:?} at path {} (watch_directory result = {})",
            svc_name,
            svc_dir.display(),
            e
        )),
    }
}
/// Waits for a file at the given path to exist using fdio Watcher APIs. The provided `path` is
/// split into a directory path and a file name, then a watcher is set up on the directory path. If
/// the directory path itself does not exist, then this function is called recursively to wait for
/// it to be created as well.
Waits for a file at the given path to exist using fdio Watcher APIs. The provided `path` is
split into a directory path and a file name, then a watcher is set up on the directory path. If
the directory path itself does not exist, then this function is called recursively to wait for
it to be created as well.
Waits for a file at the given path to exist using fdio Watcher APIs . The provided ` path ` is split into a directory path and a file name then a watcher is set up on the directory path . If the directory path itself does not exist then this function is called recursively to wait for it to be created as well .
fn wait_for_path(path: &std::path::Path) -> Result<(), anyhow::Error> {
    use {anyhow::format_err, fuchsia_zircon as zx};
    let svc_dir = path.parent().ok_or(format_err!("Invalid service path"))?;
    let svc_name = path.file_name().ok_or(format_err!("Invalid service name"))?;
    match fdio::watch_directory(
        &std::fs::File::open(&svc_dir)
            .map_err(|e| anyhow::format_err!("Failed to open service path: {}", e))?,
        zx::sys::ZX_TIME_INFINITE,
        |_event, found| if found == svc_name { Err(zx::Status::STOP) } else { Ok(()) },
    ) {
        zx::Status::STOP => Ok(()),
        zx::Status::PEER_CLOSED => wait_for_path(svc_dir),
        e => Err(format_err!(
            "Failed to find {:?} at path {} (watch_directory result = {})",
            svc_name,
            svc_dir.display(),
            e
        )),
    }
}
fn wait_for_path ( path : & std :: path :: Path ) -> Result < ( ) , anyhow :: Error > { use { anyhow :: format_err , fuchsia_zircon as zx } ; let svc_dir = path . parent ( ) . ok_or ( format_err ! ( " " ) ) ? ; let svc_name = path . file_name ( ) . ok_or ( format_err ! ( " " ) ) ? ; match fdio :: watch_directory ( & std :: fs :: File :: open ( & svc_dir ) . map_err ( | e | anyhow :: format_err ! ( " " e ) ) ? , zx :: sys :: ZX_TIME_INFINITE , | _event , found | if found == svc_name { Err ( zx :: Status :: STOP ) } else { Ok ( ( ) ) } , ) { zx :: Status :: STOP => Ok ( ( ) ) , zx :: Status :: PEER_CLOSED => wait_for_path ( svc_dir ) , e => Err ( format_err ! ( " " svc_name svc_dir display ( ) e ) ) , } }
Waits for a file at the given path to exist using fdio Watcher APIs.
Waits for a file at the given path to exist using fdio Watcher APIs .
path
&std::path::Path
path
&std::path::Path