about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2023-05-03 11:20:59 +0100
committerChris Denton <chris@chrisdenton.dev>2023-05-03 11:31:41 +0100
commit109a47fc9d63a5e093bd36423e290fe8bc18ae25 (patch)
tree8aa9461eb1e95c70fdd4d27f57db8b4e59642bcf
parent6e377849c09a310b6eef50ebd91c1f014d41ab73 (diff)
downloadrust-109a47fc9d63a5e093bd36423e290fe8bc18ae25.tar.gz
rust-109a47fc9d63a5e093bd36423e290fe8bc18ae25.zip
Use `from_wide_to_user_path` in `read_link`
-rw-r--r--library/std/src/sys/windows/args.rs5
-rw-r--r--library/std/src/sys/windows/fs.rs6
2 files changed, 7 insertions, 4 deletions
diff --git a/library/std/src/sys/windows/args.rs b/library/std/src/sys/windows/args.rs
index 43c0cdb657e..5bfd8b52ed0 100644
--- a/library/std/src/sys/windows/args.rs
+++ b/library/std/src/sys/windows/args.rs
@@ -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 {
diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs
index ff05d31915c..fe052c8281b 100644
--- a/library/std/src/sys/windows/fs.rs
+++ b/library/std/src/sys/windows/fs.rs
@@ -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)))
             }