add support for mkdir and rm and code cleanup

This commit is contained in:
Alex Zenla
2024-01-08 14:13:51 -08:00
parent 710282674a
commit f8938ac2c6
5 changed files with 135 additions and 50 deletions

View File

@ -4,21 +4,24 @@ use xsd::client::XsdClient;
fn list_recursive(client: &mut XsdClient, level: usize, path: &str) -> Result<(), XsdBusError> {
let children = match client.list(path) {
Ok(children) => children,
Err(error) => return if error.to_string() == "EINVAL" {
Ok(())
} else {
Err(error)
Err(error) => {
return if error.to_string() == "EINVAL" {
Ok(())
} else {
Err(error)
}
}
};
for child in children {
let full = format!("{}/{}", if path == "/" {
""
} else {
path
}, child);
let full = format!("{}/{}", if path == "/" { "" } else { path }, child);
let value = client.read(full.as_str())?;
println!("{}{} = {:?}", " ".repeat(level), child, String::from_utf8(value)?);
println!(
"{}{} = {:?}",
" ".repeat(level),
child,
String::from_utf8(value)?
);
list_recursive(client, level + 1, full.as_str())?;
}
Ok(())