Skip to content

Commit

Permalink
Use from_wide_to_user_path in read_link
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed May 3, 2023
1 parent 6e37784 commit 109a47f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions library/std/src/sys/windows/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ pub(crate) fn make_bat_command_line(
///
/// This is necessary because cmd.exe does not support verbatim paths.
pub(crate) fn to_user_path(path: &Path) -> io::Result<Vec<u16>> {
from_wide_to_user_path(to_u16s(path)?)
}
pub(crate) fn from_wide_to_user_path(mut path: Vec<u16>) -> io::Result<Vec<u16>> {
use crate::ptr;
use crate::sys::windows::fill_utf16_buf;

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

let mut path = to_u16s(path)?;

// Early return if the path is too long to remove the verbatim prefix.
const LEGACY_MAX_PATH: usize = 260;
if path.len() > LEGACY_MAX_PATH {
Expand Down
6 changes: 4 additions & 2 deletions library/std/src/sys/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,10 @@ impl File {
// Turn `\??\` into `\\?\` (a verbatim path).
subst[1] = b'\\' as u16;
// Attempt to convert to a more user-friendly path.
let user = super::args::to_user_path(subst.iter().copied().chain([0]).collect())?;
Ok(PathBuf::from(OsString::from_wide(&user)))
let user = super::args::from_wide_to_user_path(
subst.iter().copied().chain([0]).collect(),
)?;
Ok(PathBuf::from(OsString::from_wide(&user.strip_suffix(&[0]).unwrap_or(&user))))
} else {
Ok(PathBuf::from(OsString::from_wide(subst)))
}
Expand Down

0 comments on commit 109a47f

Please sign in to comment.