mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 20:17:45 +00:00
ls: fix windows and add more file types
This commit is contained in:
parent
c69afa00ff
commit
d624827913
1 changed files with 32 additions and 16 deletions
|
@ -1621,20 +1621,23 @@ fn format_prefixed(prefixed: NumberPrefix<f64>) -> String {
|
|||
}
|
||||
|
||||
fn display_file_size(metadata: &Metadata, config: &Config) -> String {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let ft = metadata.file_type();
|
||||
if ft.is_char_device() || ft.is_block_device() {
|
||||
let dev: u64 = metadata.rdev();
|
||||
let major = (dev >> 8) as u8;
|
||||
let minor = dev as u8;
|
||||
return format!("{}, {}", major, minor);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: The human-readable behaviour deviates from the GNU ls.
|
||||
// The GNU ls uses binary prefixes by default.
|
||||
let ft = metadata.file_type();
|
||||
if ft.is_char_device() || ft.is_block_device() {
|
||||
let dev: u64 = metadata.rdev();
|
||||
let major = (dev >> 8) as u8;
|
||||
let minor = dev as u8;
|
||||
return format!("{}, {}", major, minor);
|
||||
} else {
|
||||
match config.size_format {
|
||||
SizeFormat::Binary => format_prefixed(NumberPrefix::binary(metadata.len() as f64)),
|
||||
SizeFormat::Decimal => format_prefixed(NumberPrefix::decimal(metadata.len() as f64)),
|
||||
SizeFormat::Bytes => metadata.len().to_string(),
|
||||
}
|
||||
match config.size_format {
|
||||
SizeFormat::Binary => format_prefixed(NumberPrefix::binary(metadata.len() as f64)),
|
||||
SizeFormat::Decimal => format_prefixed(NumberPrefix::decimal(metadata.len() as f64)),
|
||||
SizeFormat::Bytes => metadata.len().to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1643,11 +1646,24 @@ fn display_file_type(file_type: FileType) -> char {
|
|||
'd'
|
||||
} else if file_type.is_symlink() {
|
||||
'l'
|
||||
} else if file_type.is_block_device() {
|
||||
'b'
|
||||
} else if file_type.is_char_device() {
|
||||
'c'
|
||||
} else {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
if file_type.is_block_device() {
|
||||
'b'
|
||||
} else if file_type.is_char_device() {
|
||||
'c'
|
||||
} else if file_type.is_fifo() {
|
||||
'p'
|
||||
} else if file_type.is_socket() {
|
||||
's'
|
||||
} else if file_type.is_file() {
|
||||
'-'
|
||||
} else {
|
||||
'?'
|
||||
}
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
'-'
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue