mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
ls: Improve error handling and other improvements (#2809)
* print error in the correct order by flushing the stdout buffer before printing an error * print correct GNU error codes * correct formatting for config.inode, and for dangling links * correct padding for Format::Long * remove colors after the -> link symbol as this doesn't match GNU * correct the major, minor #s for char devices, and correct padding * improve speed for all metadata intensive ops by not allocating metadata unless in a Sort mode * new tests, have struggled with how to deal with stderr, stdout ordering in a test though * tried to implement UIoError, but am still having issues matching the formatting of GNU Co-authored-by: electricboogie <32370782+electricboogie@users.noreply.github.com>
This commit is contained in:
parent
ae7190ec73
commit
421330d07a
2 changed files with 442 additions and 156 deletions
|
@ -11,7 +11,6 @@ use std::collections::HashMap;
|
|||
use std::path::Path;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
#[cfg(not(windows))]
|
||||
extern crate libc;
|
||||
#[cfg(not(windows))]
|
||||
|
@ -39,6 +38,75 @@ fn test_ls_i() {
|
|||
new_ucmd!().arg("-il").succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_ordering() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
at.mkdir("some-dir1");
|
||||
at.mkdir("some-dir2");
|
||||
at.mkdir("some-dir3");
|
||||
at.mkdir("some-dir4");
|
||||
at.mkdir("some-dir5");
|
||||
at.mkdir("some-dir6");
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-Rl")
|
||||
.succeeds()
|
||||
.stdout_matches(&Regex::new("some-dir1:\\ntotal 0").unwrap());
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "chmod"))]
|
||||
#[test]
|
||||
fn test_ls_io_errors() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
at.mkdir("some-dir1");
|
||||
at.mkdir("some-dir2");
|
||||
at.symlink_file("does_not_exist", "some-dir2/dangle");
|
||||
at.mkdir("some-dir3");
|
||||
at.mkdir("some-dir3/some-dir4");
|
||||
at.mkdir("some-dir3/some-dir5");
|
||||
at.mkdir("some-dir3/some-dir6");
|
||||
at.mkdir("some-dir3/some-dir7");
|
||||
at.mkdir("some-dir3/some-dir8");
|
||||
|
||||
scene.ccmd("chmod").arg("000").arg("some-dir1").succeeds();
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-1")
|
||||
.arg("some-dir1")
|
||||
.fails()
|
||||
.stderr_contains("cannot open directory")
|
||||
.stderr_contains("Permission denied");
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-Li")
|
||||
.arg("some-dir2")
|
||||
.fails()
|
||||
.stderr_contains("cannot access")
|
||||
.stderr_contains("No such file or directory")
|
||||
.stdout_contains(if cfg!(windows) { "dangle" } else { "? dangle" });
|
||||
|
||||
scene
|
||||
.ccmd("chmod")
|
||||
.arg("000")
|
||||
.arg("some-dir3/some-dir4")
|
||||
.succeeds();
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-laR")
|
||||
.arg("some-dir3")
|
||||
.fails()
|
||||
.stderr_contains("some-dir4")
|
||||
.stderr_contains("cannot open directory")
|
||||
.stderr_contains("Permission denied")
|
||||
.stdout_contains("some-dir4");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_walk_glob() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
@ -2303,8 +2371,16 @@ fn test_ls_dangling_symlinks() {
|
|||
.ucmd()
|
||||
.arg("-Li")
|
||||
.arg("temp_dir")
|
||||
.succeeds() // this should fail, though at the moment, ls lacks a way to propagate errors encountered during display
|
||||
.fails()
|
||||
.stderr_contains("cannot access")
|
||||
.stdout_contains(if cfg!(windows) { "dangle" } else { "? dangle" });
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-Ll")
|
||||
.arg("temp_dir")
|
||||
.fails()
|
||||
.stdout_contains("l?????????");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue