Skip to content

Commit 890f17a

Browse files
authored
fix: musl list ports handle /dev/* from available_ports (#635)
* fix: musl list ports handle /dev/* from available_ports * chore: add changelog entry * chore: apply rustfmt
1 parent 3497701 commit 890f17a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Fixed
1414
- Fixed help text for size parameter of read-flash subcommand
15+
- Fixed port detection on `musl` when detection returns paths starting with `/dev/`
1516
- [cargo-espflash]: Always resolve package_id from metadata when finding bootloader and partition table (#632)
1617

1718
### Changed

espflash/src/cli/serial.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn find_serial_port(ports: &[SerialPortInfo], name: &str) -> Result<SerialPortIn
111111
fn detect_usb_serial_ports(_list_all_ports: bool) -> Result<Vec<SerialPortInfo>> {
112112
use std::{
113113
fs::{read_link, read_to_string},
114-
path::PathBuf,
114+
path::{Path, PathBuf},
115115
};
116116

117117
use serialport::UsbPortInfo;
@@ -120,8 +120,12 @@ fn detect_usb_serial_ports(_list_all_ports: bool) -> Result<Vec<SerialPortInfo>>
120120
let ports = ports
121121
.into_iter()
122122
.filter_map(|port_info| {
123-
// With musl, the paths we get are `/sys/class/tty/*`
124-
let path = PathBuf::from(&port_info.port_name);
123+
// With musl, the paths we get are `/sys/class/tty/*` or `/dev/*`
124+
// In case of `/dev/*` we transform them into `/sys/class/tty/*`
125+
let path = match AsRef::<Path>::as_ref(&port_info.port_name).strip_prefix("/dev/") {
126+
Ok(rem) => PathBuf::from("/sys/class/tty/").join(rem),
127+
Err(_) => PathBuf::from(&port_info.port_name),
128+
};
125129

126130
// This will give something like:
127131
// `/sys/devices/pci0000:00/0000:00:07.1/0000:0c:00.3/usb5/5-3/5-3.1/5-3.1:1.0/ttyUSB0/tty/ttyUSB0`

0 commit comments

Comments
 (0)