From 7e644c6901c030ba2ccb248f891198f0c55bd05f Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 27 Feb 2024 10:20:05 -0300 Subject: [PATCH 1/2] Windows: Try using symlinks if they're allowed --- src/utils/raw.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/utils/raw.rs b/src/utils/raw.rs index cd733f538e..d0d1f40ee7 100644 --- a/src/utils/raw.rs +++ b/src/utils/raw.rs @@ -134,10 +134,9 @@ pub fn append_file(dest: &Path, line: &str) -> io::Result<()> { pub fn symlink_dir(src: &Path, dest: &Path) -> io::Result<()> { #[cfg(windows)] fn symlink_dir_inner(src: &Path, dest: &Path) -> io::Result<()> { - // std's symlink uses Windows's symlink function, which requires - // admin. We can create directory junctions the hard way without - // though. - symlink_junction_inner(src, dest) + // On Windows creating symlinks isn't allowed by default so if it fails + // we fallback to creating a directory junction. + std::os::windows::fs::symlink_dir(src, dest).or_else(|_| symlink_junction_inner(src, dest)) } #[cfg(not(windows))] fn symlink_dir_inner(src: &Path, dest: &Path) -> io::Result<()> { From 0b3fb979707803e59c11a591c2416c79f4943b44 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 27 Feb 2024 10:39:02 -0300 Subject: [PATCH 2/2] Add comment on why we prefer symlinks to junctions --- src/utils/raw.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/raw.rs b/src/utils/raw.rs index d0d1f40ee7..7e541030e5 100644 --- a/src/utils/raw.rs +++ b/src/utils/raw.rs @@ -136,6 +136,8 @@ pub fn symlink_dir(src: &Path, dest: &Path) -> io::Result<()> { fn symlink_dir_inner(src: &Path, dest: &Path) -> io::Result<()> { // On Windows creating symlinks isn't allowed by default so if it fails // we fallback to creating a directory junction. + // We prefer to use symlinks here because junction point paths, unlike symlinks, + // must always be absolute. This makes moving the rustup directory difficult. std::os::windows::fs::symlink_dir(src, dest).or_else(|_| symlink_junction_inner(src, dest)) } #[cfg(not(windows))]