Use from_wide_to_user_path in read_link

This commit is contained in:
Chris Denton 2023-05-03 11:20:59 +01:00
parent 6e377849c0
commit 109a47fc9d
No known key found for this signature in database
GPG Key ID: 713472F2F45627DE
2 changed files with 7 additions and 4 deletions

View File

@ -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;
@ -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 {

View File

@ -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)))
}