1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

ls: general cleanup

This commit is contained in:
Terts Diepraam 2021-04-25 00:23:14 +02:00
parent ce04f8a759
commit e995eea579

View file

@ -92,10 +92,8 @@ pub mod options {
pub static C: &str = "quote-name"; pub static C: &str = "quote-name";
} }
pub static QUOTING_STYLE: &str = "quoting-style"; pub static QUOTING_STYLE: &str = "quoting-style";
pub mod indicator_style { pub mod indicator_style {
pub static NONE: &str = "none"; pub static SLASH: &str = "p";
pub static SLASH: &str = "slash";
pub static FILE_TYPE: &str = "file-type"; pub static FILE_TYPE: &str = "file-type";
pub static CLASSIFY: &str = "classify"; pub static CLASSIFY: &str = "classify";
} }
@ -114,9 +112,6 @@ pub mod options {
pub static TIME: &str = "time"; pub static TIME: &str = "time";
pub static IGNORE_BACKUPS: &str = "ignore-backups"; pub static IGNORE_BACKUPS: &str = "ignore-backups";
pub static DIRECTORY: &str = "directory"; pub static DIRECTORY: &str = "directory";
pub static CLASSIFY: &str = "classify";
pub static FILE_TYPE: &str = "file-type";
pub static SLASH: &str = "p";
pub static INODE: &str = "inode"; pub static INODE: &str = "inode";
pub static REVERSE: &str = "reverse"; pub static REVERSE: &str = "reverse";
pub static RECURSIVE: &str = "recursive"; pub static RECURSIVE: &str = "recursive";
@ -431,19 +426,11 @@ impl Config {
"slash" => IndicatorStyle::Slash, "slash" => IndicatorStyle::Slash,
&_ => IndicatorStyle::None, &_ => IndicatorStyle::None,
} }
} else if options.is_present(options::indicator_style::NONE) { } else if options.is_present(options::indicator_style::CLASSIFY) {
IndicatorStyle::None
} else if options.is_present(options::indicator_style::CLASSIFY)
|| options.is_present(options::CLASSIFY)
{
IndicatorStyle::Classify IndicatorStyle::Classify
} else if options.is_present(options::indicator_style::SLASH) } else if options.is_present(options::indicator_style::SLASH) {
|| options.is_present(options::SLASH)
{
IndicatorStyle::Slash IndicatorStyle::Slash
} else if options.is_present(options::indicator_style::FILE_TYPE) } else if options.is_present(options::indicator_style::FILE_TYPE) {
|| options.is_present(options::FILE_TYPE)
{
IndicatorStyle::FileType IndicatorStyle::FileType
} else { } else {
IndicatorStyle::None IndicatorStyle::None
@ -969,45 +956,45 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.takes_value(true) .takes_value(true)
.possible_values(&["none", "slash", "file-type", "classify"]) .possible_values(&["none", "slash", "file-type", "classify"])
.overrides_with_all(&[ .overrides_with_all(&[
options::FILE_TYPE, options::indicator_style::FILE_TYPE,
options::SLASH, options::indicator_style::SLASH,
options::CLASSIFY, options::indicator_style::CLASSIFY,
options::INDICATOR_STYLE, options::INDICATOR_STYLE,
])) ]))
.arg( .arg(
Arg::with_name(options::CLASSIFY) Arg::with_name(options::indicator_style::CLASSIFY)
.short("F") .short("F")
.long(options::CLASSIFY) .long(options::indicator_style::CLASSIFY)
.help("Append a character to each file name indicating the file type. Also, for \ .help("Append a character to each file name indicating the file type. Also, for \
regular files that are executable, append '*'. The file type indicators are \ regular files that are executable, append '*'. The file type indicators are \
'/' for directories, '@' for symbolic links, '|' for FIFOs, '=' for sockets, \ '/' for directories, '@' for symbolic links, '|' for FIFOs, '=' for sockets, \
'>' for doors, and nothing for regular files.") '>' for doors, and nothing for regular files.")
.overrides_with_all(&[ .overrides_with_all(&[
options::FILE_TYPE, options::indicator_style::FILE_TYPE,
options::SLASH, options::indicator_style::SLASH,
options::CLASSIFY, options::indicator_style::CLASSIFY,
options::INDICATOR_STYLE, options::INDICATOR_STYLE,
]) ])
) )
.arg( .arg(
Arg::with_name(options::FILE_TYPE) Arg::with_name(options::indicator_style::FILE_TYPE)
.long(options::FILE_TYPE) .long(options::indicator_style::FILE_TYPE)
.help("Same as --classify, but do not append '*'") .help("Same as --classify, but do not append '*'")
.overrides_with_all(&[ .overrides_with_all(&[
options::FILE_TYPE, options::indicator_style::FILE_TYPE,
options::SLASH, options::indicator_style::SLASH,
options::CLASSIFY, options::indicator_style::CLASSIFY,
options::INDICATOR_STYLE, options::INDICATOR_STYLE,
])) ]))
.arg( .arg(
Arg::with_name(options::SLASH) Arg::with_name(options::indicator_style::SLASH)
.short(options::SLASH) .short(options::indicator_style::SLASH)
.help("Append / indicator to directories." .help("Append / indicator to directories."
) )
.overrides_with_all(&[ .overrides_with_all(&[
options::FILE_TYPE, options::indicator_style::FILE_TYPE,
options::SLASH, options::indicator_style::SLASH,
options::CLASSIFY, options::indicator_style::CLASSIFY,
options::INDICATOR_STYLE, options::INDICATOR_STYLE,
])) ]))
@ -1409,14 +1396,10 @@ fn cached_uid2usr(uid: u32) -> String {
} }
let mut uid_cache = UID_CACHE.lock().unwrap(); let mut uid_cache = UID_CACHE.lock().unwrap();
match uid_cache.get(&uid) { uid_cache
Some(usr) => usr.clone(), .entry(uid)
None => { .or_insert_with(|| entries::uid2usr(uid).unwrap_or_else(|_| uid.to_string()))
let usr = entries::uid2usr(uid).unwrap_or_else(|_| uid.to_string()); .clone()
uid_cache.insert(uid, usr.clone());
usr
}
}
} }
#[cfg(unix)] #[cfg(unix)]
@ -1435,14 +1418,10 @@ fn cached_gid2grp(gid: u32) -> String {
} }
let mut gid_cache = GID_CACHE.lock().unwrap(); let mut gid_cache = GID_CACHE.lock().unwrap();
match gid_cache.get(&gid) { gid_cache
Some(grp) => grp.clone(), .entry(gid)
None => { .or_insert_with(|| entries::gid2grp(gid).unwrap_or_else(|_| gid.to_string()))
let grp = entries::gid2grp(gid).unwrap_or_else(|_| gid.to_string()); .clone()
gid_cache.insert(gid, grp.clone());
grp
}
}
} }
#[cfg(unix)] #[cfg(unix)]
@ -1460,7 +1439,6 @@ fn display_uname(_metadata: &Metadata, _config: &Config) -> String {
} }
#[cfg(not(unix))] #[cfg(not(unix))]
#[allow(unused_variables)]
fn display_group(_metadata: &Metadata, _config: &Config) -> String { fn display_group(_metadata: &Metadata, _config: &Config) -> String {
"somegroup".to_string() "somegroup".to_string()
} }
@ -1535,13 +1513,13 @@ fn display_file_size(metadata: &Metadata, config: &Config) -> String {
} }
} }
fn display_file_type(file_type: FileType) -> String { fn display_file_type(file_type: FileType) -> char {
if file_type.is_dir() { if file_type.is_dir() {
"d".to_string() 'd'
} else if file_type.is_symlink() { } else if file_type.is_symlink() {
"l".to_string() 'l'
} else { } else {
"-".to_string() '-'
} }
} }