Skip to content

Commit

Permalink
gpio: Use PathBuf for socket paths instead of Strings
Browse files Browse the repository at this point in the history
Signed-off-by: Bilal Elmoussaoui <[email protected]>
  • Loading branch information
bilelmoussaoui committed Sep 15, 2023
1 parent 432304b commit 781a611
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions crates/gpio/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -139,7 +139,7 @@ fn start_backend<D: 'static + GpioDevice + Send + Sync>(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<Result<()>> = spawn(move || loop {
Expand Down Expand Up @@ -218,9 +218,9 @@ mod tests {
}
}

fn get_cmd_args(path: &str, devices: &str, count: usize) -> GpioArgs {
fn get_cmd_args(path: impl AsRef<Path>, 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(),
}
Expand Down Expand Up @@ -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,
};

Expand Down

0 comments on commit 781a611

Please sign in to comment.