Skip to content

Commit b65d479

Browse files
authored
Unrolled build for #141840
Rollup merge of #141840 - ChrisDenton:noempty, r=ChrisDenton If `HOME` is empty, use the fallback instead This is a minor change in the `home_dir` api. An empty path is never (or should never be) valid so if the `HOME` environment variable is empty then let's use the fallback instead. r? libs-api
2 parents 283a074 + 921b6c0 commit b65d479

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

library/std/src/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ impl Error for JoinPathsError {
617617
/// # Unix
618618
///
619619
/// - Returns the value of the 'HOME' environment variable if it is set
620-
/// (including to an empty string).
620+
/// (and not an empty string).
621621
/// - Otherwise, it tries to determine the home directory by invoking the `getpwuid_r` function
622622
/// using the UID of the current user. An empty home directory field returned from the
623623
/// `getpwuid_r` function is considered to be a valid value.

library/std/src/sys/pal/unix/os.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,10 @@ pub fn temp_dir() -> PathBuf {
633633
}
634634

635635
pub fn home_dir() -> Option<PathBuf> {
636-
return crate::env::var_os("HOME").or_else(|| unsafe { fallback() }).map(PathBuf::from);
636+
return crate::env::var_os("HOME")
637+
.filter(|s| !s.is_empty())
638+
.or_else(|| unsafe { fallback() })
639+
.map(PathBuf::from);
637640

638641
#[cfg(any(
639642
target_os = "android",

0 commit comments

Comments
 (0)