diff --git a/rkvm-input/src/monitor.rs b/rkvm-input/src/monitor.rs index 2747cd3..1400365 100644 --- a/rkvm-input/src/monitor.rs +++ b/rkvm-input/src/monitor.rs @@ -7,6 +7,7 @@ use std::ffi::OsStr; use std::io::{Error, ErrorKind}; use std::path::{Path, PathBuf}; use std::collections::HashSet; +use std::fs::canonicalize; use tokio::fs; use tokio::sync::mpsc::{self, Receiver, Sender}; @@ -19,7 +20,8 @@ pub struct Monitor { impl Monitor { pub fn new(input_device_paths: &HashSet) -> Self { let (sender, receiver) = mpsc::channel(1); - tokio::spawn(monitor(sender, input_device_paths.clone())); + let absolute_input_device_paths = canonicalize_input_device_paths(input_device_paths); + tokio::spawn(monitor(sender, absolute_input_device_paths)); Self { receiver } } @@ -98,6 +100,30 @@ async fn monitor(sender: Sender>, input_device_paths: } } +fn canonicalize_input_device_paths(input_device_paths: &HashSet) -> HashSet { + let mut absolute_paths = HashSet::new(); + for path in input_device_paths { + match canonicalize(path) { + Ok(abs_path) => { + match abs_path.into_os_string().into_string() { + Ok(ap) => { + absolute_paths.insert(ap); + }, + Err(err) => { + tracing::error!("Failed to convert absolute path into string {:?}", err); + continue; + }, + } + }, + Err(err) => { + tracing::error!("Failed to canonicalize a path: {}", err); + continue; + }, + } + } + return absolute_paths; +} + fn register_input_device(input_device_paths: &HashSet, input_device_path: PathBuf) -> bool { if input_device_paths.len() > 0 { match input_device_path.into_os_string().into_string() {