From d7932846f365f82c0709a41a7027285fae84a128 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 13 Apr 2020 23:09:51 -0700 Subject: [PATCH] filenamegen: more fun with path fixup on windows --- filenamegen/src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/filenamegen/src/lib.rs b/filenamegen/src/lib.rs index 94622d7..69b5e2e 100644 --- a/filenamegen/src/lib.rs +++ b/filenamegen/src/lib.rs @@ -128,12 +128,20 @@ fn normalize_slashes(path: PathBuf) -> PathBuf { use std::ffi::OsString; use std::os::windows::ffi::{OsStrExt, OsStringExt}; - let normalized: Vec = path + let mut normalized: Vec = 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() }