Merge pull request #8417 from drinkcat/du-ls-time-test

ls: -u/-c/--time control sorting when -l is not used
This commit is contained in:
Daniel Hofstetter
2025-07-31 15:55:40 +02:00
committed by GitHub
2 changed files with 26 additions and 10 deletions
+7
View File
@@ -472,6 +472,13 @@ fn extract_sort(options: &clap::ArgMatches) -> Sort {
Sort::Version
} else if options.get_flag(options::sort::EXTENSION) {
Sort::Extension
} else if !options.get_flag(options::format::LONG)
&& (options.get_flag(options::time::ACCESS)
|| options.get_flag(options::time::CHANGE)
|| options.get_one::<String>(options::TIME).is_some())
{
// If -l is not specified, -u/-c/--time controls sorting.
Sort::Time
} else {
Sort::Name
}
+19 -10
View File
@@ -2254,24 +2254,29 @@ fn test_ls_order_time() {
let result = scene.ucmd().arg("--sort=time").arg("-r").succeeds();
result.stdout_only("test-1\ntest-2\ntest-3\ntest-4\n");
let args: [&[&str]; 10] = [
&["-t", "-u"],
&["-u"], //-t is optional: when -l is not set -u/--time controls sorting
&["-t", "--time=atime"],
&["--time=atime"],
&["--time=atim"], // spell-checker:disable-line
&["--time=a"],
&["-t", "--time=access"],
&["--time=access"],
&["-t", "--time=use"],
&["--time=use"],
];
// 3 was accessed last in the read
// So the order should be 2 3 4 1
for arg in [
"-u",
"--time=atime",
"--time=atim", // spell-checker:disable-line
"--time=a",
"--time=access",
"--time=use",
] {
let result = scene.ucmd().arg("-t").arg(arg).succeeds();
for args in args {
let result = scene.ucmd().args(args).succeeds();
at.open("test-3").metadata().unwrap().accessed().unwrap();
at.open("test-4").metadata().unwrap().accessed().unwrap();
// It seems to be dependent on the platform whether the access time is actually set
#[cfg(unix)]
{
let expected = unwrap_or_return!(expected_result(&scene, &["-t", arg]));
let expected = unwrap_or_return!(expected_result(&scene, args));
at.open("test-3").metadata().unwrap().accessed().unwrap();
at.open("test-4").metadata().unwrap().accessed().unwrap();
@@ -2287,6 +2292,10 @@ fn test_ls_order_time() {
{
let result = scene.ucmd().arg("-tc").succeeds();
result.stdout_only("test-2\ntest-4\ntest-3\ntest-1\n");
// When -l is not set, -c also controls sorting
let result = scene.ucmd().arg("-c").succeeds();
result.stdout_only("test-2\ntest-4\ntest-3\ntest-1\n");
}
}