1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

`ls: Changed unwrap_or and or option handling to lazy evaluated unwrap_or_else and or_else` (#6609)

* Changed unwrap_or and option handling to lazy evaluation

* Clippy fixes
This commit is contained in:
Anirban Halder 2024-09-07 18:35:54 +05:30 committed by GitHub
parent 66e0989526
commit e4749381f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View file

@ -169,7 +169,7 @@ pub(crate) fn color_name(
// Use fn get_metadata_with_deref_opt instead of get_metadata() here because ls // Use fn get_metadata_with_deref_opt instead of get_metadata() here because ls
// should not exit with an err, if we are unable to obtain the target_metadata // should not exit with an err, if we are unable to obtain the target_metadata
let md_res = get_metadata_with_deref_opt(&target.p_buf, path.must_dereference); let md_res = get_metadata_with_deref_opt(&target.p_buf, path.must_dereference);
let md = md_res.or(path.p_buf.symlink_metadata()); let md = md_res.or_else(|_| path.p_buf.symlink_metadata());
style_manager.apply_style_based_on_metadata(path, md.ok().as_ref(), name, wrap) style_manager.apply_style_based_on_metadata(path, md.ok().as_ref(), name, wrap)
} else { } else {
let md_option = path.get_metadata(out); let md_option = path.get_metadata(out);

View file

@ -697,7 +697,7 @@ fn extract_quoting_style(options: &clap::ArgMatches, show_control: bool) -> Quot
Some(qs) => return qs, Some(qs) => return qs,
None => eprintln!( None => eprintln!(
"{}: Ignoring invalid value of environment variable QUOTING_STYLE: '{}'", "{}: Ignoring invalid value of environment variable QUOTING_STYLE: '{}'",
std::env::args().next().unwrap_or("ls".to_string()), std::env::args().next().unwrap_or_else(|| "ls".to_string()),
style style
), ),
} }
@ -3332,7 +3332,7 @@ fn display_item_name(
} }
fn create_hyperlink(name: &str, path: &PathData) -> String { fn create_hyperlink(name: &str, path: &PathData) -> String {
let hostname = hostname::get().unwrap_or(OsString::from("")); let hostname = hostname::get().unwrap_or_else(|_| OsString::from(""));
let hostname = hostname.to_string_lossy(); let hostname = hostname.to_string_lossy();
let absolute_path = fs::canonicalize(&path.p_buf).unwrap_or_default(); let absolute_path = fs::canonicalize(&path.p_buf).unwrap_or_default();