mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-08 21:13:55 +00:00
Use from_wide_to_user_path
in read_link
This commit is contained in:
parent
6e377849c0
commit
109a47fc9d
@ -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 {
|
||||
|
@ -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)))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user