Skip to content

Commit

Permalink
filenamegen: more fun with path fixup on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
wez committed Apr 14, 2020
1 parent 9dea0ee commit d793284
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion filenamegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,20 @@ fn normalize_slashes(path: PathBuf) -> PathBuf {
use std::ffi::OsString;
use std::os::windows::ffi::{OsStrExt, OsStringExt};

let normalized: Vec<u16> = path
let mut normalized: Vec<u16> = path
.into_os_string()
.encode_wide()
.map(|c| if c == b'\\' as u16 { b'/' as u16 } else { c })
.collect();

// Strip off the normalized long filename prefix.
const LONG_FILE_NAME_PREFIX: [u16; 4] = [b'/' as u16, b'/' as u16, b'?' as u16, b'/' as u16];
if normalized.starts_with(&LONG_FILE_NAME_PREFIX) {
for _ in 0..LONG_FILE_NAME_PREFIX.len() {
normalized.remove(0);
}
}

OsString::from_wide(&normalized).into()
}

Expand Down

0 comments on commit d793284

Please sign in to comment.