From cf7b90bbe7cb87099499876622f413a65a699038 Mon Sep 17 00:00:00 2001 From: Thomas Hurst Date: Tue, 28 Feb 2023 17:45:14 +0000 Subject: [PATCH 01/51] dd: use an alarm thread instead of elapsed() calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Quick benchmark on FreeBSD 13.1-RELEASE: Summary './dd-thread-alarm if=/dev/zero of=/dev/null count=4000000 status=progress' ran 1.17 ± 0.17 times faster than './dd-baseline if=/dev/zero of=/dev/null count=4000000 status=progress' --- src/uu/dd/src/dd.rs | 47 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index eaf89ca55..2baa12106 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -65,6 +65,46 @@ struct Settings { status: Option, } +use std::thread::sleep; +use std::time::Duration; + +use std::sync::{ + atomic::{AtomicBool, Ordering::Relaxed}, + Arc, +}; + +#[derive(Debug, Clone)] +pub struct Alarm { + interval: Duration, + trigger: Arc, +} + +impl Alarm { + pub fn with_interval(interval: Duration) -> Alarm { + let trigger = Arc::new(AtomicBool::default()); + + let weak_trigger = Arc::downgrade(&trigger); + std::thread::spawn(move || loop { + sleep(interval); + if let Some(trigger) = weak_trigger.upgrade() { + trigger.store(true, Relaxed); + } else { + break; + } + }); + + Alarm { interval, trigger } + } + + pub fn is_triggered(&self) -> bool { + self.trigger.swap(false, Relaxed) + } + + pub fn get_interval(&self) -> Duration { + self.interval + } +} + /// A number in blocks or bytes /// /// Some values (seek, skip, iseek, oseek) can have values either in blocks or in bytes. @@ -628,7 +668,6 @@ fn dd_copy(mut i: Input, mut o: Output) -> std::io::Result<()> { // information. let (prog_tx, rx) = mpsc::channel(); let output_thread = thread::spawn(gen_prog_updater(rx, i.settings.status)); - let mut progress_as_secs = 0; // Optimization: if no blocks are to be written, then don't // bother allocating any buffers. @@ -639,6 +678,7 @@ fn dd_copy(mut i: Input, mut o: Output) -> std::io::Result<()> { // Create a common buffer with a capacity of the block size. // This is the max size needed. let mut buf = vec![BUF_INIT_BYTE; bsize]; + let alarm = Alarm::with_interval(Duration::from_secs(1)); // The main read/write loop. // @@ -667,9 +707,8 @@ fn dd_copy(mut i: Input, mut o: Output) -> std::io::Result<()> { // error. rstat += rstat_update; wstat += wstat_update; - let prog_update = ProgUpdate::new(rstat, wstat, start.elapsed(), false); - if prog_update.duration.as_secs() >= progress_as_secs { - progress_as_secs = prog_update.duration.as_secs() + 1; + if alarm.is_triggered() { + let prog_update = ProgUpdate::new(rstat, wstat, start.elapsed(), false); prog_tx.send(prog_update).unwrap_or(()); } } From 52c93a4d107a6252c4cfe85c572075cacc493272 Mon Sep 17 00:00:00 2001 From: Thomas Hurst Date: Wed, 1 Mar 2023 13:56:18 +0000 Subject: [PATCH 02/51] dd: Simplify loop of progress Alarm thread --- src/uu/dd/src/dd.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 2baa12106..15c7e8ed4 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -80,20 +80,18 @@ pub struct Alarm { } impl Alarm { - pub fn with_interval(interval: Duration) -> Alarm { + pub fn with_interval(interval: Duration) -> Self { let trigger = Arc::new(AtomicBool::default()); let weak_trigger = Arc::downgrade(&trigger); - std::thread::spawn(move || loop { - sleep(interval); - if let Some(trigger) = weak_trigger.upgrade() { + std::thread::spawn(move || { + while let Some(trigger) = weak_trigger.upgrade() { + sleep(interval); trigger.store(true, Relaxed); - } else { - break; } }); - Alarm { interval, trigger } + Self { interval, trigger } } pub fn is_triggered(&self) -> bool { From 546631c8e77bb6256d6b211306ed71b5bbf0e16f Mon Sep 17 00:00:00 2001 From: Thomas Hurst Date: Wed, 3 May 2023 16:30:53 +0000 Subject: [PATCH 03/51] dd: Tidy includes --- src/uu/dd/src/dd.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 15c7e8ed4..541c85ff9 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -33,9 +33,12 @@ use std::os::unix::fs::FileTypeExt; #[cfg(any(target_os = "linux", target_os = "android"))] use std::os::unix::fs::OpenOptionsExt; use std::path::Path; -use std::sync::mpsc; +use std::sync::{ + atomic::{AtomicBool, Ordering::Relaxed}, + mpsc, Arc, +}; use std::thread; -use std::time; +use std::time::{Duration, Instant}; use clap::{crate_version, Arg, Command}; use gcd::Gcd; @@ -65,14 +68,6 @@ struct Settings { status: Option, } -use std::thread::sleep; -use std::time::Duration; - -use std::sync::{ - atomic::{AtomicBool, Ordering::Relaxed}, - Arc, -}; - #[derive(Debug, Clone)] pub struct Alarm { interval: Duration, @@ -84,9 +79,9 @@ impl Alarm { let trigger = Arc::new(AtomicBool::default()); let weak_trigger = Arc::downgrade(&trigger); - std::thread::spawn(move || { + thread::spawn(move || { while let Some(trigger) = weak_trigger.upgrade() { - sleep(interval); + thread::sleep(interval); trigger.store(true, Relaxed); } }); @@ -646,7 +641,7 @@ fn dd_copy(mut i: Input, mut o: Output) -> std::io::Result<()> { // of its report includes the throughput in bytes per second, // which requires knowing how long the process has been // running. - let start = time::Instant::now(); + let start = Instant::now(); // A good buffer size for reading. // @@ -718,7 +713,7 @@ fn finalize( output: &mut Output, rstat: ReadStat, wstat: WriteStat, - start: time::Instant, + start: Instant, prog_tx: &mpsc::Sender, output_thread: thread::JoinHandle, ) -> std::io::Result<()> { From 01a8623d216599449f6c895996e6ba64c12fbd89 Mon Sep 17 00:00:00 2001 From: Thomas Hurst Date: Wed, 3 May 2023 16:31:14 +0000 Subject: [PATCH 04/51] dd: Add documentation to Alarm struct --- src/uu/dd/src/dd.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 541c85ff9..41b7eb773 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -68,6 +68,15 @@ struct Settings { status: Option, } +/// A timer which triggers on a given interval +/// +/// After being constructed with [`Alarm::with_interval`], [`Alarm::is_triggered`] +/// will return true once per the given [`Duration`]. +/// +/// Can be cloned, but the trigger status is shared across all instances so only +/// the first caller each interval will yield true. +/// +/// When all instances are dropped the background thread will exit on the next interval. #[derive(Debug, Clone)] pub struct Alarm { interval: Duration, @@ -671,6 +680,11 @@ fn dd_copy(mut i: Input, mut o: Output) -> std::io::Result<()> { // Create a common buffer with a capacity of the block size. // This is the max size needed. let mut buf = vec![BUF_INIT_BYTE; bsize]; + + // Spawn a timer thread to provide a scheduled signal indicating when we + // should send an update of our progress to the reporting thread. + // + // This avoids the need to query the OS monotonic clock for every block. let alarm = Alarm::with_interval(Duration::from_secs(1)); // The main read/write loop. From 7a449feaa0a414f5cac208fcbe552f4b3e87f879 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 1 Jun 2023 10:43:09 +0200 Subject: [PATCH 05/51] Bump fundu from 0.5.1 to 1.0.0 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c38199dca..b657c84fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -957,9 +957,9 @@ dependencies = [ [[package]] name = "fundu" -version = "0.5.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a37cfff04a32112c22c5497b20b0b09100fca406e76afd47b2ba5ab33d7a851" +checksum = "47af3b646bdd738395be2db903fc11a5923b5e206016b8d4ad6db890bcae9bd5" [[package]] name = "futures" diff --git a/Cargo.toml b/Cargo.toml index ebd9a4bf4..409b03159 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -282,7 +282,7 @@ filetime = "0.2" fnv = "1.0.7" fs_extra = "1.3.0" fts-sys = "0.2" -fundu = "0.5.1" +fundu = "1.0.0" gcd = "2.3" glob = "0.3.1" half = "2.2" From ccee02f0257b44ab376c8fb5a3377099ca713b20 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 1 Jun 2023 10:57:54 +0200 Subject: [PATCH 06/51] sleep: fix compile error due to fundu update --- src/uu/sleep/src/sleep.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/uu/sleep/src/sleep.rs b/src/uu/sleep/src/sleep.rs index 009986095..8acb7724f 100644 --- a/src/uu/sleep/src/sleep.rs +++ b/src/uu/sleep/src/sleep.rs @@ -14,7 +14,7 @@ use uucore::{ }; use clap::{crate_version, Arg, ArgAction, Command}; -use fundu::{self, DurationParser, ParseError}; +use fundu::{self, DurationParser, ParseError, SaturatingInto}; static ABOUT: &str = help_about!("sleep.md"); const USAGE: &str = help_usage!("sleep.md"); @@ -63,7 +63,7 @@ pub fn uu_app() -> Command { fn sleep(args: &[&str]) -> UResult<()> { let mut arg_error = false; - use fundu::TimeUnit::*; + use fundu::TimeUnit::{Day, Hour, Minute, Second}; let parser = DurationParser::with_time_units(&[Second, Minute, Hour, Day]); let sleep_dur = args @@ -91,7 +91,9 @@ fn sleep(args: &[&str]) -> UResult<()> { None } }) - .fold(Duration::ZERO, |acc, n| acc.saturating_add(n)); + .fold(Duration::ZERO, |acc, n| { + acc.saturating_add(SaturatingInto::::saturating_into(n)) + }); if arg_error { return Err(UUsageError::new(1, "")); From b6c02c1a236d83d6f538d045eb02e6ce3eddf8eb Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 1 Jun 2023 15:30:43 +0200 Subject: [PATCH 07/51] tail: fix compile error due to fundu update --- src/uu/tail/src/args.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/uu/tail/src/args.rs b/src/uu/tail/src/args.rs index 5fb5ef2b3..c054017c2 100644 --- a/src/uu/tail/src/args.rs +++ b/src/uu/tail/src/args.rs @@ -9,7 +9,7 @@ use crate::paths::Input; use crate::{parse, platform, Quotable}; use clap::crate_version; use clap::{Arg, ArgAction, ArgMatches, Command}; -use fundu::DurationParser; +use fundu::{DurationParser, SaturatingInto}; use is_terminal::IsTerminal; use same_file::Handle; use std::collections::VecDeque; @@ -235,12 +235,15 @@ impl Settings { // `DURATION::MAX` or `infinity` was given // * not applied here but it supports customizable time units and provides better error // messages - settings.sleep_sec = - DurationParser::without_time_units() - .parse(source) - .map_err(|_| { - UUsageError::new(1, format!("invalid number of seconds: '{source}'")) - })?; + settings.sleep_sec = match DurationParser::without_time_units().parse(source) { + Ok(duration) => SaturatingInto::::saturating_into(duration), + Err(_) => { + return Err(UUsageError::new( + 1, + format!("invalid number of seconds: '{source}'"), + )) + } + } } if let Some(s) = matches.get_one::(options::MAX_UNCHANGED_STATS) { From 65a8e1540cb6cda640ca0125d420e83748c5ebcb Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Mon, 5 Jun 2023 10:09:03 +0200 Subject: [PATCH 08/51] Bump getrandom from 0.2.8 to 0.2.9 --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4c2af231b..7b9b230c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1073,9 +1073,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" dependencies = [ "cfg-if", "libc", From e817e6fc27cc61cc754de3ab418522c6ef74b3a1 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 8 Jun 2023 10:52:15 +0200 Subject: [PATCH 09/51] deny.toml: add comments --- deny.toml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/deny.toml b/deny.toml index 3aaee354a..57e432767 100644 --- a/deny.toml +++ b/deny.toml @@ -63,16 +63,25 @@ skip = [ { name = "hermit-abi", version = "0.3.1" }, # procfs { name = "rustix", version = "0.36.14" }, + # rustix { name = "linux-raw-sys", version = "0.1.4" }, # various crates { name = "windows-sys", version = "0.45.0" }, + # windows-sys { name = "windows-targets", version = "0.42.2" }, + # windows-targets { name = "windows_aarch64_gnullvm", version = "0.42.2" }, + # windows-targets { name = "windows_aarch64_msvc", version = "0.42.2" }, + # windows-targets { name = "windows_i686_gnu", version = "0.42.2" }, + # windows-targets { name = "windows_i686_msvc", version = "0.42.2" }, + # windows-targets { name = "windows_x86_64_gnu", version = "0.42.2" }, + # windows-targets { name = "windows_x86_64_gnullvm", version = "0.42.2" }, + # windows-targets { name = "windows_x86_64_msvc", version = "0.42.2" }, # tempfile { name = "redox_syscall", version = "0.3.5" }, From d26c596a4ceb609d306732afcf95215324ef135e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 8 Jun 2023 11:02:36 +0000 Subject: [PATCH 10/51] fix(deps): update rust crate memmap2 to 0.7 --- Cargo.lock | 4 ++-- src/uu/tac/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87b64c4ef..10f1bf040 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1405,9 +1405,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memmap2" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9ff02d2efdc645fca1ee55f45545b996e7da776b5b60c4e170334457551693" +checksum = "180d4b35be83d33392d1d1bfbd2ae1eca7ff5de1a94d3fc87faaa99a069e7cbd" dependencies = [ "libc", ] diff --git a/src/uu/tac/Cargo.toml b/src/uu/tac/Cargo.toml index a1c2e076a..4455ebe13 100644 --- a/src/uu/tac/Cargo.toml +++ b/src/uu/tac/Cargo.toml @@ -18,7 +18,7 @@ path = "src/tac.rs" [dependencies] memchr = { workspace = true } -memmap2 = "0.6" +memmap2 = "0.7" regex = { workspace = true } clap = { workspace = true } uucore = { workspace = true } From e1fd9e5342484c6a1943a26977a69c502da9fd30 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 8 Jun 2023 22:55:22 +0000 Subject: [PATCH 11/51] chore(deps): update rust crate blake3 to 1.4.0 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 10f1bf040..0357f7fe0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -192,9 +192,9 @@ dependencies = [ [[package]] name = "blake3" -version = "1.3.3" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ae2468a89544a466886840aa467a25b766499f4f04bf7d9fcd10ecee9fccef" +checksum = "729b71f35bd3fa1a4c86b85d32c8b9069ea7fe14f7a53cfabb65f62d4265b888" dependencies = [ "arrayref", "arrayvec", diff --git a/Cargo.toml b/Cargo.toml index 179584604..3d20bb97d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -338,7 +338,7 @@ sha1 = "0.10.5" sha2 = "0.10.6" sha3 = "0.10.8" blake2b_simd = "1.0.1" -blake3 = "1.3.3" +blake3 = "1.4.0" sm3 = "0.4.2" digest = "0.10.7" From ad96a1b8a065fa42903079d9c2b296700954908b Mon Sep 17 00:00:00 2001 From: Frantisek Kropac Date: Sat, 10 Jun 2023 09:22:01 +0200 Subject: [PATCH 12/51] Find MountInfo properly when symlink is used (#4929) * Find MountInfo properly when symlink is entered According to GNU implementation the entered path is being compared with the canonicalized device name in MountInfo. Co-authored-by: Frantisek Kropac Co-authored-by: Sylvestre Ledru --- Cargo.lock | 1 + src/uu/df/Cargo.toml | 3 +++ src/uu/df/src/filesystem.rs | 24 ++++++++++++++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0357f7fe0..b7f071c5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2562,6 +2562,7 @@ name = "uu_df" version = "0.0.19" dependencies = [ "clap", + "tempfile", "unicode-width", "uucore", ] diff --git a/src/uu/df/Cargo.toml b/src/uu/df/Cargo.toml index 0974a443c..2be3967af 100644 --- a/src/uu/df/Cargo.toml +++ b/src/uu/df/Cargo.toml @@ -19,6 +19,9 @@ clap = { workspace = true } uucore = { workspace = true, features = ["libc", "fsext"] } unicode-width = { workspace = true } +[dev-dependencies] +tempfile = "3" + [[bin]] name = "df" path = "src/main.rs" diff --git a/src/uu/df/src/filesystem.rs b/src/uu/df/src/filesystem.rs index 461815e67..813846a6c 100644 --- a/src/uu/df/src/filesystem.rs +++ b/src/uu/df/src/filesystem.rs @@ -42,7 +42,7 @@ pub(crate) struct Filesystem { /// This function returns the element of `mounts` on which `path` is /// mounted. If there are no matches, this function returns /// [`None`]. If there are two or more matches, then the single -/// [`MountInfo`] with the longest mount directory is returned. +/// [`MountInfo`] with the device name corresponding to the entered path. /// /// If `canonicalize` is `true`, then the `path` is canonicalized /// before checking whether it matches any mount directories. @@ -68,9 +68,19 @@ where path.as_ref().to_path_buf() }; + // Find the potential mount point that matches entered path let maybe_mount_point = mounts .iter() - .find(|mi| mi.dev_name.eq(&path.to_string_lossy())); + // Create pair MountInfo, canonicalized device name + // TODO Abstract from accessing real filesystem to + // make code more testable + .map(|m| (m, std::fs::canonicalize(&m.dev_name))) + // Ignore non existing paths + .filter(|m| m.1.is_ok()) + .map(|m| (m.0, m.1.ok().unwrap())) + // Try to find canonicalized device name corresponding to entered path + .find(|m| m.1.eq(&path)) + .map(|m| m.0); maybe_mount_point.or_else(|| { mounts @@ -211,10 +221,16 @@ mod tests { #[test] fn test_dev_name_match() { + let tmp = tempfile::TempDir::new().expect("Failed to create temp dir"); + let dev_name = std::fs::canonicalize(tmp.path()) + .expect("Failed to canonicalize tmp path") + .to_string_lossy() + .to_string(); + let mut mount_info = mount_info("/foo"); - mount_info.dev_name = "/dev/sda2".to_string(); + mount_info.dev_name = dev_name.clone(); let mounts = [mount_info]; - let actual = mount_info_from_path(&mounts, "/dev/sda2", false).unwrap(); + let actual = mount_info_from_path(&mounts, dev_name, false).unwrap(); assert!(mount_info_eq(actual, &mounts[0])); } } From ab42b1e5995dec8dfbf145c0229afc9a0c71d920 Mon Sep 17 00:00:00 2001 From: Rayhan Faizel Date: Sat, 10 Jun 2023 18:31:30 +0530 Subject: [PATCH 13/51] uucore: add function which checks hardlink as well as directed symlink --- src/uucore/src/lib/features/fs.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 797be9c2c..a97e8ac9c 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -648,6 +648,36 @@ pub fn are_hardlinks_to_same_file(source: &Path, target: &Path) -> bool { source_metadata.ino() == target_metadata.ino() && source_metadata.dev() == target_metadata.dev() } +#[cfg(not(unix))] +pub fn are_hardlinks_or_one_way_symlink_to_same_file(_source: &Path, _target: &Path) -> bool { + false +} + +/// Checks if either two paths are hard links to the same file or if the source path is a symbolic link which when fully resolved points to target path +/// +/// # Arguments +/// +/// * `source` - A reference to a `Path` representing the source path. +/// * `target` - A reference to a `Path` representing the target path. +/// +/// # Returns +/// +/// * `bool` - Returns `true` if either of above conditions are true, and `false` otherwise. +#[cfg(unix)] +pub fn are_hardlinks_or_one_way_symlink_to_same_file(source: &Path, target: &Path) -> bool { + let source_metadata = match fs::metadata(source) { + Ok(metadata) => metadata, + Err(_) => return false, + }; + + let target_metadata = match fs::symlink_metadata(target) { + Ok(metadata) => metadata, + Err(_) => return false, + }; + + source_metadata.ino() == target_metadata.ino() && source_metadata.dev() == target_metadata.dev() +} + #[cfg(test)] mod tests { // Note this useful idiom: importing names from outer (for mod tests) scope. From 28ad5cab9f25f15e6584ac6eb97dec301670dc31 Mon Sep 17 00:00:00 2001 From: Rayhan Faizel Date: Sat, 10 Jun 2023 18:32:09 +0530 Subject: [PATCH 14/51] mv: fix GNU test tests/mv/into-self-2.sh --- src/uu/mv/src/mv.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 5ca677c69..523183b0b 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -25,7 +25,7 @@ use std::path::{Path, PathBuf}; use uucore::backup_control::{self, BackupMode}; use uucore::display::Quotable; use uucore::error::{set_exit_code, FromIo, UError, UResult, USimpleError, UUsageError}; -use uucore::fs::are_hardlinks_to_same_file; +use uucore::fs::are_hardlinks_or_one_way_symlink_to_same_file; use uucore::update_control::{self, UpdateMode}; use uucore::{format_usage, help_about, help_section, help_usage, prompt_yes, show}; @@ -255,7 +255,7 @@ fn handle_two_paths(source: &Path, target: &Path, b: &Behavior) -> UResult<()> { return Err(MvError::NoSuchFile(source.quote().to_string()).into()); } - if (source.eq(target) || are_hardlinks_to_same_file(source, target)) + if (source.eq(target) || are_hardlinks_or_one_way_symlink_to_same_file(source, target)) && b.backup != BackupMode::SimpleBackup { if source.eq(Path::new(".")) || source.ends_with("/.") || source.is_file() { From 6bc15aac99d6fd77d09fa8cc88b109f6a18c39d5 Mon Sep 17 00:00:00 2001 From: Rayhan Faizel Date: Sat, 10 Jun 2023 18:32:41 +0530 Subject: [PATCH 15/51] tests/mv: Test for particular edge cases when handling symlink files --- tests/by-util/test_mv.rs | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index f73d3249d..cef95d195 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -417,6 +417,54 @@ fn test_mv_same_hardlink() { .stderr_is(format!("mv: '{file_a}' and '{file_b}' are the same file\n",)); } +#[test] +#[cfg(all(unix, not(target_os = "android")))] +fn test_mv_same_symlink() { + let (at, mut ucmd) = at_and_ucmd!(); + let file_a = "test_mv_same_file_a"; + let file_b = "test_mv_same_file_b"; + let file_c = "test_mv_same_file_c"; + + at.touch(file_a); + + at.symlink_file(file_a, file_b); + + ucmd.arg(file_b) + .arg(file_a) + .fails() + .stderr_is(format!("mv: '{file_b}' and '{file_a}' are the same file\n",)); + + let (at2, mut ucmd2) = at_and_ucmd!(); + at2.touch(file_a); + + at2.symlink_file(file_a, file_b); + ucmd2.arg(file_a).arg(file_b).succeeds(); + assert!(at2.file_exists(file_b)); + assert!(!at2.file_exists(file_a)); + + let (at3, mut ucmd3) = at_and_ucmd!(); + at3.touch(file_a); + + at3.symlink_file(file_a, file_b); + at3.symlink_file(file_b, file_c); + + ucmd3.arg(file_c).arg(file_b).succeeds(); + assert!(!at3.symlink_exists(file_c)); + assert!(at3.symlink_exists(file_b)); + + let (at4, mut ucmd4) = at_and_ucmd!(); + at4.touch(file_a); + + at4.symlink_file(file_a, file_b); + at4.symlink_file(file_b, file_c); + + ucmd4 + .arg(file_c) + .arg(file_a) + .fails() + .stderr_is(format!("mv: '{file_c}' and '{file_a}' are the same file\n",)); +} + #[test] #[cfg(all(unix, not(target_os = "android")))] fn test_mv_same_hardlink_backup_simple() { From 67114ac63c580a7a7ff9e75ef7605b3d20385c91 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Sun, 11 Jun 2023 14:05:26 +0200 Subject: [PATCH 16/51] date: switch to parse_datetime --- Cargo.lock | 24 ++++++++++++------------ Cargo.toml | 4 ++-- deny.toml | 2 -- src/uu/date/Cargo.toml | 4 ++-- src/uu/date/src/date.rs | 4 ++-- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bba47cff6..a92d01416 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1154,16 +1154,6 @@ dependencies = [ "time", ] -[[package]] -name = "humantime_to_duration" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a80a233096ddccb74e62145f3a49cacea6a2669ee90f6e144e15fe28f4037c4" -dependencies = [ - "chrono", - "regex", -] - [[package]] name = "iana-time-zone" version = "0.1.53" @@ -1654,6 +1644,16 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "parse_datetime" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fecceaede7767a9a98058687a321bc91742eff7670167a34104afb30fc8757df" +dependencies = [ + "chrono", + "regex", +] + [[package]] name = "peeking_take_while" version = "0.1.2" @@ -2539,8 +2539,8 @@ version = "0.0.19" dependencies = [ "chrono", "clap", - "humantime_to_duration 0.3.1", "libc", + "parse_datetime", "uucore", "windows-sys 0.48.0", ] @@ -3235,7 +3235,7 @@ version = "0.0.19" dependencies = [ "clap", "filetime", - "humantime_to_duration 0.2.1", + "humantime_to_duration", "time", "uucore", "windows-sys 0.48.0", diff --git a/Cargo.toml b/Cargo.toml index 6f7cec3c9..09e120957 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ # coreutils (uutils) # * see the repository LICENSE, README, and CONTRIBUTING files for more information -# spell-checker:ignore (libs) libselinux gethostid procfs bigdecimal kqueue fundu mangen humantime uuhelp +# spell-checker:ignore (libs) libselinux gethostid procfs bigdecimal kqueue fundu mangen datetime uuhelp [package] name = "coreutils" @@ -284,7 +284,6 @@ fundu = "1.0.0" gcd = "2.3" glob = "0.3.1" half = "2.2" -humantime_to_duration = "0.3.1" indicatif = "0.17" is-terminal = "0.4.7" itertools = "0.10.5" @@ -302,6 +301,7 @@ number_prefix = "0.4" once_cell = "1.18.0" onig = { version = "~6.4", default-features = false } ouroboros = "0.15.6" +parse_datetime = "0.4.0" phf = "0.11.1" phf_codegen = "0.11.1" platform-info = "2.0.1" diff --git a/deny.toml b/deny.toml index 57e432767..8687fbfae 100644 --- a/deny.toml +++ b/deny.toml @@ -87,8 +87,6 @@ skip = [ { name = "redox_syscall", version = "0.3.5" }, # cpp_macros { name = "aho-corasick", version = "0.7.19" }, - # touch, can be remove when touch switches from time to chrono - { name = "humantime_to_duration", version = "0.2.1" }, ] # spell-checker: enable diff --git a/src/uu/date/Cargo.toml b/src/uu/date/Cargo.toml index 62308bf53..e28762493 100644 --- a/src/uu/date/Cargo.toml +++ b/src/uu/date/Cargo.toml @@ -1,4 +1,4 @@ -# spell-checker:ignore humantime +# spell-checker:ignore datetime [package] name = "uu_date" version = "0.0.19" @@ -19,7 +19,7 @@ path = "src/date.rs" chrono = { workspace = true } clap = { workspace = true } uucore = { workspace = true } -humantime_to_duration = { workspace = true } +parse_datetime = { workspace = true } [target.'cfg(unix)'.dependencies] libc = { workspace = true } diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index 44b54be5e..7bd64839c 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -6,7 +6,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -// spell-checker:ignore (chrono) Datelike Timelike ; (format) DATEFILE MMDDhhmm ; (vars) datetime datetimes humantime +// spell-checker:ignore (chrono) Datelike Timelike ; (format) DATEFILE MMDDhhmm ; (vars) datetime datetimes use chrono::format::{Item, StrftimeItems}; use chrono::{DateTime, Duration, FixedOffset, Local, Offset, Utc}; @@ -170,7 +170,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { }; let date_source = if let Some(date) = matches.get_one::(OPT_DATE) { - if let Ok(duration) = humantime_to_duration::from_str(date.as_str()) { + if let Ok(duration) = parse_datetime::from_str(date.as_str()) { DateSource::Human(duration) } else { DateSource::Custom(date.into()) From 18cbb862e21380d7714b2a0729fe2aea323c83d0 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 11 Jun 2023 18:53:42 +0200 Subject: [PATCH 17/51] Create a FUNDING.yml file The sponsor will be used for improving the CI machines on github --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..ccae1f831 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: uutils From c113284a4bf6441e59d621bc1022f23d48405f85 Mon Sep 17 00:00:00 2001 From: Rayhan Faizel Date: Mon, 12 Jun 2023 23:46:33 +0530 Subject: [PATCH 18/51] uucore: modify are_hardlinks_to_same_file to check only immediate metadata --- src/uucore/src/lib/features/fs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index a97e8ac9c..e92d0977f 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -635,12 +635,12 @@ pub fn are_hardlinks_to_same_file(_source: &Path, _target: &Path) -> bool { /// * `bool` - Returns `true` if the paths are hard links to the same file, and `false` otherwise. #[cfg(unix)] pub fn are_hardlinks_to_same_file(source: &Path, target: &Path) -> bool { - let source_metadata = match fs::metadata(source) { + let source_metadata = match fs::symlink_metadata(source) { Ok(metadata) => metadata, Err(_) => return false, }; - let target_metadata = match fs::metadata(target) { + let target_metadata = match fs::symlink_metadata(target) { Ok(metadata) => metadata, Err(_) => return false, }; From fa11315ce7f2b47c098cb5b3741a0b0b1e11eb9e Mon Sep 17 00:00:00 2001 From: Rayhan Faizel Date: Mon, 12 Jun 2023 23:48:49 +0530 Subject: [PATCH 19/51] mv: check strictly for hard links first before checking for symlinks to catch a very special case, plus ensure only nobackupmode is considered --- src/uu/mv/src/mv.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 523183b0b..6289e79f9 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -25,7 +25,7 @@ use std::path::{Path, PathBuf}; use uucore::backup_control::{self, BackupMode}; use uucore::display::Quotable; use uucore::error::{set_exit_code, FromIo, UError, UResult, USimpleError, UUsageError}; -use uucore::fs::are_hardlinks_or_one_way_symlink_to_same_file; +use uucore::fs::{are_hardlinks_or_one_way_symlink_to_same_file, are_hardlinks_to_same_file}; use uucore::update_control::{self, UpdateMode}; use uucore::{format_usage, help_about, help_section, help_usage, prompt_yes, show}; @@ -255,8 +255,10 @@ fn handle_two_paths(source: &Path, target: &Path, b: &Behavior) -> UResult<()> { return Err(MvError::NoSuchFile(source.quote().to_string()).into()); } - if (source.eq(target) || are_hardlinks_or_one_way_symlink_to_same_file(source, target)) - && b.backup != BackupMode::SimpleBackup + if (source.eq(target) + || are_hardlinks_to_same_file(source, target) + || are_hardlinks_or_one_way_symlink_to_same_file(source, target)) + && b.backup == BackupMode::NoBackup { if source.eq(Path::new(".")) || source.ends_with("/.") || source.is_file() { return Err( From 269ffc12b47243fcd16dcda561eee558f4eb12dd Mon Sep 17 00:00:00 2001 From: Rayhan Faizel Date: Mon, 12 Jun 2023 23:49:28 +0530 Subject: [PATCH 20/51] tests/mv: add tests to check for copying symlinks onto hardlinks to symlink --- tests/by-util/test_mv.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index cef95d195..0c292c50d 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -465,6 +465,35 @@ fn test_mv_same_symlink() { .stderr_is(format!("mv: '{file_c}' and '{file_a}' are the same file\n",)); } +#[test] +#[cfg(all(unix, not(target_os = "android")))] +fn test_mv_hardlink_to_symlink() { + let (at, mut ucmd) = at_and_ucmd!(); + let file = "file"; + let symlink_file = "symlink"; + let hardlink_to_symlink_file = "hardlink_to_symlink"; + + at.touch(file); + at.symlink_file(file, symlink_file); + at.hard_link(symlink_file, hardlink_to_symlink_file); + + ucmd.arg(symlink_file).arg(hardlink_to_symlink_file).fails(); + + let (at2, mut ucmd2) = at_and_ucmd!(); + + at2.touch(file); + at2.symlink_file(file, symlink_file); + at2.hard_link(symlink_file, hardlink_to_symlink_file); + + ucmd2 + .arg("--backup") + .arg(symlink_file) + .arg(hardlink_to_symlink_file) + .succeeds(); + assert!(!at2.symlink_exists(symlink_file)); + assert!(at2.symlink_exists(&format!("{hardlink_to_symlink_file}~"))); +} + #[test] #[cfg(all(unix, not(target_os = "android")))] fn test_mv_same_hardlink_backup_simple() { From fe5bf911e54cd0a7631061d62a08372c1ff333c8 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 13 Jun 2023 06:09:54 +0000 Subject: [PATCH 21/51] chore(deps): update davidanson/markdownlint-cli2-action action to v11 --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index b52ea5098..47da567b2 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -319,7 +319,7 @@ jobs: shell: bash run: | RUSTDOCFLAGS="-Dwarnings" cargo doc ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} --no-deps --workspace --document-private-items - - uses: DavidAnson/markdownlint-cli2-action@v10 + - uses: DavidAnson/markdownlint-cli2-action@v11 with: command: fix globs: | From 3506dd11b8562e08c9cb3f0a7abc69ac514de5d0 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 15 Jun 2023 19:18:09 +0000 Subject: [PATCH 22/51] chore(deps): update rust crate sha2 to 0.10.7 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a92d01416..84d6a9c34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2096,9 +2096,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" dependencies = [ "cfg-if", "cpufeatures", diff --git a/Cargo.toml b/Cargo.toml index 09e120957..a7df5d46a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -335,7 +335,7 @@ zip = { version = "0.6.6", default_features = false, features = ["deflate"] } hex = "0.4.3" md-5 = "0.10.5" sha1 = "0.10.5" -sha2 = "0.10.6" +sha2 = "0.10.7" sha3 = "0.10.8" blake2b_simd = "1.0.1" blake3 = "1.4.0" From 6865f91fd3b92ea9338ef4c7a2c96780a195c926 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 16 Jun 2023 00:01:15 +0000 Subject: [PATCH 23/51] chore(deps): update rust crate notify to v6.0.1 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a92d01416..1c9553fe6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1462,9 +1462,9 @@ dependencies = [ [[package]] name = "notify" -version = "6.0.0" +version = "6.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d9ba6c734de18ca27c8cef5cd7058aa4ac9f63596131e4c7e41e579319032a2" +checksum = "5738a2795d57ea20abec2d6d76c6081186709c0024187cd5977265eda6598b51" dependencies = [ "bitflags", "crossbeam-channel", diff --git a/Cargo.toml b/Cargo.toml index 09e120957..d35f38ddb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -294,7 +294,7 @@ lscolors = { version = "0.14.0", default-features = false, features = [ memchr = "2" nix = { version = "0.26", default-features = false } nom = "7.1.3" -notify = { version = "=6.0.0", features = ["macos_kqueue"] } +notify = { version = "=6.0.1", features = ["macos_kqueue"] } num-bigint = "0.4.3" num-traits = "0.2.15" number_prefix = "0.4" From 47d0ac4a421b370e4655051d59b05830aa8138da Mon Sep 17 00:00:00 2001 From: John Shin Date: Sat, 17 Jun 2023 19:31:27 -0700 Subject: [PATCH 24/51] sync: fix error msg --- src/uu/sync/src/sync.rs | 4 ++-- tests/by-util/test_sync.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index e12703bca..821ad639b 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -173,7 +173,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let path = Path::new(&f); if let Err(e) = open(path, OFlag::O_NONBLOCK, Mode::empty()) { if e != Errno::EACCES || (e == Errno::EACCES && path.is_dir()) { - return e.map_err_context(|| format!("cannot stat {}", f.quote()))?; + return e.map_err_context(|| format!("error opening {}", f.quote()))?; } } } @@ -183,7 +183,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if !Path::new(&f).exists() { return Err(USimpleError::new( 1, - format!("cannot stat {}: No such file or directory", f.quote()), + format!("error opening {}: No such file or directory", f.quote()), )); } } diff --git a/tests/by-util/test_sync.rs b/tests/by-util/test_sync.rs index d55a874ba..9cae3b8a0 100644 --- a/tests/by-util/test_sync.rs +++ b/tests/by-util/test_sync.rs @@ -41,7 +41,7 @@ fn test_sync_no_existing_files() { .arg("--data") .arg("do-no-exist") .fails() - .stderr_contains("cannot stat"); + .stderr_contains("error opening"); } #[test] @@ -63,9 +63,9 @@ fn test_sync_no_permission_dir() { ts.ccmd("chmod").arg("0").arg(dir).succeeds(); let result = ts.ucmd().arg("--data").arg(dir).fails(); - result.stderr_contains("sync: cannot stat 'foo': Permission denied"); + result.stderr_contains("sync: error opening 'foo': Permission denied"); let result = ts.ucmd().arg(dir).fails(); - result.stderr_contains("sync: cannot stat 'foo': Permission denied"); + result.stderr_contains("sync: error opening 'foo': Permission denied"); } #[cfg(not(target_os = "windows"))] From 5882151eb10878e177df2f483c7ca0b234a52b54 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Sun, 18 Jun 2023 15:13:15 +0200 Subject: [PATCH 25/51] deny.toml: add hashbrown to skip list --- deny.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deny.toml b/deny.toml index 8687fbfae..780de3c8c 100644 --- a/deny.toml +++ b/deny.toml @@ -87,6 +87,8 @@ skip = [ { name = "redox_syscall", version = "0.3.5" }, # cpp_macros { name = "aho-corasick", version = "0.7.19" }, + # ordered-multimap (via rust-ini) + { name = "hashbrown", version = "0.13.2" }, ] # spell-checker: enable From 9fbc98fc4edb505d830fa696dad8fd1e8d684e7b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 18 Jun 2023 14:05:34 +0000 Subject: [PATCH 26/51] chore(deps): update rust crate rust-ini to 0.19.0 --- Cargo.lock | 62 +++++++++++++++++++++++++++++++++++++++++++++++------- Cargo.toml | 2 +- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7394c98a1..2e39978ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -371,6 +371,28 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "const-random" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368a7a772ead6ce7e1de82bfb04c485f3db8ec744f72925af5735e29a22cc18e" +dependencies = [ + "const-random-macro", + "proc-macro-hack", +] + +[[package]] +name = "const-random-macro" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d7d6ab3c3a2282db210df5f02c4dab6e0a7057af0fb7ebd4070f30fe05c0ddb" +dependencies = [ + "getrandom", + "once_cell", + "proc-macro-hack", + "tiny-keccak", +] + [[package]] name = "constant_time_eq" version = "0.2.4" @@ -809,9 +831,12 @@ dependencies = [ [[package]] name = "dlv-list" -version = "0.3.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" +checksum = "d529fd73d344663edfd598ccb3f344e46034db51ebd103518eae34338248ad73" +dependencies = [ + "const-random", +] [[package]] name = "dns-lookup" @@ -1106,6 +1131,12 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -1572,12 +1603,12 @@ dependencies = [ [[package]] name = "ordered-multimap" -version = "0.4.3" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a" +checksum = "4ed8acf08e98e744e5384c8bc63ceb0364e68a6854187221c18df61c4797690e" dependencies = [ "dlv-list", - "hashbrown", + "hashbrown 0.13.2", ] [[package]] @@ -1774,6 +1805,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.20+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" + [[package]] name = "proc-macro2" version = "1.0.47" @@ -1973,9 +2010,9 @@ dependencies = [ [[package]] name = "rust-ini" -version = "0.18.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" +checksum = "7e2a3bcec1f113553ef1c88aae6c020a369d03d55b58de9869a0908930385091" dependencies = [ "cfg-if", "ordered-multimap", @@ -2329,6 +2366,15 @@ dependencies = [ "time-core", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "typenum" version = "1.15.0" @@ -2347,7 +2393,7 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5faade31a542b8b35855fff6e8def199853b2da8da256da52f52f1316ee3137" dependencies = [ - "hashbrown", + "hashbrown 0.12.3", "regex", ] diff --git a/Cargo.toml b/Cargo.toml index c0f6ab779..e92f6719e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -312,7 +312,7 @@ rayon = "1.7" redox_syscall = "0.3" regex = "1.8.4" rstest = "0.17.0" -rust-ini = "0.18.0" +rust-ini = "0.19.0" same-file = "1.0.6" selinux = "0.4" signal-hook = "0.3.15" From 7306be6e5862fd7081ea735effe6c17290523d19 Mon Sep 17 00:00:00 2001 From: Kostiantyn Hryshchuk Date: Sun, 18 Jun 2023 15:26:23 +0200 Subject: [PATCH 27/51] fixed shred -u for windows fixed shred panic on windows --- src/uu/shred/src/shred.rs | 4 +++- tests/by-util/test_shred.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 5ec1d1213..fd14a3245 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -532,7 +532,9 @@ fn wipe_name(orig_path: &Path, verbose: bool) -> Option { } // Sync every file rename - let new_file = File::open(new_path.clone()) + let new_file = OpenOptions::new() + .write(true) + .open(new_path.clone()) .expect("Failed to open renamed file for syncing"); new_file.sync_all().expect("Failed to sync renamed file"); diff --git a/tests/by-util/test_shred.rs b/tests/by-util/test_shred.rs index a34345aee..d98b840c4 100644 --- a/tests/by-util/test_shred.rs +++ b/tests/by-util/test_shred.rs @@ -18,7 +18,7 @@ fn test_shred_remove() { at.touch(file_b); // Shred file_a. - scene.ucmd().arg("-u").arg(file_a).run(); + scene.ucmd().arg("-u").arg(file_a).succeeds(); // file_a was deleted, file_b exists. assert!(!at.file_exists(file_a)); From b7154a80e121e75429769c6c04ac16bc9dc1325d Mon Sep 17 00:00:00 2001 From: Damon Harris Date: Sun, 18 Jun 2023 07:41:11 +0530 Subject: [PATCH 28/51] od: fix parsing of hex input ending with `E` --- src/uu/od/src/parse_nrofbytes.rs | 3 ++- tests/by-util/test_od.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/uu/od/src/parse_nrofbytes.rs b/src/uu/od/src/parse_nrofbytes.rs index 4c310755b..7d3bca03d 100644 --- a/src/uu/od/src/parse_nrofbytes.rs +++ b/src/uu/od/src/parse_nrofbytes.rs @@ -43,7 +43,7 @@ pub fn parse_number_of_bytes(s: &str) -> Result { len -= 1; } #[cfg(target_pointer_width = "64")] - Some('E') => { + Some('E') if radix != 16 => { multiply = 1024 * 1024 * 1024 * 1024 * 1024 * 1024; len -= 1; } @@ -84,6 +84,7 @@ fn test_parse_number_of_bytes() { // hex input assert_eq!(15, parse_number_of_bytes("0xf").unwrap()); + assert_eq!(14, parse_number_of_bytes("0XE").unwrap()); assert_eq!(15, parse_number_of_bytes("0XF").unwrap()); assert_eq!(27, parse_number_of_bytes("0x1b").unwrap()); assert_eq!(16 * 1024, parse_number_of_bytes("0x10k").unwrap()); diff --git a/tests/by-util/test_od.rs b/tests/by-util/test_od.rs index 24626cd76..54ac06384 100644 --- a/tests/by-util/test_od.rs +++ b/tests/by-util/test_od.rs @@ -627,6 +627,35 @@ fn test_skip_bytes() { )); } +#[test] +fn test_skip_bytes_hex() { + let input = "abcdefghijklmnopq"; // spell-checker:disable-line + new_ucmd!() + .arg("-c") + .arg("--skip-bytes=0xB") + .run_piped_stdin(input.as_bytes()) + .no_stderr() + .success() + .stdout_is(unindent( + " + 0000013 l m n o p q + 0000021 + ", + )); + new_ucmd!() + .arg("-c") + .arg("--skip-bytes=0xE") + .run_piped_stdin(input.as_bytes()) + .no_stderr() + .success() + .stdout_is(unindent( + " + 0000016 o p q + 0000021 + ", + )); +} + #[test] fn test_skip_bytes_error() { let input = "12345"; From 6ebfaf4b9d5ff2350a4b87b18a326cd0e8b50c14 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Mon, 12 Jun 2023 15:58:49 +0200 Subject: [PATCH 29/51] sort: migrate from ouroboros to self_cell --- Cargo.lock | 67 ++++--------------------------------- Cargo.toml | 2 +- src/uu/sort/Cargo.toml | 2 +- src/uu/sort/src/chunks.rs | 31 ++++++++--------- src/uu/sort/src/ext_sort.rs | 2 +- src/uu/sort/src/merge.rs | 2 +- 6 files changed, 27 insertions(+), 79 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e39978ca..5721d1f55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "Inflector" -version = "0.11.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" - [[package]] name = "adler" version = "1.0.2" @@ -43,12 +37,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "aliasable" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" - [[package]] name = "android-tzdata" version = "0.1.1" @@ -1620,29 +1608,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "ouroboros" -version = "0.15.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1358bd1558bd2a083fed428ffeda486fbfb323e698cdda7794259d592ca72db" -dependencies = [ - "aliasable", - "ouroboros_macro", -] - -[[package]] -name = "ouroboros_macro" -version = "0.15.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f7d21ccd03305a674437ee1248f3ab5d4b1db095cf1caf49f1713ddf61956b7" -dependencies = [ - "Inflector", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "output_vt100" version = "0.1.3" @@ -1781,30 +1746,6 @@ dependencies = [ "yansi", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro-hack" version = "0.5.20+deprecated" @@ -2082,6 +2023,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" +[[package]] +name = "self_cell" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3926e239738d36060909ffe6f511502f92149a45a1fade7fe031cb2d33e88b" + [[package]] name = "selinux" version = "0.4.0" @@ -3145,9 +3092,9 @@ dependencies = [ "fnv", "itertools", "memchr", - "ouroboros", "rand", "rayon", + "self_cell", "tempfile", "unicode-width", "uucore", diff --git a/Cargo.toml b/Cargo.toml index e92f6719e..8f639c036 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -300,7 +300,6 @@ num-traits = "0.2.15" number_prefix = "0.4" once_cell = "1.18.0" onig = { version = "~6.4", default-features = false } -ouroboros = "0.15.6" parse_datetime = "0.4.0" phf = "0.11.1" phf_codegen = "0.11.1" @@ -314,6 +313,7 @@ regex = "1.8.4" rstest = "0.17.0" rust-ini = "0.19.0" same-file = "1.0.6" +self_cell = "1.0.0" selinux = "0.4" signal-hook = "0.3.15" smallvec = { version = "1.10", features = ["union"] } diff --git a/src/uu/sort/Cargo.toml b/src/uu/sort/Cargo.toml index 7540522ed..533b31831 100644 --- a/src/uu/sort/Cargo.toml +++ b/src/uu/sort/Cargo.toml @@ -22,9 +22,9 @@ ctrlc = { workspace = true } fnv = { workspace = true } itertools = { workspace = true } memchr = { workspace = true } -ouroboros = { workspace = true } rand = { workspace = true } rayon = { workspace = true } +self_cell = { workspace = true } tempfile = { workspace = true } unicode-width = { workspace = true } uucore = { workspace = true, features = ["fs"] } diff --git a/src/uu/sort/src/chunks.rs b/src/uu/sort/src/chunks.rs index 9b60d5f5b..ffee7e453 100644 --- a/src/uu/sort/src/chunks.rs +++ b/src/uu/sort/src/chunks.rs @@ -16,21 +16,22 @@ use std::{ }; use memchr::memchr_iter; -use ouroboros::self_referencing; +use self_cell::self_cell; use uucore::error::{UResult, USimpleError}; use crate::{numeric_str_cmp::NumInfo, GeneralF64ParseResult, GlobalSettings, Line, SortError}; -/// The chunk that is passed around between threads. -/// `lines` consist of slices into `buffer`. -#[self_referencing(pub_extras)] -#[derive(Debug)] -pub struct Chunk { - pub buffer: Vec, - #[borrows(buffer)] - #[covariant] - pub contents: ChunkContents<'this>, -} +self_cell!( + /// The chunk that is passed around between threads. + pub struct Chunk { + owner: Vec, + + #[covariant] + dependent: ChunkContents, + } + + impl {Debug} +); #[derive(Debug)] pub struct ChunkContents<'a> { @@ -48,7 +49,7 @@ pub struct LineData<'a> { impl Chunk { /// Destroy this chunk and return its components to be reused. pub fn recycle(mut self) -> RecycledChunk { - let recycled_contents = self.with_contents_mut(|contents| { + let recycled_contents = self.with_dependent_mut(|_, contents| { contents.lines.clear(); contents.line_data.selections.clear(); contents.line_data.num_infos.clear(); @@ -81,15 +82,15 @@ impl Chunk { selections: recycled_contents.1, num_infos: recycled_contents.2, parsed_floats: recycled_contents.3, - buffer: self.into_heads().buffer, + buffer: self.into_owner(), } } pub fn lines(&self) -> &Vec { - &self.borrow_contents().lines + &self.borrow_dependent().lines } pub fn line_data(&self) -> &LineData { - &self.borrow_contents().line_data + &self.borrow_dependent().line_data } } diff --git a/src/uu/sort/src/ext_sort.rs b/src/uu/sort/src/ext_sort.rs index 45ddc7304..27cb12d0b 100644 --- a/src/uu/sort/src/ext_sort.rs +++ b/src/uu/sort/src/ext_sort.rs @@ -158,7 +158,7 @@ fn reader_writer< /// The function that is executed on the sorter thread. fn sorter(receiver: &Receiver, sender: &SyncSender, settings: &GlobalSettings) { while let Ok(mut payload) = receiver.recv() { - payload.with_contents_mut(|contents| { + payload.with_dependent_mut(|_, contents| { sort_by(&mut contents.lines, settings, &contents.line_data); }); if sender.send(payload).is_err() { diff --git a/src/uu/sort/src/merge.rs b/src/uu/sort/src/merge.rs index f6da0ee32..7c682d88f 100644 --- a/src/uu/sort/src/merge.rs +++ b/src/uu/sort/src/merge.rs @@ -288,7 +288,7 @@ impl<'a> FileMerger<'a> { file_number: file.file_number, }); - file.current_chunk.with_contents(|contents| { + file.current_chunk.with_dependent(|_, contents| { let current_line = &contents.lines[file.line_idx]; if settings.unique { if let Some(prev) = &prev { From bf7f3783d1b2d075e93eb60bc32fb8ed8ddbff46 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 19 Jun 2023 19:10:53 +0200 Subject: [PATCH 30/51] yes: allow --version Test: tests/help/help-version-getopt.sh --- src/uu/yes/src/yes.rs | 3 ++- tests/by-util/test_yes.rs | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/uu/yes/src/yes.rs b/src/uu/yes/src/yes.rs index fd5124064..72c19b872 100644 --- a/src/uu/yes/src/yes.rs +++ b/src/uu/yes/src/yes.rs @@ -9,7 +9,7 @@ // cSpell:ignore strs -use clap::{builder::ValueParser, Arg, ArgAction, Command}; +use clap::{builder::ValueParser, crate_version, Arg, ArgAction, Command}; use std::error::Error; use std::ffi::OsString; use std::io::{self, Write}; @@ -44,6 +44,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uu_app() -> Command { Command::new(uucore::util_name()) + .version(crate_version!()) .about(ABOUT) .override_usage(format_usage(USAGE)) .arg( diff --git a/tests/by-util/test_yes.rs b/tests/by-util/test_yes.rs index 89a68e7e1..a674f8245 100644 --- a/tests/by-util/test_yes.rs +++ b/tests/by-util/test_yes.rs @@ -35,6 +35,11 @@ fn test_invalid_arg() { new_ucmd!().arg("--definitely-invalid").fails().code_is(1); } +#[test] +fn test_version() { + new_ucmd!().arg("--version").succeeds(); +} + #[test] fn test_simple() { run(NO_ARGS, b"y\ny\ny\ny\n"); From e70d7d3b90c66596ab54b573c55f10a407bcdb2f Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 19 Jun 2023 22:32:49 +0200 Subject: [PATCH 31/51] Hack the tests/help/help-version-getopt.sh tests: * "hostid BEFORE --help" doesn't fail for GNU. we fail. we are probably doing better * "hostid BEFORE --help AFTER " same for this --- util/build-gnu.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/build-gnu.sh b/util/build-gnu.sh index 13fef7bb9..e3a523e34 100755 --- a/util/build-gnu.sh +++ b/util/build-gnu.sh @@ -232,3 +232,8 @@ sed -i -e "s/Try 'mv --help' for more information/For more information, try '--h sed -i -E "s|^([^#]*2_31.*)$|#\1|g" tests/misc/printf-cov.pl sed -i -e "s/du: invalid -t argument/du: invalid --threshold argument/" -e "s/du: option requires an argument/error: a value is required for '--threshold ' but none was supplied/" -e "/Try 'du --help' for more information./d" tests/du/threshold.sh + +# disable two kind of tests: +# "hostid BEFORE --help" doesn't fail for GNU. we fail. we are probably doing better +# "hostid BEFORE --help AFTER " same for this +sed -i -e "s/env \$prog \$BEFORE \$opt > out2/env \$prog \$BEFORE \$opt > out2 #/" -e "s/env \$prog \$BEFORE \$opt AFTER > out3/env \$prog \$BEFORE \$opt AFTER > out3 #/" -e "s/compare exp out2/compare exp out2 #/" -e "s/compare exp out3/compare exp out3 #/" tests/help/help-version-getopt.sh From e990f87edcac67e9df7f75d67a1c6c5fdce6548f Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Tue, 20 Jun 2023 15:23:54 +0200 Subject: [PATCH 32/51] touch: rename CURRENT to TIMESTAMP --- src/uu/touch/src/touch.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 55663fdab..8a21a2f5c 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -29,7 +29,7 @@ pub mod options { pub mod sources { pub static DATE: &str = "date"; pub static REFERENCE: &str = "reference"; - pub static CURRENT: &str = "current"; + pub static TIMESTAMP: &str = "timestamp"; } pub static HELP: &str = "help"; pub static ACCESS: &str = "access"; @@ -120,12 +120,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { (timestamp, timestamp) } (None, None) => { - let timestamp = - if let Some(current) = matches.get_one::(options::sources::CURRENT) { - parse_timestamp(current)? - } else { - local_dt_to_filetime(time::OffsetDateTime::now_local().unwrap()) - }; + let timestamp = if let Some(ts) = matches.get_one::(options::sources::TIMESTAMP) + { + parse_timestamp(ts)? + } else { + local_dt_to_filetime(time::OffsetDateTime::now_local().unwrap()) + }; (timestamp, timestamp) } }; @@ -243,7 +243,7 @@ pub fn uu_app() -> Command { .action(ArgAction::SetTrue), ) .arg( - Arg::new(options::sources::CURRENT) + Arg::new(options::sources::TIMESTAMP) .short('t') .help("use [[CC]YY]MMDDhhmm[.ss] instead of the current time") .value_name("STAMP"), @@ -255,7 +255,7 @@ pub fn uu_app() -> Command { .allow_hyphen_values(true) .help("parse argument and use it instead of current time") .value_name("STRING") - .conflicts_with(options::sources::CURRENT), + .conflicts_with(options::sources::TIMESTAMP), ) .arg( Arg::new(options::MODIFICATION) @@ -288,7 +288,7 @@ pub fn uu_app() -> Command { .value_name("FILE") .value_parser(ValueParser::os_string()) .value_hint(clap::ValueHint::AnyPath) - .conflicts_with(options::sources::CURRENT), + .conflicts_with(options::sources::TIMESTAMP), ) .arg( Arg::new(options::TIME) @@ -311,7 +311,7 @@ pub fn uu_app() -> Command { .group( ArgGroup::new(options::SOURCES) .args([ - options::sources::CURRENT, + options::sources::TIMESTAMP, options::sources::DATE, options::sources::REFERENCE, ]) From 98ef87af867cca01ea13f08e09eac147f15bc2ae Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Tue, 20 Jun 2023 15:28:32 +0200 Subject: [PATCH 33/51] touch: cleanup "spell-checker:ignore" line --- src/uu/touch/src/touch.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 8a21a2f5c..4efea56c4 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -6,7 +6,7 @@ // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. -// spell-checker:ignore (ToDO) filetime strptime utcoff strs datetime MMDDhhmm clapv PWSTR lpszfilepath hresult mktime YYYYMMDDHHMM YYMMDDHHMM DATETIME YYYYMMDDHHMMS subsecond humantime +// spell-checker:ignore (ToDO) filetime datetime MMDDhhmm lpszfilepath mktime YYYYMMDDHHMM YYMMDDHHMM DATETIME YYYYMMDDHHMMS subsecond humantime use clap::builder::ValueParser; use clap::{crate_version, Arg, ArgAction, ArgGroup, Command}; From 01af46e914e20936ae2c68ee4c06891233fdd0a0 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 20 Jun 2023 15:45:55 +0200 Subject: [PATCH 34/51] Use misc instead of test Co-authored-by: Daniel Hofstetter --- util/build-gnu.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/build-gnu.sh b/util/build-gnu.sh index e3a523e34..2b7e5c0bf 100755 --- a/util/build-gnu.sh +++ b/util/build-gnu.sh @@ -236,4 +236,4 @@ sed -i -e "s/du: invalid -t argument/du: invalid --threshold argument/" -e "s/du # disable two kind of tests: # "hostid BEFORE --help" doesn't fail for GNU. we fail. we are probably doing better # "hostid BEFORE --help AFTER " same for this -sed -i -e "s/env \$prog \$BEFORE \$opt > out2/env \$prog \$BEFORE \$opt > out2 #/" -e "s/env \$prog \$BEFORE \$opt AFTER > out3/env \$prog \$BEFORE \$opt AFTER > out3 #/" -e "s/compare exp out2/compare exp out2 #/" -e "s/compare exp out3/compare exp out3 #/" tests/help/help-version-getopt.sh +sed -i -e "s/env \$prog \$BEFORE \$opt > out2/env \$prog \$BEFORE \$opt > out2 #/" -e "s/env \$prog \$BEFORE \$opt AFTER > out3/env \$prog \$BEFORE \$opt AFTER > out3 #/" -e "s/compare exp out2/compare exp out2 #/" -e "s/compare exp out3/compare exp out3 #/" tests/misc/help-version-getopt.sh From c3f2ac6f044e1d00cb440214c7ddb5d5bdeea505 Mon Sep 17 00:00:00 2001 From: yt2b Date: Tue, 20 Jun 2023 23:20:22 +0900 Subject: [PATCH 35/51] yes: add --version option --- src/uu/yes/src/yes.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/uu/yes/src/yes.rs b/src/uu/yes/src/yes.rs index fd5124064..72c19b872 100644 --- a/src/uu/yes/src/yes.rs +++ b/src/uu/yes/src/yes.rs @@ -9,7 +9,7 @@ // cSpell:ignore strs -use clap::{builder::ValueParser, Arg, ArgAction, Command}; +use clap::{builder::ValueParser, crate_version, Arg, ArgAction, Command}; use std::error::Error; use std::ffi::OsString; use std::io::{self, Write}; @@ -44,6 +44,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uu_app() -> Command { Command::new(uucore::util_name()) + .version(crate_version!()) .about(ABOUT) .override_usage(format_usage(USAGE)) .arg( From a3fe70f7b2669202b70fa70c7df2a983230db8f0 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 20 Jun 2023 23:14:54 +0200 Subject: [PATCH 36/51] try to fix ignore intermittent --- .github/workflows/GnuTests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/GnuTests.yml b/.github/workflows/GnuTests.yml index 372bf0717..eb3e22a80 100644 --- a/.github/workflows/GnuTests.yml +++ b/.github/workflows/GnuTests.yml @@ -205,7 +205,7 @@ jobs: path_UUTILS='${{ steps.vars.outputs.path_UUTILS }}' # https://github.com/uutils/coreutils/issues/4294 # https://github.com/uutils/coreutils/issues/4295 - IGNORE_INTERMITTENT='${path_UUTILS}/.github/workflows/ignore-intermittent.txt' + IGNORE_INTERMITTENT="${path_UUTILS}/.github/workflows/ignore-intermittent.txt" mkdir -p ${{ steps.vars.outputs.path_reference }} From 98d242de7e880ae52667e651aa3e9cef8c9cee08 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 22 Jun 2023 10:04:37 +0200 Subject: [PATCH 37/51] nl: fix typo in nl.md --- src/uu/nl/nl.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/nl/nl.md b/src/uu/nl/nl.md index b64b9f627..d7cfc698f 100644 --- a/src/uu/nl/nl.md +++ b/src/uu/nl/nl.md @@ -1,4 +1,4 @@ -#nl +# nl ``` nl [OPTION]... [FILE]... From c32139784a33619344179ff85e9f18cf4c2c32eb Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 22 Jun 2023 14:30:53 +0200 Subject: [PATCH 38/51] nl: implement Default for Settings --- src/uu/nl/src/nl.rs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 44fdec8c7..d3e90bc75 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -42,6 +42,24 @@ pub struct Settings { number_separator: String, } +impl Default for Settings { + fn default() -> Self { + Self { + header_numbering: NumberingStyle::NumberForNone, + body_numbering: NumberingStyle::NumberForAll, + footer_numbering: NumberingStyle::NumberForNone, + section_delimiter: ['\\', ':'], + starting_line_number: 1, + line_increment: 1, + join_blank_lines: 1, + number_width: 6, + number_format: NumberFormat::Right, + renumber: true, + number_separator: String::from("\t"), + } + } +} + // NumberingStyle stores which lines are to be numbered. // The possible options are: // 1. Number all lines @@ -87,20 +105,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().try_get_matches_from(args)?; - // A mutable settings object, initialized with the defaults. - let mut settings = Settings { - header_numbering: NumberingStyle::NumberForNone, - body_numbering: NumberingStyle::NumberForAll, - footer_numbering: NumberingStyle::NumberForNone, - section_delimiter: ['\\', ':'], - starting_line_number: 1, - line_increment: 1, - join_blank_lines: 1, - number_width: 6, - number_format: NumberFormat::Right, - renumber: true, - number_separator: String::from("\t"), - }; + let mut settings = Settings::default(); // Update the settings from the command line options, and terminate the // program if some options could not successfully be parsed. From d00134640bb19cc91f706e511c16ef31c14502d7 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 22 Jun 2023 14:33:32 +0200 Subject: [PATCH 39/51] nl: use "const" instead of "static" --- src/uu/nl/src/nl.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index d3e90bc75..809ff2650 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -18,8 +18,8 @@ use uucore::{format_usage, help_about, help_usage}; mod helper; -static ABOUT: &str = help_about!("nl.md"); -static USAGE: &str = help_usage!("nl.md"); +const ABOUT: &str = help_about!("nl.md"); +const USAGE: &str = help_usage!("nl.md"); // Settings store options used by nl to produce its output. pub struct Settings { From 0010fece35cf81274474c00b97ed9d7cb4095bc8 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 22 Jun 2023 14:35:04 +0200 Subject: [PATCH 40/51] nl: remove "spell-checker:ignore" line --- src/uu/nl/src/nl.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 809ff2650..7e18d7588 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -6,8 +6,6 @@ // * file that was distributed with this source code. // * -// spell-checker:ignore (ToDO) corasick memchr - use clap::{crate_version, Arg, ArgAction, Command}; use std::fs::File; use std::io::{stdin, BufRead, BufReader, Read}; From 0144a3c78fc8f86767fc67ff19b1e5b7a33de471 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 22 Jun 2023 13:43:21 +0000 Subject: [PATCH 41/51] fix(deps): update rust crate itertools to 0.11.0 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/uucore/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e39978ca..25414fb03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1275,9 +1275,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.5" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" dependencies = [ "either", ] diff --git a/Cargo.toml b/Cargo.toml index e92f6719e..c49b1c432 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -286,7 +286,7 @@ glob = "0.3.1" half = "2.2" indicatif = "0.17" is-terminal = "0.4.7" -itertools = "0.10.5" +itertools = "0.11.0" libc = "0.2.146" lscolors = { version = "0.14.0", default-features = false, features = [ "nu-ansi-term", diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index 7fa4aa344..8fd5769c9 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -25,7 +25,7 @@ dunce = "1.0.4" wild = "2.1" glob = "0.3.1" # * optional -itertools = { version = "0.10.5", optional = true } +itertools = { version = "0.11.0", optional = true } thiserror = { workspace = true, optional = true } time = { workspace = true, optional = true, features = [ "formatting", From d57a5eb6a3c5f9f01b54f49d4961dc649763494f Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Sat, 24 Jun 2023 07:07:38 +0200 Subject: [PATCH 42/51] seq: remove two chars in seq.md --- src/uu/seq/seq.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/seq/seq.md b/src/uu/seq/seq.md index 065404e20..8e67391e4 100644 --- a/src/uu/seq/seq.md +++ b/src/uu/seq/seq.md @@ -5,5 +5,5 @@ Display numbers from FIRST to LAST, in steps of INCREMENT. ``` seq [OPTION]... LAST seq [OPTION]... FIRST LAST -seq [OPTION]... FIRST INCREMENT LAST"; +seq [OPTION]... FIRST INCREMENT LAST ``` From 9324a52a5692319e97293b310e65041b7b9337ee Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 24 Jun 2023 08:25:07 +0000 Subject: [PATCH 43/51] chore(deps): update rust crate phf_codegen to 0.11.2 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 25414fb03..1e4265dc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1702,9 +1702,9 @@ dependencies = [ [[package]] name = "phf_codegen" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56ac890c5e3ca598bbdeaa99964edb5b0258a583a9eb6ef4e89fc85d9224770" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" dependencies = [ "phf_generator", "phf_shared", diff --git a/Cargo.toml b/Cargo.toml index c49b1c432..21c455f0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -303,7 +303,7 @@ onig = { version = "~6.4", default-features = false } ouroboros = "0.15.6" parse_datetime = "0.4.0" phf = "0.11.1" -phf_codegen = "0.11.1" +phf_codegen = "0.11.2" platform-info = "2.0.1" quick-error = "2.0.1" rand = { version = "0.8", features = ["small_rng"] } From a02b3354e6fdba967e71a1cc2807fc7ccd1c9b88 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 24 Jun 2023 11:23:11 +0000 Subject: [PATCH 44/51] chore(deps): update rust crate phf to 0.11.2 --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e4265dc7..240c14bc5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1693,9 +1693,9 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "phf" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ "phf_shared", ] @@ -1722,9 +1722,9 @@ dependencies = [ [[package]] name = "phf_shared" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" dependencies = [ "siphasher", ] diff --git a/Cargo.toml b/Cargo.toml index 21c455f0a..d975bace9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -302,7 +302,7 @@ once_cell = "1.18.0" onig = { version = "~6.4", default-features = false } ouroboros = "0.15.6" parse_datetime = "0.4.0" -phf = "0.11.1" +phf = "0.11.2" phf_codegen = "0.11.2" platform-info = "2.0.1" quick-error = "2.0.1" From ddcdda44db9ebbd8a8c73f6a167b0b76a7236915 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 25 Jun 2023 00:18:33 +0200 Subject: [PATCH 45/51] Remove the auto capitalization of error message --- src/uucore/src/lib/mods/error.rs | 11 +---------- tests/by-util/test_cp.rs | 2 +- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/uucore/src/lib/mods/error.rs b/src/uucore/src/lib/mods/error.rs index e564c7bb5..f0f62569d 100644 --- a/src/uucore/src/lib/mods/error.rs +++ b/src/uucore/src/lib/mods/error.rs @@ -396,7 +396,7 @@ impl Display for UIoError { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { use std::io::ErrorKind::*; - let mut message; + let message; let message = if self.inner.raw_os_error().is_some() { // These are errors that come directly from the OS. // We want to normalize their messages across systems, @@ -424,7 +424,6 @@ impl Display for UIoError { // (https://github.com/rust-lang/rust/issues/86442) // are stabilized, we should add them to the match statement. message = strip_errno(&self.inner); - capitalize(&mut message); &message } } @@ -435,7 +434,6 @@ impl Display for UIoError { // a file that was not found. // There are also errors with entirely custom messages. message = self.inner.to_string(); - capitalize(&mut message); &message }; if let Some(ctx) = &self.context { @@ -446,13 +444,6 @@ impl Display for UIoError { } } -/// Capitalize the first character of an ASCII string. -fn capitalize(text: &mut str) { - if let Some(first) = text.get_mut(..1) { - first.make_ascii_uppercase(); - } -} - /// Strip the trailing " (os error XX)" from io error strings. pub fn strip_errno(err: &std::io::Error) -> String { let mut msg = err.to_string(); diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index fa5845eac..5289489ea 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -2724,7 +2724,7 @@ fn test_copy_dir_preserve_permissions_inaccessible_file() { ucmd.args(&["-p", "-R", "d1", "d2"]) .fails() .code_is(1) - .stderr_only("cp: cannot open 'd1/f' for reading: Permission denied\n"); + .stderr_only("cp: cannot open 'd1/f' for reading: permission denied\n"); assert!(at.dir_exists("d2")); assert!(!at.file_exists("d2/f")); From 2f1b710752864bad86acf97a97bc5291efcfcce0 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 25 Jun 2023 12:12:26 +0000 Subject: [PATCH 46/51] chore(deps): update vmactions/freebsd-vm action to v0.3.1 --- .github/workflows/freebsd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/freebsd.yml b/.github/workflows/freebsd.yml index 9507b3a56..095ec3230 100644 --- a/.github/workflows/freebsd.yml +++ b/.github/workflows/freebsd.yml @@ -35,7 +35,7 @@ jobs: - name: Run sccache-cache uses: mozilla-actions/sccache-action@v0.0.3 - name: Prepare, build and test - uses: vmactions/freebsd-vm@v0.3.0 + uses: vmactions/freebsd-vm@v0.3.1 with: usesh: true # We need jq to run show-utils.sh and bash to use inline shell string replacement @@ -125,7 +125,7 @@ jobs: - name: Run sccache-cache uses: mozilla-actions/sccache-action@v0.0.3 - name: Prepare, build and test - uses: vmactions/freebsd-vm@v0.3.0 + uses: vmactions/freebsd-vm@v0.3.1 with: usesh: true # sync: sshfs From ae90bad6cf0baeec5441b594cdebdd357b0cdce3 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Sun, 25 Jun 2023 16:53:50 +0200 Subject: [PATCH 47/51] docs: add seq to extensions; add some backticks --- docs/src/extensions.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/src/extensions.md b/docs/src/extensions.md index 281d8ef2e..428ae84ca 100644 --- a/docs/src/extensions.md +++ b/docs/src/extensions.md @@ -61,7 +61,11 @@ feature is adopted from [FreeBSD](https://www.freebsd.org/cgi/man.cgi?cut). ## `fmt` -`fmt` has additional flags for prefixes: `-P/--skip-prefix`, `-x/--exact-prefix`, and -`-X/--exact-skip-prefix`. With `-m/--preserve-headers`, an attempt is made to detect and preserve -mail headers in the input. `-q/--quick` breaks lines more quickly. And `-T/--tab-width` defines the +`fmt` has additional flags for prefixes: `-P`/`--skip-prefix`, `-x`/`--exact-prefix`, and +`-X`/`--exact-skip-prefix`. With `-m`/`--preserve-headers`, an attempt is made to detect and preserve +mail headers in the input. `-q`/`--quick` breaks lines more quickly. And `-T`/`--tab-width` defines the number of spaces representing a tab when determining the line length. + +## `seq` + +`seq` provides `-t`/`--terminator` to set the terminator character. From 824097d22469d07e658597182a110a618d545763 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 25 Jun 2023 19:09:01 +0000 Subject: [PATCH 48/51] fix(deps): update rust crate libc to 0.2.147 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/uucore/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 240c14bc5..b50c79e02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1340,9 +1340,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.146" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libloading" diff --git a/Cargo.toml b/Cargo.toml index d975bace9..6ec760a27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -287,7 +287,7 @@ half = "2.2" indicatif = "0.17" is-terminal = "0.4.7" itertools = "0.11.0" -libc = "0.2.146" +libc = "0.2.147" lscolors = { version = "0.14.0", default-features = false, features = [ "nu-ansi-term", ] } diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index 8fd5769c9..19054811c 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -36,7 +36,7 @@ time = { workspace = true, optional = true, features = [ data-encoding = { version = "2.4", optional = true } data-encoding-macro = { version = "0.1.13", optional = true } z85 = { version = "3.0.5", optional = true } -libc = { version = "0.2.146", optional = true } +libc = { version = "0.2.147", optional = true } once_cell = { workspace = true } os_display = "0.1.3" From 0ba972b2139cc90317e5c560dd3c2e44beb5d3ac Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 25 Jun 2023 19:15:50 +0000 Subject: [PATCH 49/51] chore(deps): update rust crate self_cell to 1.0.1 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a0d0f11e0..5c095a916 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2025,9 +2025,9 @@ checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" [[package]] name = "self_cell" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a3926e239738d36060909ffe6f511502f92149a45a1fade7fe031cb2d33e88b" +checksum = "4c309e515543e67811222dbc9e3dd7e1056279b782e1dacffe4242b718734fb6" [[package]] name = "selinux" diff --git a/Cargo.toml b/Cargo.toml index 609bd3e57..3be87fad8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -313,7 +313,7 @@ regex = "1.8.4" rstest = "0.17.0" rust-ini = "0.19.0" same-file = "1.0.6" -self_cell = "1.0.0" +self_cell = "1.0.1" selinux = "0.4" signal-hook = "0.3.15" smallvec = { version = "1.10", features = ["union"] } From b34e7f7bf6b7fe851a7579e92aa6be37fc95e9be Mon Sep 17 00:00:00 2001 From: John Shin Date: Tue, 20 Jun 2023 11:28:05 -0700 Subject: [PATCH 50/51] du: directories have apparent size of 0 --- src/uu/du/src/du.rs | 4 +- tests/by-util/test_du.rs | 117 +++++++++++++-------------------------- tests/common/util.rs | 11 ++++ 3 files changed, 52 insertions(+), 80 deletions(-) diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 3325ca1f5..db385c720 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -145,7 +145,7 @@ impl Stat { return Ok(Self { path: path.to_path_buf(), is_dir: metadata.is_dir(), - size: metadata.len(), + size: if path.is_dir() { 0 } else { metadata.len() }, blocks: metadata.blocks(), inodes: 1, inode: Some(file_info), @@ -162,7 +162,7 @@ impl Stat { Ok(Self { path: path.to_path_buf(), is_dir: metadata.is_dir(), - size: metadata.len(), + size: if path.is_dir() { 0 } else { metadata.len() }, blocks: size_on_disk / 1024 * 2, inode: file_info, inodes: 1, diff --git a/tests/by-util/test_du.rs b/tests/by-util/test_du.rs index 699746f03..892b5cfb1 100644 --- a/tests/by-util/test_du.rs +++ b/tests/by-util/test_du.rs @@ -580,97 +580,58 @@ fn test_du_invalid_threshold() { #[test] fn test_du_apparent_size() { - let ts = TestScenario::new(util_name!()); - let result = ts.ucmd().arg("--apparent-size").succeeds(); + let (at, mut ucmd) = at_and_ucmd!(); - #[cfg(any(target_os = "linux", target_os = "android"))] + at.mkdir_all("a/b"); + + at.write("a/b/file1", "foo"); + at.write("a/b/file2", "foobar"); + + let result = ucmd.args(&["--apparent-size", "--all", "a"]).succeeds(); + + #[cfg(not(target_os = "windows"))] { - let result_reference = unwrap_or_return!(expected_result(&ts, &["--apparent-size"])); - assert_eq!(result.stdout_str(), result_reference.stdout_str()); + result.stdout_contains_line("1\ta/b/file2"); + result.stdout_contains_line("1\ta/b/file1"); + result.stdout_contains_line("1\ta/b"); + result.stdout_contains_line("1\ta"); } - #[cfg(not(any(target_os = "linux", target_os = "android")))] - _du_apparent_size(result.stdout_str()); -} - -#[cfg(target_os = "windows")] -fn _du_apparent_size(s: &str) { - assert_eq!( - s, - "1\t.\\subdir\\deeper\\deeper_dir -1\t.\\subdir\\deeper -6\t.\\subdir\\links -6\t.\\subdir -6\t. -" - ); -} -#[cfg(target_vendor = "apple")] -fn _du_apparent_size(s: &str) { - assert_eq!( - s, - "1\t./subdir/deeper/deeper_dir -1\t./subdir/deeper -6\t./subdir/links -6\t./subdir -6\t. -" - ); -} -#[cfg(target_os = "freebsd")] -fn _du_apparent_size(s: &str) { - assert_eq!( - s, - "1\t./subdir/deeper/deeper_dir -2\t./subdir/deeper -6\t./subdir/links -8\t./subdir -8\t. -" - ); -} -#[cfg(all( - not(target_vendor = "apple"), - not(target_os = "windows"), - not(target_os = "freebsd") -))] -fn _du_apparent_size(s: &str) { - assert_eq!( - s, - "5\t./subdir/deeper/deeper_dir -9\t./subdir/deeper -10\t./subdir/links -22\t./subdir -26\t. -" - ); + #[cfg(target_os = "windows")] + { + result.stdout_contains_line("1\ta\\b\\file2"); + result.stdout_contains_line("1\ta\\b\\file1"); + result.stdout_contains_line("1\ta\\b"); + result.stdout_contains_line("1\ta"); + } } #[test] fn test_du_bytes() { - let ts = TestScenario::new(util_name!()); - let result = ts.ucmd().arg("--bytes").succeeds(); + let (at, mut ucmd) = at_and_ucmd!(); - #[cfg(any(target_os = "linux", target_os = "android"))] + at.mkdir_all("a/b"); + + at.write("a/b/file1", "foo"); + at.write("a/b/file2", "foobar"); + + let result = ucmd.args(&["--bytes", "--all", "a"]).succeeds(); + + #[cfg(not(target_os = "windows"))] { - let result_reference = unwrap_or_return!(expected_result(&ts, &["--bytes"])); - assert_eq!(result.stdout_str(), result_reference.stdout_str()); + result.stdout_contains_line("6\ta/b/file2"); + result.stdout_contains_line("3\ta/b/file1"); + result.stdout_contains_line("9\ta/b"); + result.stdout_contains_line("9\ta"); } #[cfg(target_os = "windows")] - result.stdout_contains("5145\t.\\subdir\n"); - #[cfg(target_vendor = "apple")] - result.stdout_contains("5625\t./subdir\n"); - #[cfg(target_os = "freebsd")] - result.stdout_contains("7193\t./subdir\n"); - #[cfg(all( - not(target_vendor = "apple"), - not(target_os = "windows"), - not(target_os = "freebsd"), - not(target_os = "linux"), - not(target_os = "android"), - ))] - result.stdout_contains("21529\t./subdir\n"); + { + result.stdout_contains_line("6\ta\\b\\file2"); + result.stdout_contains_line("3\ta\\b\\file1"); + result.stdout_contains_line("9\ta\\b"); + result.stdout_contains_line("9\ta"); + } } #[test] diff --git a/tests/common/util.rs b/tests/common/util.rs index 0898a4ad7..995312f08 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -659,6 +659,17 @@ impl CmdResult { self } + #[track_caller] + pub fn stdout_contains_line>(&self, cmp: T) -> &Self { + assert!( + self.stdout_str().lines().any(|line| line == cmp.as_ref()), + "'{}' does not contain line '{}'", + self.stdout_str(), + cmp.as_ref() + ); + self + } + #[track_caller] pub fn stderr_contains>(&self, cmp: T) -> &Self { assert!( From c64f3ccbdd2810fbd6d85b0573772c20efe20d31 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 26 Jun 2023 04:29:30 +0000 Subject: [PATCH 51/51] chore(deps): update rust crate fundu to 1.1.0 --- Cargo.lock | 13 +++++++++++-- Cargo.toml | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a0d0f11e0..3055d7394 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -969,9 +969,18 @@ dependencies = [ [[package]] name = "fundu" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47af3b646bdd738395be2db903fc11a5923b5e206016b8d4ad6db890bcae9bd5" +checksum = "d579dcb632d86591bdd7fc445e705b96cb2a7fb5488d918d956f392b6148e898" +dependencies = [ + "fundu-core", +] + +[[package]] +name = "fundu-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a363b75dd1e4b5bd2cdc305c47399c524cae24638b368b66b1a4c2a36482801f" [[package]] name = "futures" diff --git a/Cargo.toml b/Cargo.toml index 609bd3e57..cd52536f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -280,7 +280,7 @@ filetime = "0.2" fnv = "1.0.7" fs_extra = "1.3.0" fts-sys = "0.2" -fundu = "1.0.0" +fundu = "1.1.0" gcd = "2.3" glob = "0.3.1" half = "2.2"