Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,14 @@ where
/// If `dest` already exists then it will be replaced.
pub(crate) fn symlink_or_hardlink_file(src: &Path, dest: &Path) -> Result<()> {
let _ = fs::remove_file(dest);
// Use a relative symlink path if the src and dest are in the same directory.
let symlink_target = if src.parent() == dest.parent() {
src.file_name().map(Path::new).unwrap_or(src)
} else {
src
};
// The error is only used by macos
let Err(_err) = symlink_file(src, dest) else {
let Err(_err) = symlink_file(symlink_target, dest) else {
return Ok(());
};

Expand Down
49 changes: 49 additions & 0 deletions tests/suite/cli_self_upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,55 @@ info: default toolchain set to 'stable-{0}'
}
}

/// Ensure that proxies are relative symlinks.
#[tokio::test]
async fn proxies_are_relative_symlinks() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
#[cfg(windows)]
let _path_guard = RegistryGuard::new(&USER_PATH).unwrap();

cx.config
.expect_ok_contains(
&["rustup-init", "-y"],
for_host!(
r"
stable-{0} installed - 1.1.0 (hash-stable-1.1.0)

"
),
for_host!(
r"info: syncing channel updates for 'stable-{0}'
info: latest update on 2015-01-02, rust version 1.1.0 (hash-stable-1.1.0)
info: downloading component 'cargo'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: installing component 'cargo'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: default toolchain set to 'stable-{0}'
"
),
)
.await;

let rustup = format!("rustup{EXE_SUFFIX}");
for tool in TOOLS.iter().chain(DUP_TOOLS.iter()) {
let path = &cx.config.cargodir.join(format!("bin/{tool}{EXE_SUFFIX}"));
// If it's a normal file then it means that hardlinks are being used
// for proxies instead of symlinks.
if std::fs::symlink_metadata(path).unwrap().is_file() {
continue;
}
let is_rustup_symlink = match std::fs::read_link(path) {
Ok(p) => p.as_os_str() == rustup.as_str(),
_ => false,
};
assert!(is_rustup_symlink, "{}", path.display());
}
}

#[tokio::test]
async fn install_twice() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
Expand Down
Loading