mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-06 22:51:31 +00:00
add support for mkdir and rm and code cleanup
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
use crate::bus::{XsdBusError, XsdSocket};
|
||||
use crate::sys::{XSD_DIRECTORY, XSD_READ};
|
||||
use crate::sys::{XSD_DIRECTORY, XSD_MKDIR, XSD_READ, XSD_RM, XSD_WRITE};
|
||||
use std::ffi::CString;
|
||||
|
||||
pub struct XsdClient {
|
||||
socket: XsdSocket,
|
||||
@ -13,11 +14,28 @@ impl XsdClient {
|
||||
|
||||
pub fn list(&mut self, path: &str) -> Result<Vec<String>, XsdBusError> {
|
||||
let response = self.socket.send_single(0, XSD_DIRECTORY, path)?;
|
||||
Ok(response.parse_string_vec()?)
|
||||
response.parse_string_vec()
|
||||
}
|
||||
|
||||
pub fn read(&mut self, path: &str) -> Result<Vec<u8>, XsdBusError> {
|
||||
let response = self.socket.send_single(0, XSD_READ, path)?;
|
||||
Ok(response.payload)
|
||||
}
|
||||
|
||||
pub fn write(&mut self, path: &str, data: Vec<u8>) -> Result<bool, XsdBusError> {
|
||||
let mut buffer = Vec::new();
|
||||
let path = CString::new(path)?;
|
||||
buffer.extend_from_slice(path.as_bytes_with_nul());
|
||||
buffer.extend_from_slice(data.as_slice());
|
||||
let response = self.socket.send(0, XSD_WRITE, buffer.as_slice())?;
|
||||
response.parse_bool()
|
||||
}
|
||||
|
||||
pub fn mkdir(&mut self, path: &str) -> Result<bool, XsdBusError> {
|
||||
self.socket.send_single(0, XSD_MKDIR, path)?.parse_bool()
|
||||
}
|
||||
|
||||
pub fn rm(&mut self, path: &str) -> Result<bool, XsdBusError> {
|
||||
self.socket.send_single(0, XSD_RM, path)?.parse_bool()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user