Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(utils): resolve input path in delete_dir_contents() if it's a link #3754

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion src/utils/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,9 @@ where
}

pub(crate) fn delete_dir_contents(dir_path: &Path) {
rami3l marked this conversation as resolved.
Show resolved Hide resolved
match remove_dir_all::remove_dir_contents(dir_path) {
use remove_dir_all::RemoveDir;

match raw::open_dir_following_links(dir_path).and_then(|mut p| p.remove_dir_contents(None)) {
Err(e) if e.kind() != io::ErrorKind::NotFound => {
panic!("Unable to clean up {}: {:?}", dir_path.display(), e);
}
Expand Down
30 changes: 30 additions & 0 deletions tests/suite/cli_misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,36 @@ fn toolchains_symlink() {
});
}

// issue #3344
rami3l marked this conversation as resolved.
Show resolved Hide resolved
/// `~/.rustup/tmp` and `~/.rustup/downloads` are permitted to be symlinks.
#[test]
#[cfg(any(unix, windows))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this equivalent to all platforms?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are indeed other platforms such as wasm, although I don't know if Rustup is meaningful there or not. Similar to other tests above/below it, this one relies on the fact that we compile for Unix or Windows. I just copied the code over as I mentioned above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that platforms like WASM exist, this seems okay.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a side effect of code evolution, it isn't the pattern in general, and rustup does depend on hardlinks to operate at all. Are there platforms that have hardlinks, but not symlinks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rbtcollins Looks like symlinks are also available on WASM/WASI: https://doc.rust-lang.org/std/os/wasi/fs/fn.symlink.html, so I'm also okay with removing this line. Anyway Rustup in its current form will fail to build on WASM and not all dependencies of this test work on WASM anyway.

fn tmp_downloads_symlink() {
use rustup::utils::raw::symlink_dir;
use std::fs;

clitools::test(Scenario::ArchivesV2, &|config| {
let cwd = config.current_dir();

let test_tmp = cwd.join("tmp-test");
fs::create_dir(&test_tmp).unwrap();
symlink_dir(&test_tmp, &config.rustupdir.join("tmp")).unwrap();

let test_downloads = cwd.join("tmp-downloads");
fs::create_dir(&test_downloads).unwrap();
symlink_dir(&test_downloads, &config.rustupdir.join("downloads")).unwrap();

set_current_dist_date(config, "2015-01-01");
config.expect_ok(&["rustup", "default", "nightly"]);

set_current_dist_date(config, "2015-01-02");
config.expect_ok(&["rustup", "update"]);

assert!(config.rustupdir.join("tmp").exists());
assert!(config.rustupdir.join("downloads").exists());
});
}

// issue #1169
/// A toolchain that is a stale symlink should be correctly uninstalled.
#[test]
Expand Down
Loading