Skip to content

Commit

Permalink
bugfix: Don't use canonicalized strings on Windows (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajSadel committed Aug 15, 2022
1 parent 312c115 commit 3c21364
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
13 changes: 11 additions & 2 deletions espflash/src/cli/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ pub fn get_serial_port_info(
// select a serial port. If some VID and PID were provided then the user will
// also be prompted to select a port, unless there is only one found and its VID
// and PID match the configured values.
//
// The call to canonicalize() was originally added to resolve https://github.com/esp-rs/espflash/issues/177,
// however, canonicalize doesn't work (on Windows) with "dummy" device paths like `COM4`.
// That's the reason we need to handle Windows/Posix differently.

let ports = detect_usb_serial_ports().unwrap_or_default();

if let Some(serial) = &matches.serial {
find_serial_port(&ports, &std::fs::canonicalize(serial)?.to_string_lossy())
#[cfg(not(target_os = "windows"))]
let serial = std::fs::canonicalize(serial)?.to_string_lossy().to_string();
find_serial_port(&ports, &serial)
} else if let Some(serial) = &config.connection.serial {
find_serial_port(&ports, &std::fs::canonicalize(serial)?.to_string_lossy())
#[cfg(not(target_os = "windows"))]
let serial = std::fs::canonicalize(serial)?.to_string_lossy().to_string();
find_serial_port(&ports, &serial)
} else {
let (port, matches) = select_serial_port(ports, config)?;

Expand Down
10 changes: 5 additions & 5 deletions espflash/src/partition_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const MD5_PART_MAGIC_BYTES: &[u8] = &[
];
const END_MARKER: [u8; 32] = [0xFF; 32];

#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, BinRead)]
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, BinRead)]
#[repr(u8)]
#[br(little, repr = u8)]
#[serde(rename_all = "lowercase")]
Expand Down Expand Up @@ -62,7 +62,7 @@ impl Display for Type {
}
}

#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, BinRead)]
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, BinRead)]
#[repr(u8)]
#[br(little, repr = u8)]
pub enum AppType {
Expand Down Expand Up @@ -104,7 +104,7 @@ pub enum AppType {
Test = 0x20,
}

#[derive(Copy, Clone, Debug, Deserialize, EnumIter, Serialize, PartialEq, BinRead)]
#[derive(Copy, Clone, Debug, Deserialize, EnumIter, Serialize, PartialEq, Eq, BinRead)]
#[repr(u8)]
#[br(little, repr = u8)]
#[serde(rename_all = "lowercase")]
Expand All @@ -127,7 +127,7 @@ impl DataType {
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Copy, Clone, BinRead)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Copy, Clone, BinRead)]
#[serde(untagged)]
pub enum SubType {
App(AppType),
Expand Down Expand Up @@ -162,7 +162,7 @@ impl SubType {
}
}

#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, BinRead)]
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, BinRead)]
#[repr(u8)]
#[br(little, repr = u8)]
#[serde(rename_all = "lowercase")]
Expand Down

0 comments on commit 3c21364

Please sign in to comment.