Skip to content

Commit 109a47f

Browse files
committed
Use from_wide_to_user_path in read_link
1 parent 6e37784 commit 109a47f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

library/std/src/sys/windows/args.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ pub(crate) fn make_bat_command_line(
313313
///
314314
/// This is necessary because cmd.exe does not support verbatim paths.
315315
pub(crate) fn to_user_path(path: &Path) -> io::Result<Vec<u16>> {
316+
from_wide_to_user_path(to_u16s(path)?)
317+
}
318+
pub(crate) fn from_wide_to_user_path(mut path: Vec<u16>) -> io::Result<Vec<u16>> {
316319
use crate::ptr;
317320
use crate::sys::windows::fill_utf16_buf;
318321

@@ -325,8 +328,6 @@ pub(crate) fn to_user_path(path: &Path) -> io::Result<Vec<u16>> {
325328
const N: u16 = b'N' as _;
326329
const C: u16 = b'C' as _;
327330

328-
let mut path = to_u16s(path)?;
329-
330331
// Early return if the path is too long to remove the verbatim prefix.
331332
const LEGACY_MAX_PATH: usize = 260;
332333
if path.len() > LEGACY_MAX_PATH {

library/std/src/sys/windows/fs.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,10 @@ impl File {
542542
// Turn `\??\` into `\\?\` (a verbatim path).
543543
subst[1] = b'\\' as u16;
544544
// Attempt to convert to a more user-friendly path.
545-
let user = super::args::to_user_path(subst.iter().copied().chain([0]).collect())?;
546-
Ok(PathBuf::from(OsString::from_wide(&user)))
545+
let user = super::args::from_wide_to_user_path(
546+
subst.iter().copied().chain([0]).collect(),
547+
)?;
548+
Ok(PathBuf::from(OsString::from_wide(&user.strip_suffix(&[0]).unwrap_or(&user))))
547549
} else {
548550
Ok(PathBuf::from(OsString::from_wide(subst)))
549551
}

0 commit comments

Comments
 (0)