From ea478c2bb64afcb31042f08207cb2384c74bf763 Mon Sep 17 00:00:00 2001 From: Pyokyeong Son <17530016+pyoky@users.noreply.github.com> Date: Fri, 5 Jul 2024 03:59:41 -0400 Subject: [PATCH] ls: fixed dired option (-D) not outputting datetime and parent dir byte offsets (#6538) Closes #6522 --- src/uu/ls/src/dired.rs | 2 +- src/uu/ls/src/ls.rs | 4 ++-- tests/by-util/test_ls.rs | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/uu/ls/src/dired.rs b/src/uu/ls/src/dired.rs index afb82a509..b039c8d90 100644 --- a/src/uu/ls/src/dired.rs +++ b/src/uu/ls/src/dired.rs @@ -110,7 +110,7 @@ pub fn print_dired_output( out: &mut BufWriter, ) -> UResult<()> { out.flush()?; - if dired.padding == 0 && !dired.dired_positions.is_empty() { + if !dired.dired_positions.is_empty() { print_positions("//DIRED//", &dired.dired_positions); } if config.recursive { diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index ce2c55dec..54682c34f 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -971,7 +971,8 @@ impl Config { let mut quoting_style = extract_quoting_style(options, show_control); let indicator_style = extract_indicator_style(options); // Only parse the value to "--time-style" if it will become relevant. - let time_style = if format == Format::Long { + let dired = options.get_flag(options::DIRED); + let time_style = if format == Format::Long || dired { parse_time_style(options)? } else { TimeStyle::Iso @@ -1092,7 +1093,6 @@ impl Config { None }; - let dired = options.get_flag(options::DIRED); if dired || is_dired_arg_present() { // --dired implies --format=long // if we have --dired --hyperlink, we don't show dired but we still want to see the diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 8eea0b88b..6346ea906 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -4058,6 +4058,42 @@ fn test_ls_dired_recursive() { .stdout_contains("//DIRED-OPTIONS// --quoting-style"); } +#[test] +fn test_ls_dired_outputs_parent_offset() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + at.mkdir("dir"); + at.mkdir("dir/a"); + scene + .ucmd() + .arg("--dired") + .arg("dir") + .arg("-R") + .succeeds() + .stdout_contains("//DIRED//"); +} + +#[test] +fn test_ls_dired_outputs_same_date_time_format() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + at.mkdir("dir"); + at.mkdir("dir/a"); + let binding = scene.ucmd().arg("-l").arg("dir").run(); + let long_output_str = binding.stdout_str(); + let split_lines: Vec<&str> = long_output_str.split('\n').collect(); + // the second line should contain the long output which includes date + let list_line = split_lines.get(1).unwrap(); + // should be same as the dired output + scene + .ucmd() + .arg("--dired") + .arg("dir") + .arg("-R") + .succeeds() + .stdout_contains(list_line); +} + #[test] fn test_ls_dired_recursive_multiple() { let scene = TestScenario::new(util_name!());