Skip to content

Commit 13e5370

Browse files
majahadjc
authored andcommitted
Fix the test toolchain_broken_symlink on Windows
`rustup` on Windows uses "directory junctions" instead of symbolic links for `rustup toolchain link`. These are somewhere between a symbolic and a hard link, and require fewer permissions. However, the test in question was trying to use symbolic links. It now uses the same codepath to create the link as `toolchain link` itself.
1 parent b5d74ac commit 13e5370

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

src/utils/raw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn append_file(dest: &Path, line: &str) -> io::Result<()> {
131131
Ok(())
132132
}
133133

134-
pub(crate) fn symlink_dir(src: &Path, dest: &Path) -> io::Result<()> {
134+
pub fn symlink_dir(src: &Path, dest: &Path) -> io::Result<()> {
135135
#[cfg(windows)]
136136
fn symlink_dir_inner(src: &Path, dest: &Path) -> io::Result<()> {
137137
// std's symlink uses Windows's symlink function, which requires

tests/suite/cli_misc.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -665,29 +665,22 @@ fn rename_rls_remove() {
665665
#[test]
666666
#[cfg(any(unix, windows))]
667667
fn toolchain_broken_symlink() {
668+
use rustup::utils::raw::symlink_dir;
668669
use std::fs;
669670
use std::path::Path;
670671

671-
#[cfg(unix)]
672-
fn create_symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) {
673-
use std::os::unix::fs;
674-
fs::symlink(src, dst).unwrap();
675-
}
676-
677-
#[cfg(windows)]
678-
fn create_symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) {
679-
use std::os::windows::fs;
680-
fs::symlink_dir(src, dst).unwrap();
681-
}
682-
683672
clitools::test(Scenario::None, &|config| {
684673
// We artificially create a broken symlink toolchain -- but this can also happen "legitimately"
685674
// by having a proper toolchain there, using "toolchain link", and later removing the directory.
686675
fs::create_dir(config.rustupdir.join("toolchains")).unwrap();
687-
create_symlink_dir(
688-
config.rustupdir.join("this-directory-does-not-exist"),
689-
config.rustupdir.join("toolchains").join("test"),
690-
);
676+
fs::create_dir(config.rustupdir.join("this-directory-does-not-exist")).unwrap();
677+
symlink_dir(
678+
&config.rustupdir.join("this-directory-does-not-exist"),
679+
&config.rustupdir.join("toolchains").join("test"),
680+
)
681+
.unwrap();
682+
fs::remove_dir(config.rustupdir.join("this-directory-does-not-exist")).unwrap();
683+
691684
// Make sure this "fake install" actually worked
692685
config.expect_ok_ex(&["rustup", "toolchain", "list"], "test\n", "");
693686
// Now try to uninstall it. That should work only once.

0 commit comments

Comments
 (0)