Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2305,7 +2305,7 @@ fn should_display(entry: &DirEntry, config: &Config) -> bool {
#[allow(clippy::cognitive_complexity)]
fn enter_directory(
path_data: &PathData,
read_dir: ReadDir,
mut read_dir: ReadDir,
config: &Config,
state: &mut ListState,
listed_ancestors: &mut HashSet<FileInformation>,
Expand Down Expand Up @@ -2334,7 +2334,7 @@ fn enter_directory(
};

// Convert those entries to the PathData struct
for raw_entry in read_dir {
for raw_entry in read_dir.by_ref() {
let dir_entry = match raw_entry {
Ok(path) => path,
Err(err) => {
Expand Down
15 changes: 15 additions & 0 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6663,3 +6663,18 @@ fn test_f_with_long_format() {
// Long format should still work (contains permissions, etc.)
assert!(result.contains("-rw"));
}

#[test]
#[cfg(target_os = "linux")]
fn test_ls_proc_self_fd_no_errors() {
// Regression test: ReadDir must stay alive until metadata() is called
// to prevent "cannot access '/proc/self/fd/3'" errors.
let scene = TestScenario::new(util_name!());

scene
.ucmd()
.arg("-l")
.arg("/proc/self/fd")
.succeeds()
.stderr_does_not_contain("cannot access");
}
Loading