mirror of
https://github.com/rust-vmm/vhost-device.git
synced 2025-12-26 22:48:17 +00:00
scmi: use PathBuf for socket path
clap can parse a PathBuf directly from the command line arguments, and paths are not always UTF-8. Use PathBuf instead of a String to allow for all valid filesystem paths. Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
This commit is contained in:
parent
ea750d7daf
commit
4ba64be44b
@ -39,6 +39,7 @@ mod vhu_scmi;
|
||||
use devices::common::{print_devices_help, DeviceDescription, DeviceProperties};
|
||||
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
process::exit,
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
@ -58,7 +59,7 @@ struct ScmiArgs {
|
||||
// Location of vhost-user Unix domain socket.
|
||||
// Required, unless one of the --help options is used.
|
||||
#[clap(short, long, help = "vhost-user socket to use (required)")]
|
||||
socket_path: Option<String>,
|
||||
socket_path: Option<PathBuf>,
|
||||
// Specification of SCMI devices to create.
|
||||
#[clap(short, long, help = "Devices to expose")]
|
||||
#[arg(num_args(1..))]
|
||||
@ -68,7 +69,7 @@ struct ScmiArgs {
|
||||
}
|
||||
|
||||
pub struct VuScmiConfig {
|
||||
socket_path: String,
|
||||
socket_path: PathBuf,
|
||||
devices: DeviceDescription,
|
||||
}
|
||||
|
||||
@ -76,10 +77,9 @@ impl TryFrom<ScmiArgs> for VuScmiConfig {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(cmd_args: ScmiArgs) -> Result<Self> {
|
||||
if cmd_args.socket_path.is_none() {
|
||||
let Some(socket_path) = cmd_args.socket_path else {
|
||||
return Result::Err("Required argument socket-path was not provided".to_string());
|
||||
}
|
||||
let socket_path = cmd_args.socket_path.unwrap().trim().to_string();
|
||||
};
|
||||
let mut devices: DeviceDescription = vec![];
|
||||
let device_iterator = cmd_args.device.iter();
|
||||
for d in device_iterator {
|
||||
@ -159,6 +159,7 @@ fn main() {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn test_command_line() {
|
||||
@ -173,7 +174,7 @@ mod tests {
|
||||
let params: Vec<&str> = params_string.split_whitespace().collect();
|
||||
let args: ScmiArgs = process_args(Parser::parse_from(params)).unwrap();
|
||||
let config = VuScmiConfig::try_from(args).unwrap();
|
||||
assert_eq!(config.socket_path, path);
|
||||
assert_eq!(&config.socket_path, Path::new(&path));
|
||||
let devices = vec![
|
||||
("dummy".to_owned(), DeviceProperties::new(vec![])),
|
||||
(
|
||||
|
||||
@ -587,7 +587,7 @@ mod tests {
|
||||
|
||||
fn make_backend() -> VuScmiBackend {
|
||||
let config = VuScmiConfig {
|
||||
socket_path: "/foo/scmi.sock".to_owned(),
|
||||
socket_path: "/foo/scmi.sock".into(),
|
||||
devices: vec![],
|
||||
};
|
||||
VuScmiBackend::new(&config).unwrap()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user