mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
ls: implement -i option
This commit is contained in:
parent
62d5a6bbc8
commit
8a51ddf6fb
2 changed files with 34 additions and 1 deletions
29
src/ls/ls.rs
29
src/ls/ls.rs
|
@ -107,6 +107,9 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
.optflag("h",
|
||||
"human-readable",
|
||||
"Print human readable file sizes (e.g. 1K 234M 56G).")
|
||||
.optflag("i",
|
||||
"inode",
|
||||
"print the index number of each file")
|
||||
.optflag("L",
|
||||
"dereference",
|
||||
"When showing file information for a symbolic link, show information for the \
|
||||
|
@ -353,7 +356,8 @@ fn display_item_long(item: &PathBuf,
|
|||
Ok(md) => md,
|
||||
};
|
||||
|
||||
println!("{}{} {} {} {} {} {} {}",
|
||||
println!("{}{}{} {} {} {} {} {} {}",
|
||||
get_inode(&md, options),
|
||||
display_file_type(md.file_type()),
|
||||
display_permissions(&md),
|
||||
pad_left(display_symlink_count(&md), max_links),
|
||||
|
@ -364,6 +368,21 @@ fn display_item_long(item: &PathBuf,
|
|||
display_file_name(&item, strip, &md, options).contents);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn get_inode(metadata: &Metadata, options: &getopts::Matches) -> String {
|
||||
if options.opt_present("inode") {
|
||||
format!("{:8} ", metadata.ino())
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
fn get_inode(_metadata: &Metadata, _options: &getopts::Matches) -> Option<String> {
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
|
||||
// Currently getpwuid is `linux` target only. If it's broken out into
|
||||
// a posix-compliant attribute this can be updated...
|
||||
#[cfg(unix)]
|
||||
|
@ -453,6 +472,11 @@ fn display_file_name(path: &Path,
|
|||
options: &getopts::Matches)
|
||||
-> Cell {
|
||||
let mut name = get_file_name(path, strip);
|
||||
|
||||
if ! options.opt_present("long") {
|
||||
name = get_inode(metadata, options) + &name;
|
||||
}
|
||||
|
||||
if options.opt_present("classify") {
|
||||
let file_type = metadata.file_type();
|
||||
if file_type.is_dir() {
|
||||
|
@ -512,6 +536,9 @@ fn display_file_name(path: &Path,
|
|||
options: &getopts::Matches)
|
||||
-> Cell {
|
||||
let mut name = get_file_name(path, strip);
|
||||
if ! options.opt_present("long") {
|
||||
name = get_inode(metadata, options) + &name;
|
||||
}
|
||||
let mut width = UnicodeWidthStr::width(&*name);
|
||||
|
||||
let color = options.opt_present("color");
|
||||
|
|
|
@ -5,3 +5,9 @@ use common::util::*;
|
|||
fn test_ls_ls() {
|
||||
new_ucmd!().succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_ls_i() {
|
||||
new_ucmd!().arg("-i").succeeds();
|
||||
new_ucmd!().arg("-il").succeeds();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue