From cd8574a47ca93105d2e52f361fcaa892f8a82766 Mon Sep 17 00:00:00 2001 From: electricboogie <32370782+kimono-koans@users.noreply.github.com> Date: Thu, 19 Mar 2026 13:49:57 -0500 Subject: [PATCH 1/5] Initial commit --- src/uu/ls/src/ls.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 507689eee41..68f7283e1e4 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -2188,8 +2188,10 @@ fn push_basic_escape(buf: &mut String, byte: u8) { } } } - -type DirData = (PathBuf, bool); +struct DirData { + path: PathBuf, + needs_blank_line: bool, +} // A struct to encapsulate state that is passed around from `list` functions. struct ListState<'a> { @@ -2298,15 +2300,13 @@ pub fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> { path_data.must_dereference, )?); + let dir_data = DirData { + path: path_data.path().to_path_buf(), + needs_blank_line, + }; + // List each of the arguments to ls first. - depth_first_list( - (path_data.path().to_path_buf(), needs_blank_line), - read_dir, - config, - &mut state, - &mut dired, - true, - )?; + depth_first_list(dir_data, read_dir, config, &mut state, &mut dired, true)?; // Only runs if it must list recursively. while let Some(dir_data) = state.stack.pop() { @@ -2453,7 +2453,7 @@ fn should_display(entry: &DirEntry, config: &Config) -> bool { } fn depth_first_list( - (dir_path, needs_blank_line): DirData, + dir_data: DirData, mut read_dir: ReadDir, config: &Config, state: &mut ListState, @@ -2579,7 +2579,13 @@ fn depth_first_list( if cap == len { state.stack.reserve_exact(len / 4 + 4); } - state.stack.push((e.path().to_path_buf(), true)); + + let dir_data = DirData { + path: path_data.path().to_path_buf(), + needs_blank_line: true, + }; + + state.stack.push(dir_data); } else { state.out.flush()?; show!(LsError::AlreadyListedError(e.path().to_path_buf())); From 3b98846488d5eaf42356ebb064b9cf3a0f2fdb44 Mon Sep 17 00:00:00 2001 From: electricboogie <32370782+kimono-koans@users.noreply.github.com> Date: Thu, 19 Mar 2026 13:57:26 -0500 Subject: [PATCH 2/5] Cleanup --- src/uu/ls/src/ls.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 68f7283e1e4..47d3d9cd423 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -2193,6 +2193,15 @@ struct DirData { needs_blank_line: bool, } +impl DirData { + fn new(path: &Path, needs_blank_line: bool) -> Self { + DirData { + path: path.to_path_buf(), + needs_blank_line, + } + } +} + // A struct to encapsulate state that is passed around from `list` functions. struct ListState<'a> { out: BufWriter, @@ -2300,10 +2309,7 @@ pub fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> { path_data.must_dereference, )?); - let dir_data = DirData { - path: path_data.path().to_path_buf(), - needs_blank_line, - }; + let dir_data = DirData::new(path_data.path(), needs_blank_line); // List each of the arguments to ls first. depth_first_list(dir_data, read_dir, config, &mut state, &mut dired, true)?; @@ -2580,10 +2586,7 @@ fn depth_first_list( state.stack.reserve_exact(len / 4 + 4); } - let dir_data = DirData { - path: path_data.path().to_path_buf(), - needs_blank_line: true, - }; + let dir_data = DirData::new(path_data.path(), true); state.stack.push(dir_data); } else { From d0b507919fa0b995c084c913f26a709342b20f00 Mon Sep 17 00:00:00 2001 From: electricboogie <32370782+kimono-koans@users.noreply.github.com> Date: Thu, 19 Mar 2026 14:14:44 -0500 Subject: [PATCH 3/5] Fix lints --- src/uu/ls/src/ls.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 47d3d9cd423..029ba5429a8 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -2466,12 +2466,12 @@ fn depth_first_list( dired: &mut DiredOutput, is_top_level: bool, ) -> UResult<()> { - let path_data = PathData::new(dir_path, None, None, config, false); + let path_data = PathData::new(dir_data.path, None, None, config, false); // Print dir heading - name... 'total' comes after error display if state.initial_locs_len > 1 || config.recursive { if is_top_level { - if needs_blank_line { + if dir_data.needs_blank_line { writeln!(state.out)?; if config.dired { dired.padding += 1; From d7d59d4c346525c6cfd995198d897eb7b43aa27e Mon Sep 17 00:00:00 2001 From: electricboogie <32370782+kimono-koans@users.noreply.github.com> Date: Thu, 19 Mar 2026 14:24:27 -0500 Subject: [PATCH 4/5] Fix lints --- src/uu/ls/src/ls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 029ba5429a8..c5d57afcc0c 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -2316,7 +2316,7 @@ pub fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> { // Only runs if it must list recursively. while let Some(dir_data) = state.stack.pop() { - let read_dir = match fs::read_dir(&dir_data.0) { + let read_dir = match fs::read_dir(&dir_data.path) { Err(err) => { // flush stdout buffer before the error to preserve formatting and order state.out.flush()?; From 7b09775753b8d436f9e7929a368de72de0d71ba8 Mon Sep 17 00:00:00 2001 From: electricboogie <32370782+kimono-koans@users.noreply.github.com> Date: Thu, 19 Mar 2026 14:38:54 -0500 Subject: [PATCH 5/5] Cleanup lint --- src/uu/ls/src/ls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index c5d57afcc0c..f85ba9db519 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -2195,7 +2195,7 @@ struct DirData { impl DirData { fn new(path: &Path, needs_blank_line: bool) -> Self { - DirData { + Self { path: path.to_path_buf(), needs_blank_line, }