|
| 1 | +#[cfg(not(target_os = "windows"))] |
1 | 2 | use std::fs;
|
2 | 3 |
|
3 | 4 | use crossterm::style::Stylize;
|
@@ -31,12 +32,8 @@ pub fn get_serial_port_info(
|
31 | 32 | let ports = detect_usb_serial_ports().unwrap_or_default();
|
32 | 33 |
|
33 | 34 | if let Some(serial) = &matches.port {
|
34 |
| - #[cfg(not(target_os = "windows"))] |
35 |
| - let serial = fs::canonicalize(serial)?.to_string_lossy().to_string(); |
36 | 35 | find_serial_port(&ports, &serial)
|
37 | 36 | } else if let Some(serial) = &config.connection.serial {
|
38 |
| - #[cfg(not(target_os = "windows"))] |
39 |
| - let serial = fs::canonicalize(serial)?.to_string_lossy().to_string(); |
40 | 37 | find_serial_port(&ports, &serial)
|
41 | 38 | } else {
|
42 | 39 | let (port, matches) = select_serial_port(ports, config)?;
|
@@ -71,14 +68,19 @@ pub fn get_serial_port_info(
|
71 | 68 | /// Given a vector of `SerialPortInfo` structs, attempt to find and return one
|
72 | 69 | /// whose `port_name` field matches the provided `name` argument.
|
73 | 70 | fn find_serial_port(ports: &[SerialPortInfo], name: &str) -> Result<SerialPortInfo, Error> {
|
| 71 | + #[cfg(not(target_os = "windows"))] |
| 72 | + let name = fs::canonicalize(name)?; |
| 73 | + #[cfg(not(target_os = "windows"))] |
| 74 | + let name = name.to_string_lossy(); |
| 75 | + |
74 | 76 | let port_info = ports
|
75 | 77 | .iter()
|
76 |
| - .find(|port| port.port_name.to_lowercase() == name.to_lowercase()); |
| 78 | + .find(|port| port.port_name.eq_ignore_ascii_case(name.as_ref())); |
77 | 79 |
|
78 | 80 | if let Some(port) = port_info {
|
79 | 81 | Ok(port.to_owned())
|
80 | 82 | } else {
|
81 |
| - Err(Error::SerialNotFound(name.to_owned())) |
| 83 | + Err(Error::SerialNotFound(name.to_string())) |
82 | 84 | }
|
83 | 85 | }
|
84 | 86 |
|
|
0 commit comments