Skip to content

Commit 3c21364

Browse files
authored
bugfix: Don't use canonicalized strings on Windows (#218)
1 parent 312c115 commit 3c21364

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

espflash/src/cli/serial.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@ pub fn get_serial_port_info(
1919
// select a serial port. If some VID and PID were provided then the user will
2020
// also be prompted to select a port, unless there is only one found and its VID
2121
// and PID match the configured values.
22+
//
23+
// The call to canonicalize() was originally added to resolve https://github.com/esp-rs/espflash/issues/177,
24+
// however, canonicalize doesn't work (on Windows) with "dummy" device paths like `COM4`.
25+
// That's the reason we need to handle Windows/Posix differently.
26+
2227
let ports = detect_usb_serial_ports().unwrap_or_default();
2328

2429
if let Some(serial) = &matches.serial {
25-
find_serial_port(&ports, &std::fs::canonicalize(serial)?.to_string_lossy())
30+
#[cfg(not(target_os = "windows"))]
31+
let serial = std::fs::canonicalize(serial)?.to_string_lossy().to_string();
32+
find_serial_port(&ports, &serial)
2633
} else if let Some(serial) = &config.connection.serial {
27-
find_serial_port(&ports, &std::fs::canonicalize(serial)?.to_string_lossy())
34+
#[cfg(not(target_os = "windows"))]
35+
let serial = std::fs::canonicalize(serial)?.to_string_lossy().to_string();
36+
find_serial_port(&ports, &serial)
2837
} else {
2938
let (port, matches) = select_serial_port(ports, config)?;
3039

espflash/src/partition_table.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const MD5_PART_MAGIC_BYTES: &[u8] = &[
2929
];
3030
const END_MARKER: [u8; 32] = [0xFF; 32];
3131

32-
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, BinRead)]
32+
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, BinRead)]
3333
#[repr(u8)]
3434
#[br(little, repr = u8)]
3535
#[serde(rename_all = "lowercase")]
@@ -62,7 +62,7 @@ impl Display for Type {
6262
}
6363
}
6464

65-
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, BinRead)]
65+
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, BinRead)]
6666
#[repr(u8)]
6767
#[br(little, repr = u8)]
6868
pub enum AppType {
@@ -104,7 +104,7 @@ pub enum AppType {
104104
Test = 0x20,
105105
}
106106

107-
#[derive(Copy, Clone, Debug, Deserialize, EnumIter, Serialize, PartialEq, BinRead)]
107+
#[derive(Copy, Clone, Debug, Deserialize, EnumIter, Serialize, PartialEq, Eq, BinRead)]
108108
#[repr(u8)]
109109
#[br(little, repr = u8)]
110110
#[serde(rename_all = "lowercase")]
@@ -127,7 +127,7 @@ impl DataType {
127127
}
128128
}
129129

130-
#[derive(Debug, Serialize, Deserialize, PartialEq, Copy, Clone, BinRead)]
130+
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Copy, Clone, BinRead)]
131131
#[serde(untagged)]
132132
pub enum SubType {
133133
App(AppType),
@@ -162,7 +162,7 @@ impl SubType {
162162
}
163163
}
164164

165-
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, BinRead)]
165+
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, BinRead)]
166166
#[repr(u8)]
167167
#[br(little, repr = u8)]
168168
#[serde(rename_all = "lowercase")]

0 commit comments

Comments
 (0)