about summary refs log tree commit diff
path: root/library/std/src/fs
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2023-02-12 12:05:56 +0000
committerChris Denton <chris@chrisdenton.dev>2023-05-03 10:24:56 +0100
commit6e377849c09a310b6eef50ebd91c1f014d41ab73 (patch)
tree1b17781bad1484f5b797202fd344f265a4175ac3 /library/std/src/fs
parentcad92b4c979760b088ffd18e6c89801668c944f2 (diff)
downloadrust-6e377849c09a310b6eef50ebd91c1f014d41ab73.tar.gz
rust-6e377849c09a310b6eef50ebd91c1f014d41ab73.zip
Correctly convert an NT path to a Win32 path
This can be done by simply changing the `\??\` prefix to `\\?\` and then attempting to convert to a user path.

Currently it simply strips off the prefix which could lead to the wrong path being returned (e.g. if it's not a drive path or if the path contains trailing spaces, etc).
Diffstat (limited to 'library/std/src/fs')
-rw-r--r--library/std/src/fs/tests.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs
index 401def18458..a8a0b9f122d 100644
--- a/library/std/src/fs/tests.rs
+++ b/library/std/src/fs/tests.rs
@@ -919,6 +919,7 @@ fn symlink_noexist() {
 
 #[test]
 fn read_link() {
+    let tmpdir = tmpdir();
     if cfg!(windows) {
         // directory symlink
         assert_eq!(check!(fs::read_link(r"C:\Users\All Users")), Path::new(r"C:\ProgramData"));
@@ -933,8 +934,11 @@ fn read_link() {
                 Path::new(r"C:\Users")
             );
         }
+        // Check that readlink works with non-drive paths on Windows.
+        let link = tmpdir.join("link_unc");
+        check!(symlink_dir(r"\\localhost\c$\", &link));
+        assert_eq!(check!(fs::read_link(&link)), Path::new(r"\\localhost\c$\"));
     }
-    let tmpdir = tmpdir();
     let link = tmpdir.join("link");
     if !got_symlink_permission(&tmpdir) {
         return;