1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-16 19:56:17 +00:00

Merge pull request #2675 from blyxxyz/whoami-cleanup

whoami: Cleanup
This commit is contained in:
Sylvestre Ledru 2021-09-18 17:20:09 +02:00 committed by GitHub
commit 3e8b4045c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 65 deletions

View file

@ -3,7 +3,6 @@
// * For the full copyright and license information, please view the LICENSE
// * file that was distributed with this source code.
#[cfg(unix)]
use crate::common::util::*;
#[test]
@ -34,7 +33,6 @@ fn test_normal_compare_id() {
}
#[test]
#[cfg(unix)]
fn test_normal_compare_env() {
let whoami = whoami();
if whoami == "nobody" {

View file

@ -1069,10 +1069,12 @@ pub fn whoami() -> String {
// Use environment variable to get current user instead of
// invoking `whoami` and fall back to user "nobody" on error.
std::env::var("USER").unwrap_or_else(|e| {
println!("{}: {}, using \"nobody\" instead", UUTILS_WARNING, e);
"nobody".to_string()
})
std::env::var("USER")
.or_else(|_| std::env::var("USERNAME"))
.unwrap_or_else(|e| {
println!("{}: {}, using \"nobody\" instead", UUTILS_WARNING, e);
"nobody".to_string()
})
}
/// Add prefix 'g' for `util_name` if not on linux