Skip to content

Commit

Permalink
fix: musl list ports handle /dev/* from available_ports (#635)
Browse files Browse the repository at this point in the history
* fix: musl list ports handle /dev/* from available_ports

* chore: add changelog entry

* chore: apply rustfmt
  • Loading branch information
TheEdward162 committed May 14, 2024
1 parent 3497701 commit 890f17a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

### Changed
Expand Down
10 changes: 7 additions & 3 deletions espflash/src/cli/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn find_serial_port(ports: &[SerialPortInfo], name: &str) -> Result<SerialPortIn
fn detect_usb_serial_ports(_list_all_ports: bool) -> Result<Vec<SerialPortInfo>> {
use std::{
fs::{read_link, read_to_string},
path::PathBuf,
path::{Path, PathBuf},
};

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

// This will give something like:
// `/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`
Expand Down

0 comments on commit 890f17a

Please sign in to comment.