diff --git a/crates/gpio/src/backend.rs b/crates/gpio/src/backend.rs index 872073b1d..256bdff64 100644 --- a/crates/gpio/src/backend.rs +++ b/crates/gpio/src/backend.rs @@ -6,10 +6,10 @@ // SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause use log::{error, info, warn}; -use std::num::ParseIntError; use std::process::exit; use std::sync::{Arc, RwLock}; use std::thread::{spawn, JoinHandle}; +use std::{num::ParseIntError, path::PathBuf}; use clap::Parser; use thiserror::Error as ThisError; @@ -50,7 +50,7 @@ pub(crate) enum Error { struct GpioArgs { /// Location of vhost-user Unix domain socket. This is suffixed by 0,1,2..socket_count-1. #[clap(short, long)] - socket_path: String, + socket_path: PathBuf, /// Number of guests (sockets) to connect to. #[clap(short = 'c', long, default_value_t = 1)] @@ -104,7 +104,7 @@ impl TryFrom<&str> for DeviceConfig { #[derive(PartialEq, Debug)] struct GpioConfiguration { - socket_path: String, + socket_path: PathBuf, socket_count: usize, devices: DeviceConfig, } @@ -139,7 +139,7 @@ fn start_backend(args: GpioArgs) -> Resul let mut handles = Vec::new(); for i in 0..config.socket_count { - let socket = config.socket_path.to_owned() + &i.to_string(); + let socket = config.socket_path.join(i.to_string()); let device_num = config.devices.inner[i]; let handle: JoinHandle> = spawn(move || loop { @@ -218,9 +218,9 @@ mod tests { } } - fn get_cmd_args(path: &str, devices: &str, count: usize) -> GpioArgs { + fn get_cmd_args(path: impl AsRef, devices: &str, count: usize) -> GpioArgs { GpioArgs { - socket_path: path.to_string(), + socket_path: path.as_ref().to_owned(), socket_count: count, device_list: devices.to_string(), } @@ -280,7 +280,7 @@ mod tests { let expected_devices = DeviceConfig::new_with(vec![1, 4, 32, 21, 5]); let expected_config = GpioConfiguration { socket_count: 5, - socket_path: String::from(socket_name), + socket_path: PathBuf::from(socket_name), devices: expected_devices, };