Files
krata/libs/xen/xenstore/examples/list.rs

33 lines
1012 B
Rust
Raw Normal View History

2024-02-23 04:37:53 +00:00
use futures::executor::block_on;
2024-01-08 17:07:00 -08:00
use xenstore::client::{XsdClient, XsdInterface};
use xenstore::error::Result;
2024-01-08 17:07:00 -08:00
use xenstore::sys::XSD_ERROR_EINVAL;
2024-01-08 12:43:16 -08:00
fn list_recursive(client: &mut XsdClient, level: usize, path: &str) -> Result<()> {
2024-02-23 04:37:53 +00:00
let children = match block_on(client.list(path)) {
2024-01-08 12:43:16 -08:00
Ok(children) => children,
Err(error) => {
2024-01-08 14:16:33 -08:00
return if error.to_string() == XSD_ERROR_EINVAL.error {
Ok(())
} else {
Err(error)
}
2024-01-08 12:43:16 -08:00
}
};
for child in children {
let full = format!("{}/{}", if path == "/" { "" } else { path }, child);
2024-02-23 04:37:53 +00:00
let value = block_on(client.read_string(full.as_str()))?.expect("expected value");
println!("{}{} = {:?}", " ".repeat(level), child, value,);
2024-01-08 12:43:16 -08:00
list_recursive(client, level + 1, full.as_str())?;
}
Ok(())
}
2024-02-23 04:37:53 +00:00
#[tokio::main]
async fn main() -> Result<()> {
let mut client = XsdClient::open().await?;
2024-01-08 12:43:16 -08:00
list_recursive(&mut client, 0, "/")?;
Ok(())
}