Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Don't use canonicalized strings on Windows #218

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a comment explaining this please? There are a couple things going on here and it isn't immediately clear to others what the motivation for this is:

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