From 21c317614957d8d0dde455f085f8767b3f6b8afe Mon Sep 17 00:00:00 2001 From: mtsoltan Date: Sat, 2 Oct 2021 22:59:09 +0200 Subject: [PATCH 1/5] Changed inode in ls (and get_inode) to align question-mark inodes properly. Explicitly put :>8 to right-format inodes, and never left-format them (in case of a question-mark for example). --- src/uu/ls/src/ls.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 51dc0d2471c..76cfbea3af2 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -1668,7 +1668,7 @@ fn display_item_long( #[cfg(unix)] { if config.inode { - let _ = write!(out, "{} ", get_inode(md)); + let _ = write!(out, "{} ", get_inode(item.md())); } } @@ -1733,8 +1733,8 @@ fn display_item_long( } #[cfg(unix)] -fn get_inode(metadata: &Metadata) -> String { - format!("{:8}", metadata.ino()) +fn get_inode(metadata: Option<&Metadata>) -> String { + metadata.map_or_else(|| format!("{:>8}", "?"), |md| format!("{:>8}", md.ino())) } // Currently getpwuid is `linux` target only. If it's broken out into @@ -1967,11 +1967,7 @@ fn display_file_name( #[cfg(unix)] { if config.format != Format::Long && config.inode { - name = path - .md() - .map_or_else(|| "?".to_string(), |md| get_inode(md)) - + " " - + &name; + name = get_inode(path.md()) + " " + &name; } } From 8cb1bb2359774b2d10f87a18ef325e955b7bcc37 Mon Sep 17 00:00:00 2001 From: mtsoltan Date: Sat, 2 Oct 2021 23:17:00 +0200 Subject: [PATCH 2/5] Naively modified the test to make sure "lots of spaces" exist before the question-mark. This is to make sure the behavior does not regress. --- tests/by-util/test_ls.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 56711d6e0c8..4696bea0426 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -2259,6 +2259,7 @@ fn test_ls_dangling_symlinks() { at.mkdir("temp_dir"); at.symlink_file("does_not_exist", "temp_dir/dangle"); + at.symlink_file("temp_dir", "temp_dir/a"); scene.ucmd().arg("-L").arg("temp_dir/dangle").fails(); scene.ucmd().arg("-H").arg("temp_dir/dangle").fails(); @@ -2274,7 +2275,7 @@ fn test_ls_dangling_symlinks() { .arg("-Li") .arg("temp_dir") .succeeds() // this should fail, though at the moment, ls lacks a way to propagate errors encountered during display - .stdout_contains(if cfg!(windows) { "dangle" } else { "? dangle" }); + .stdout_contains(if cfg!(windows) { " dangle" } else { " ? dangle" }); } #[test] From 06792438ac8045fe52a813f44e88cbae1819c737 Mon Sep 17 00:00:00 2001 From: mtsoltan Date: Sat, 2 Oct 2021 23:33:29 +0200 Subject: [PATCH 3/5] Fixed CI rustfmt problem. --- tests/by-util/test_ls.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 4696bea0426..6286f9a0f18 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -2275,7 +2275,11 @@ fn test_ls_dangling_symlinks() { .arg("-Li") .arg("temp_dir") .succeeds() // this should fail, though at the moment, ls lacks a way to propagate errors encountered during display - .stdout_contains(if cfg!(windows) { " dangle" } else { " ? dangle" }); + .stdout_contains(if cfg!(windows) { + " dangle" + } else { + " ? dangle" + }); } #[test] From e971a081829fbc38aaa0f1a185550dd164a5eae1 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Wed, 22 Dec 2021 10:26:48 +0100 Subject: [PATCH 4/5] ls: add width to missing inode test --- tests/by-util/test_ls.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 6286f9a0f18..33aa9494bcd 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -2274,6 +2274,7 @@ fn test_ls_dangling_symlinks() { .ucmd() .arg("-Li") .arg("temp_dir") + .arg("-w40") .succeeds() // this should fail, though at the moment, ls lacks a way to propagate errors encountered during display .stdout_contains(if cfg!(windows) { " dangle" From 3b1643b0ff8fc5283ae8207a230b6b6ab67675ee Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Wed, 22 Dec 2021 11:07:11 +0100 Subject: [PATCH 5/5] ls: fix windows string for dangling symlink test --- tests/by-util/test_ls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 33aa9494bcd..09efb542bf4 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -2277,7 +2277,7 @@ fn test_ls_dangling_symlinks() { .arg("-w40") .succeeds() // this should fail, though at the moment, ls lacks a way to propagate errors encountered during display .stdout_contains(if cfg!(windows) { - " dangle" + "dangle" } else { " ? dangle" });