Skip to content

Commit 495c65d

Browse files
committed
Unify home directory handling.
The `std::env::home_dir()` function is deprecated (as of 1.29.0) due to potentially "surprising" behaviour. The compiler recommends we switch to `dirs::home_dir()` so this commit does just that. In addition, we risked diverging in behaviour because rustup-utils has its own `home_dir()` behaviour for Windows, so change rustup-cli to use that too.
1 parent be16639 commit 495c65d

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/rustup-cli/self_update.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ fn do_pre_install_sanity_checks() -> Result<()> {
383383
let multirust_manifest_path = PathBuf::from("/usr/local/lib/rustlib/manifest-multirust");
384384
let rustc_manifest_path = PathBuf::from("/usr/local/lib/rustlib/manifest-rustc");
385385
let uninstaller_path = PathBuf::from("/usr/local/lib/rustlib/uninstall.sh");
386-
let multirust_meta_path = env::home_dir().map(|d| d.join(".multirust"));
386+
let multirust_meta_path = utils::home_dir().map(|d| d.join(".multirust"));
387387
let multirust_version_path = multirust_meta_path.as_ref().map(|p| p.join("version"));
388-
let rustup_sh_path = env::home_dir().map(|d| d.join(".rustup"));
388+
let rustup_sh_path = utils::home_dir().map(|d| d.join(".rustup"));
389389
let rustup_sh_version_path = rustup_sh_path.as_ref().map(|p| p.join("rustup-version"));
390390

391391
let multirust_exists = multirust_manifest_path.exists() && uninstaller_path.exists();

src/rustup-utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ semver = "0.9.0"
2323
sha2 = "0.7.0"
2424
toml = "0.4"
2525
url = "1.1"
26+
dirs = "1.0"
2627

2728
[target."cfg(windows)".dependencies]
2829
winapi = { version = "0.3", features = ["combaseapi", "errhandlingapi", "fileapi", "handleapi",

src/rustup-utils/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ where
522522

523523
#[cfg(unix)]
524524
pub fn home_dir() -> Option<PathBuf> {
525-
::std::env::home_dir()
525+
dirs::home_dir()
526526
}
527527

528528
pub fn cargo_home() -> Result<PathBuf> {

0 commit comments

Comments
 (0)