From 86738ce6cfe4a7b0cffd642f9896baac17bccc67 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Sun, 9 Oct 2022 00:27:32 +0200 Subject: [PATCH 1/9] ls,stat: Show more info in long format --- src/uucore/src/lib/features/fs.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 2d41db418..05f191c47 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -401,12 +401,26 @@ pub fn canonicalize>( } #[cfg(not(unix))] -#[allow(unused_variables)] pub fn display_permissions(metadata: &fs::Metadata, display_file_type: bool) -> String { + let write = if metadata.permissions().readonly() { + '-' + } else { + 'w' + }; + if display_file_type { - return String::from("----------"); + let file_type = if metadata.is_symlink() { + 'l' + } else if metadata.is_dir() { + 'd' + } else { + '-' + }; + + format!("{0}r{1}xr{1}xr{1}x", file_type, write) + } else { + format!("r{0}xr{0}xr{0}x", write) } - String::from("---------") } #[cfg(unix)] From b3e6472d025a005bfe804fd5323134486bd7db79 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Sun, 9 Oct 2022 12:03:44 +0200 Subject: [PATCH 2/9] test_ls: adapt to new windows permissions --- tests/by-util/test_ls.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index e083464d6..0ea88f751 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -964,9 +964,9 @@ fn test_ls_long() { let result = scene.ucmd().arg(arg).arg("test-long").succeeds(); #[cfg(not(windows))] result.stdout_matches(&Regex::new(r"[-bcCdDlMnpPsStTx?]([r-][w-][xt-]){3}.*").unwrap()); - + #[cfg(windows)] - result.stdout_contains("---------- 1 somebody somegroup"); + result.stdout_matches(&Regex::new(r"[-dl](r[w-]x){3}.*").unwrap()); } } From 538e8eca0b34f2492d94658af6fb8ddc708e1679 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 9 Oct 2022 20:03:06 +0200 Subject: [PATCH 3/9] Fix coding style --- tests/by-util/test_ls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 0ea88f751..f37a5ee81 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -964,7 +964,7 @@ fn test_ls_long() { let result = scene.ucmd().arg(arg).arg("test-long").succeeds(); #[cfg(not(windows))] result.stdout_matches(&Regex::new(r"[-bcCdDlMnpPsStTx?]([r-][w-][xt-]){3}.*").unwrap()); - + #[cfg(windows)] result.stdout_matches(&Regex::new(r"[-dl](r[w-]x){3}.*").unwrap()); } From 95e7b53402cc5d189a5336903a59b0fde807e590 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Mon, 12 Sep 2022 17:40:59 +0300 Subject: [PATCH 4/9] test_sort: make timeout smarter, wait if failed to create dir Before the change it slept for 0.1 seconds and right after that asserted if `sort` has created the directory. Sometimes `sort` didn't manage to create the directory in 0.1 seconds. So the change is it tries to wait for `timeout` starting with 0.1 seconds, and if directory was not found, it tries 4 more times, each time increasing timeout twice. Once the directory is found it breaks. --- tests/by-util/test_sort.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index ff4c79427..e0bfb6025 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -1124,7 +1124,14 @@ fn test_tmp_files_deleted_on_sigint() { ]); let mut child = ucmd.run_no_wait(); // wait a short amount of time so that `sort` can create a temporary directory. - std::thread::sleep(Duration::from_millis(100)); + let mut timeout = Duration::from_millis(100); + for _ in 0..5 { + std::thread::sleep(timeout); + if read_dir(at.plus("tmp_dir")).unwrap().next().is_some() { + break; + } + timeout *= 2; + } // `sort` should have created a temporary directory. assert!(read_dir(at.plus("tmp_dir")).unwrap().next().is_some()); // kill sort with SIGINT From ec8e610e48e156a9d42de97629c8dffc375223c0 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Mon, 12 Sep 2022 18:32:57 +0300 Subject: [PATCH 5/9] test_sort: created a new big file for sort Before, the sort could work faster and we could be late with the signal. Now we create a new big file, `sort` can't process it in a minute, so we can safely wait for the temporary directory to be created and send a signal afterwards --- tests/by-util/test_sort.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index e0bfb6025..cb0aa2683 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -1117,8 +1117,23 @@ fn test_tmp_files_deleted_on_sigint() { let (at, mut ucmd) = at_and_ucmd!(); at.mkdir("tmp_dir"); + let file_name = "big_file_to_sort.txt"; + { + use rand::Rng; + use std::io::Write; + let mut file = at.make_file(file_name); + // approximately 20 MB + for _ in 0..40 { + let lines = rand::thread_rng() + .sample_iter(rand::distributions::uniform::Uniform::new(0, 10007)) + .take(100000) + .map(|x| x.to_string() + "\n") + .collect::(); + file.write_all(lines.as_bytes()).unwrap(); + } + } ucmd.args(&[ - "ext_sort.txt", + file_name, "--buffer-size=1", // with a small buffer size `sort` will be forced to create a temporary directory very soon. "--temporary-directory=tmp_dir", ]); From 729d97e9939ad5143260bcb79fbb1c02e5315142 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Mon, 12 Sep 2022 19:36:51 +0300 Subject: [PATCH 6/9] test_sort: use Pcg32 random number generator --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + tests/by-util/test_sort.rs | 6 +++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1fefbb83c..e90824cb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -367,6 +367,7 @@ dependencies = [ "pretty_assertions", "procfs", "rand", + "rand_pcg", "regex", "rlimit", "selinux", @@ -1664,6 +1665,15 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rand_pcg" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" +dependencies = [ + "rand_core", +] + [[package]] name = "rayon" version = "1.5.3" diff --git a/Cargo.toml b/Cargo.toml index 6086b968e..2830ac531 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -391,6 +391,7 @@ glob = "0.3.0" libc = "0.2" pretty_assertions = "1" rand = "0.8" +rand_pcg = "0.3" regex = "1.6" sha1 = { version="0.10", features=["std"] } tempfile = "3" diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index cb0aa2683..5c753470a 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -1119,13 +1119,13 @@ fn test_tmp_files_deleted_on_sigint() { at.mkdir("tmp_dir"); let file_name = "big_file_to_sort.txt"; { - use rand::Rng; + use rand::{Rng, SeedableRng}; use std::io::Write; let mut file = at.make_file(file_name); // approximately 20 MB for _ in 0..40 { - let lines = rand::thread_rng() - .sample_iter(rand::distributions::uniform::Uniform::new(0, 10007)) + let lines = rand_pcg::Pcg32::seed_from_u64(123) + .sample_iter(rand::distributions::uniform::Uniform::new(0, 10000)) .take(100000) .map(|x| x.to_string() + "\n") .collect::(); From 43d85c648975a6e57e73923879d4a159e02d1ae4 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Mon, 12 Sep 2022 19:54:49 +0300 Subject: [PATCH 7/9] rand_pcg is used only in unix tests, moved to unix dev-dependencies --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2830ac531..ce528c41e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -391,7 +391,6 @@ glob = "0.3.0" libc = "0.2" pretty_assertions = "1" rand = "0.8" -rand_pcg = "0.3" regex = "1.6" sha1 = { version="0.10", features=["std"] } tempfile = "3" @@ -409,6 +408,7 @@ rlimit = "0.8.3" [target.'cfg(unix)'.dev-dependencies] nix = { version = "0.25", default-features = false, features = ["process", "signal", "user"] } rust-users = { version="0.11", package="users" } +rand_pcg = "0.3" [build-dependencies] phf_codegen = "0.11.1" From 5696059d51c668c3c29a35e502a0b28d86f332ad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 22 Oct 2022 08:21:48 +0000 Subject: [PATCH 8/9] build(deps): bump filetime from 0.2.17 to 0.2.18 Bumps [filetime](https://github.com/alexcrichton/filetime) from 0.2.17 to 0.2.18. - [Release notes](https://github.com/alexcrichton/filetime/releases) - [Commits](https://github.com/alexcrichton/filetime/compare/0.2.17...0.2.18) --- updated-dependencies: - dependency-name: filetime dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 6 +++--- src/uu/touch/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cc8cf8424..f19eebc73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -862,14 +862,14 @@ checksum = "31a7a908b8f32538a2143e59a6e4e2508988832d5d4d6f7c156b3cbc762643a5" [[package]] name = "filetime" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94a7bbaa59354bc20dd75b67f23e2797b4490e9d6928203fb105c79e448c86c" +checksum = "4b9663d381d07ae25dc88dbdf27df458faa83a9b25336bcac83d5e452b5fc9d3" dependencies = [ "cfg-if", "libc", "redox_syscall", - "windows-sys 0.36.1", + "windows-sys 0.42.0", ] [[package]] diff --git a/src/uu/touch/Cargo.toml b/src/uu/touch/Cargo.toml index a8fadffdb..7aae33ccf 100644 --- a/src/uu/touch/Cargo.toml +++ b/src/uu/touch/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" path = "src/touch.rs" [dependencies] -filetime = "0.2.17" +filetime = "0.2.18" clap = { version = "4.0", features = ["wrap_help", "cargo"] } time = { version = "0.3", features = ["parsing", "formatting", "local-offset", "macros"] } uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["libc"] } From 02f6fa7b249f44d4fa5b10c5f008fadaaa9d6f56 Mon Sep 17 00:00:00 2001 From: Huijeong Kim Date: Sat, 22 Oct 2022 18:23:39 +0900 Subject: [PATCH 9/9] hashsum: test b3sum::test_nonames for real (#4027) * hashsum: test b3sum::test_nonames for real Signed-off-by: Huijeong Kim * apply cargo format Signed-off-by: Huijeong Kim --- src/uu/hashsum/src/hashsum.rs | 9 ++++----- tests/by-util/test_hashsum.rs | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index 828436595..2d01c9d64 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -276,11 +276,10 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { }; let check = matches.get_flag("check"); let tag = matches.get_flag("tag"); - let nonames = if binary_name == "b3sum" { - matches.get_flag("no-names") - } else { - false - }; + let nonames = *matches + .try_get_one("no-names") + .unwrap_or(Some(&false)) + .unwrap(); let status = matches.get_flag("status"); let quiet = matches.get_flag("quiet") || status; let strict = matches.get_flag("strict"); diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index f30eb42ce..e8f716815 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -34,7 +34,7 @@ macro_rules! test_digest { fn test_nonames() { let ts = TestScenario::new("hashsum"); // EXPECTED_FILE has no newline character at the end - if DIGEST_ARG == "b3sum" { + if DIGEST_ARG == "--b3sum" { // Option only available on b3sum assert_eq!(format!("{0}\n{0}\n", ts.fixtures.read(EXPECTED_FILE)), ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).arg("--no-names").arg("input.txt").arg("-").pipe_in_fixture("input.txt")