@Screwtapello I agree with this, and the way user land tools work – but what happens when the home dir is not set in /etc/passwd?
I checked, and it seems you receive an empty string. Rust considers this empty string to be a valid home directory.
Now the question is whether this should be the case, and if one assumed this makes sense (I don’t – just as I don’t believe an empty $HOME env should be accepted as a valid home directory¹), under which circumstances can home_dir actually return None?
@xfix The issue is not about what happens when users don’t care and user land tools add some default value to /etc/passwd – it’s what happens when no value is given in /etc/passwd.
¹ Compare std::env::home_dirs claim:
Returns the value of the ‘HOME’ environment variable if it is set and not equal to the empty string.
… with its actual behavior:
std::env::set_var("HOME", "");
println!("{:?}", std::env::var_os("HOME")); // Some("")
println!("{:?}", std::env::home_dir()); // Some("")
From my perspective so far, home_dir should either
- return
T if the implementation in which any value is considered valid is kept and the documentation needs to be fixed to reflect that, or
- return
Option<T> and stop considering empty strings a valid home directory in the implementation, regardless of whether they come from $HOME or getpwuid.