diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 589126b6f4c..78b1faa557d 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -142,6 +142,13 @@ jobs: ## Run it cd fuzz cargo +nightly fuzz run fuzz_date -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0 + - name: Run fuzz_test for XX seconds + continue-on-error: true + shell: bash + run: | + ## Run it + cd fuzz + cargo +nightly fuzz run fuzz_test -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0 - name: Run fuzz_parse_glob for XX seconds shell: bash run: | diff --git a/Cargo.lock b/Cargo.lock index 0b5e67fbf23..f25b7c20c05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2116,9 +2116,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.7.1" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if", "fastrand", diff --git a/Cargo.toml b/Cargo.toml index c3413d86bdb..71c04d355bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -152,6 +152,7 @@ feat_os_unix = [ "feat_require_crate_cpp", "feat_require_unix", "feat_require_unix_utmpx", + "feat_require_unix_hostid", ] # "feat_os_windows" == set of utilities which can be built/run on modern/usual windows platforms feat_os_windows = [ @@ -318,7 +319,7 @@ self_cell = "1.0.1" selinux = "0.4" signal-hook = "0.3.17" smallvec = { version = "1.11", features = ["union"] } -tempfile = "3.7.1" +tempfile = "3.8.0" term_grid = "0.1.5" terminal_size = "0.2.6" textwrap = { version = "0.16.0", features = ["terminal_size"] } diff --git a/README.md b/README.md index 4929224d195..c5b4609c924 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,8 @@ that scripts can be easily transferred between platforms. uutils has both user and developer documentation available: -- [User Manual](https://uutils.github.io/user/) -- [Developer Documentation](https://uutils.github.io/dev/coreutils/) +- [User Manual](https://uutils.github.io/coreutils/book/) +- [Developer Documentation](https://uutils.github.io/dev/coreutils/) (currently offline, you can use docs.rs in the meantime) Both can also be generated locally, the instructions for that can be found in the [coreutils docs](https://github.com/uutils/uutils.github.io) repository. @@ -303,7 +303,7 @@ make PREFIX=/my/path uninstall Below is the evolution of how many GNU tests uutils passes. A more detailed breakdown of the GNU test results of the main branch can be found -[in the user manual](https://uutils.github.io/user/test_coverage.html). +[in the user manual](https://uutils.github.io/coreutils/book/test_coverage.html). See for the main meta bugs (many are missing). diff --git a/README.target.md b/README.target.md deleted file mode 100644 index b8190ce3edb..00000000000 --- a/README.target.md +++ /dev/null @@ -1,28 +0,0 @@ -# Targets that compile - -**Note: this list isn't up to date.** - -This is an auto-generated table showing which binaries compile for each target-triple. Note that this **does not** indicate that they are fully implemented, or that the tests pass. - -|######OS######|###ARCH####|arch|base32|base64|basename|cat|chgrp|chmod|chown|chroot|cksum|comm|cp|csplit|cut|date|df|dircolors|dirname|du|echo|env|expand|expr|factor|false|fmt|fold|groups|hashsum|head|hostid|hostname|id|install|join|kill|link|ln|logname|ls|mkdir|mkfifo|mknod|mktemp|more|mv|nice|nl|nohup|nproc|numfmt|od|paste|pathchk|pinky|printenv|printf|ptx|pwd|readlink|realpath|relpath|rm|rmdir|seq|shred|shuf|sleep|sort|split|stat|stdbuf|sum|sync|tac|tail|tee|test|timeout|touch|tr|true|truncate|tsort|tty|uname|unexpand|uniq|unlink|uptime|users|wc|who|whoami|yes|chcon|pr|dir|vdir|dd|basenc|runcon| -|--------------|-----------|----|------|------|--------|---|-----|-----|-----|------|-----|----|--|------|---|----|--|---------|-------|--|----|---|------|----|------|-----|---|----|------|-------|----|------|--------|--|-------|----|----|----|--|-------|--|-----|------|-----|------|----|--|----|--|-----|-----|------|--|-----|-------|-----|--------|------|---|---|--------|--------|-------|--|-----|---|-----|----|-----|----|-----|----|------|---|----|---|----|---|----|-------|-----|--|----|--------|-----|---|-----|--------|----|------|------|-----|--|---|------|---|-----|--|---|----|--|------|------| -|linux-gnu|aarch64|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| |y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| -|linux-gnu|i686|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| -|linux-gnu|powerpc64|y|y|y|y|y|y|y|y|y|y|y| |y|y|y|y|y|y|y|y|y|y| |y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| -|linux-gnu|riscv64gc| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -|linux-gnu|x86_64|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| |y|y|y|y|y| |y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| -|windows-msvc|aarch64|y|y|y|y|y| | | | |y|y|y|y|y|y|y|y|y| |y|y|y| |y|y|y|y| |y|y|y|y| | |y| |y|y|y| |y| | |y|y|y| |y| |y|y|y|y| | |y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| | |y|y|y|y|y|y| |y|y|y|y|y| |y|y|y| |y| |y| | |y|y|y|y|y|y|y|y| -|windows-gnu|i686|y|y|y|y|y| | | | |y|y|y|y|y|y|y|y|y| |y|y|y| |y|y|y|y| |y|y|y|y| | |y| |y|y|y|y|y| | |y|y|y| |y| |y|y|y|y| | |y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| | |y|y|y|y|y|y| |y|y|y|y|y|y|y|y|y| |y| |y| |y|y|y|y|y|y|y|y|y| -|windows-msvc|i686|y|y|y|y|y| | | | |y|y|y|y|y|y|y|y|y| |y|y|y| |y|y|y|y| |y|y|y|y| | |y| |y|y|y|y|y| | |y|y|y| |y| |y|y|y|y| | |y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| | |y|y|y|y|y|y| |y|y|y|y|y| |y|y|y| |y| |y| |y|y|y|y|y|y|y|y|y| -|windows-gnu|x86_64|y|y|y|y|y| | | | |y|y|y|y|y|y|y|y|y| |y|y|y| |y|y|y|y| |y|y|y|y| | |y| |y|y|y|y|y| | |y|y|y| |y| |y|y|y|y| | |y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| | |y|y|y|y|y|y| |y|y|y|y|y|y|y|y|y| |y| |y| |y|y|y|y|y|y|y|y|y| -|windows-msvc|x86_64|y|y|y|y|y| | | | |y|y|y|y|y|y|y|y|y| |y|y|y| |y|y|y|y| |y|y|y|y| | |y| |y|y|y|y|y| | |y|y|y| |y| |y|y|y|y| | |y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| | |y|y|y|y|y|y| |y|y|y|y|y| |y|y|y| |y| |y| |y|y|y|y|y|y|y|y|y| -|apple MacOS|x86_64|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| |y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| -|freebsd|x86_64|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| -|netbsd|x86_64|y|y|y|y|y|y|y|y| |y|y|y|y|y|y| |y|y|y|y|y|y| |y|y|y|y|y|y|y|y|y| |y|y| |y|y|y|y|y|y|y|y|y|y|y|y| |y|y|y|y|y| |y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| |y|y|y|y|y|y| |y|y|y| | |y| |y|y|y|y|y|y|y|y|y| -|android|aarch64|y|y|y|y|y|y|y|y| |y|y|y|y|y|y| |y|y|y|y|y|y| |y|y|y|y|y|y|y|y|y| |y|y| |y|y|y|y|y|y|y|y|y|y|y|y| |y|y|y|y|y| |y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| |y|y| |y|y|y|y| |y|y|y|y|y|y| |y|y|y| | |y| |y|y|y|y|y|y|y|y|y| -|android|x86_64|y|y|y|y|y|y|y|y| |y|y|y|y|y|y| |y|y|y|y|y|y| |y|y|y|y|y|y|y|y|y| |y|y| |y|y|y|y|y|y|y|y|y|y|y|y| |y|y|y|y|y| |y|y|y|y|y|y|y|y|y|y|y|y|y|y|y| |y|y| |y|y|y|y| |y|y|y|y|y|y| |y|y|y| | |y| |y|y|y|y|y|y|y|y|y| -|solaris|x86_64| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -|wasi|wasm32| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -|redox|x86_64| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -|fuchsia|aarch64| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -|fuchsia|x86_64| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | diff --git a/build.rs b/build.rs index 09b33fa911f..d210e2a2ec6 100644 --- a/build.rs +++ b/build.rs @@ -40,6 +40,7 @@ pub fn main() { mf.write_all( "type UtilityMap = phf::OrderedMap<&'static str, (fn(T) -> i32, fn() -> Command)>;\n\ \n\ + #[allow(clippy::too_many_lines)] fn util_map() -> UtilityMap {\n" .as_bytes(), ) diff --git a/docs/.gitignore b/docs/.gitignore index c669da8f672..be017dfbe7c 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -1,4 +1,5 @@ book src/utils src/SUMMARY.md +src/platform_table.md tldr.zip \ No newline at end of file diff --git a/docs/src/installation.md b/docs/src/installation.md index e5fcb62205f..da124ead977 100644 --- a/docs/src/installation.md +++ b/docs/src/installation.md @@ -1,4 +1,4 @@ - + # Installation @@ -139,6 +139,16 @@ pkg install rust-coreutils scoop install uutils-coreutils ``` +## Alternative installers + +### Conda + +[Conda package](https://anaconda.org/conda-forge/uutils-coreutils) + +``` +conda install -c conda-forge uutils-coreutils +``` + ## Non-standard packages ### `coreutils-hybrid` (AUR) diff --git a/docs/src/platforms.md b/docs/src/platforms.md new file mode 100644 index 00000000000..b84516e3f69 --- /dev/null +++ b/docs/src/platforms.md @@ -0,0 +1,45 @@ +# Platform support + + + +uutils aims to be as "universal" as possible, meaning that we try to support +many platforms. However, it is infeasible for us to guarantee that every +platform works. Just like Rust itself, we therefore have multiple tiers of +platform support, with different guarantees. We support two tiers of platforms: + + - **Tier 1**: All applicable utils are compiled and tested in CI for these + platforms. + - **Tier 2**: These platforms are supported but not actively tested. We do accept + fixes for these platforms. + +> **Note**: The tiers are dictated by our CI. We would happily accept a job +> in the CI for testing more platforms, bumping those platforms to tier 1. + +## Platforms per tier + +The platforms in tier 1 and the platforms that we test in CI are listed below. + +| Operating system | Tested targets | +| ---------------- | -------------- | +| **Linux** | `x86_64-unknown-linux-gnu`
`x86_64-unknown-linux-musl`
`arm-unknown-linux-gnueabihf`
`i686-unknown-linux-gnu`
`aarch64-unknown-linux-gnu` | +| **macOS** | `x86_64-apple-darwin` | +| **Windows** | `i686-pc-windows-msvc`
`x86_64-pc-windows-gnu`
`x86_64-pc-windows-msvc` | +| **FreeBSD** | `x86_64-unknown-freebsd` | +| **Android** | `i686-linux-android` | + +The platforms in tier 2 are more vague, but include: + + - untested variations of the platforms above, + - Redox OS, + - and BSDs such as OpenBSD, NetBSD & DragonFlyBSD. + +## Utility compatibility per platform + +Not all utils work on every platform. For instance, `chgrp` is not supported on +Windows, because Windows does not have the concept of groups. Below is a full table +detailing which utilities are supported for the tier 1 platforms. + +Note that for some utilities, not all functionality is supported on each +platform. This is documented per utility. + +{{ #include platform_table.md }} diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index c8565d69127..91a85b45a0f 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -9,12 +9,13 @@ cargo-fuzz = true [dependencies] libfuzzer-sys = "0.4" +libc = "0.2" +rand = { version = "0.8", features = ["small_rng"] } -[dependencies.uucore] -path = "../src/uucore/" +uucore = { path = "../src/uucore/" } +uu_date = { path = "../src/uu/date/" } +uu_test = { path = "../src/uu/test/" } -[dependencies.uu_date] -path = "../src/uu/date/" # Prevent this from interfering with workspaces [workspace] @@ -26,6 +27,12 @@ path = "fuzz_targets/fuzz_date.rs" test = false doc = false +[[bin]] +name = "fuzz_test" +path = "fuzz_targets/fuzz_test.rs" +test = false +doc = false + [[bin]] name = "fuzz_parse_glob" path = "fuzz_targets/fuzz_parse_glob.rs" diff --git a/fuzz/fuzz_targets/fuzz_test.rs b/fuzz/fuzz_targets/fuzz_test.rs new file mode 100644 index 00000000000..537e21abda5 --- /dev/null +++ b/fuzz/fuzz_targets/fuzz_test.rs @@ -0,0 +1,291 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. +// spell-checker:ignore STRINGSTRING INTEGERINTEGER FILEFILE + +#![no_main] +use libfuzzer_sys::fuzz_target; +use uu_test::uumain; + +use rand::seq::SliceRandom; +use rand::Rng; +use std::ffi::OsString; + +use libc::{dup, dup2, STDOUT_FILENO}; +use std::process::Command; + +#[derive(PartialEq, Debug, Clone)] +enum ArgType { + STRING, + STRINGSTRING, + INTEGER, + INTEGERINTEGER, + FILE, + FILEFILE, + // Add any other types as needed +} + +fn run_gnu_test(args: &[OsString]) -> Result<(String, i32), std::io::Error> { + let mut command = Command::new("test"); + for arg in args { + command.arg(arg); + } + let output = command.output()?; + let exit_status = output.status.code().unwrap_or(-1); // Capture the exit status code + Ok(( + String::from_utf8_lossy(&output.stdout).to_string(), + exit_status, + )) +} + +fn generate_random_string(max_length: usize) -> String { + let mut rng = rand::thread_rng(); + let valid_utf8: Vec = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + .chars() + .collect(); + let invalid_utf8 = [0xC3, 0x28]; // Invalid UTF-8 sequence + let mut result = String::new(); + + for _ in 0..rng.gen_range(1..=max_length) { + if rng.gen_bool(0.9) { + let ch = valid_utf8.choose(&mut rng).unwrap(); + result.push(*ch); + } else { + let ch = invalid_utf8.choose(&mut rng).unwrap(); + if let Some(c) = char::from_u32(*ch as u32) { + result.push(c); + } + } + } + + result +} + +#[derive(Debug, Clone)] +struct TestArg { + arg: String, + arg_type: ArgType, +} + +fn generate_random_path(rng: &mut dyn rand::RngCore) -> &'static str { + match rng.gen_range(0..=3) { + 0 => "/dev/null", + 1 => "/dev/random", + 2 => "/tmp", + _ => "/dev/urandom", + } +} + +fn generate_test_args() -> Vec { + vec![ + TestArg { + arg: "-z".to_string(), + arg_type: ArgType::STRING, + }, + TestArg { + arg: "-n".to_string(), + arg_type: ArgType::STRING, + }, + TestArg { + arg: "=".to_string(), + arg_type: ArgType::STRINGSTRING, + }, + TestArg { + arg: "!=".to_string(), + arg_type: ArgType::STRINGSTRING, + }, + TestArg { + arg: "-eq".to_string(), + arg_type: ArgType::INTEGERINTEGER, + }, + TestArg { + arg: "-ne".to_string(), + arg_type: ArgType::INTEGERINTEGER, + }, + TestArg { + arg: "-gt".to_string(), + arg_type: ArgType::INTEGERINTEGER, + }, + TestArg { + arg: "-ge".to_string(), + arg_type: ArgType::INTEGERINTEGER, + }, + TestArg { + arg: "-lt".to_string(), + arg_type: ArgType::INTEGERINTEGER, + }, + TestArg { + arg: "-le".to_string(), + arg_type: ArgType::INTEGERINTEGER, + }, + TestArg { + arg: "-f".to_string(), + arg_type: ArgType::FILE, + }, + TestArg { + arg: "-d".to_string(), + arg_type: ArgType::FILE, + }, + TestArg { + arg: "-e".to_string(), + arg_type: ArgType::FILE, + }, + TestArg { + arg: "-ef".to_string(), + arg_type: ArgType::FILEFILE, + }, + TestArg { + arg: "-nt".to_string(), + arg_type: ArgType::FILEFILE, + }, + ] +} + +fn generate_test_arg() -> String { + let mut rng = rand::thread_rng(); + let test_args = generate_test_args(); + let mut arg = String::new(); + + let choice = rng.gen_range(0..=5); + + match choice { + 0 => { + arg.push_str(&rng.gen_range(-100..=100).to_string()); + } + 1 | 2 | 3 => { + let test_arg = test_args + .choose(&mut rng) + .expect("Failed to choose a random test argument"); + if test_arg.arg_type == ArgType::INTEGER { + arg.push_str(&format!( + "{} {} {}", + &rng.gen_range(-100..=100).to_string(), + test_arg.arg, + &rng.gen_range(-100..=100).to_string() + )); + } else if test_arg.arg_type == ArgType::STRINGSTRING { + let random_str = generate_random_string(rng.gen_range(1..=10)); + let random_str2 = generate_random_string(rng.gen_range(1..=10)); + + arg.push_str(&format!( + "{} {} {}", + &random_str, test_arg.arg, &random_str2 + )); + } else if test_arg.arg_type == ArgType::STRING { + let random_str = generate_random_string(rng.gen_range(1..=10)); + arg.push_str(&format!("{} {}", test_arg.arg, &random_str)); + } else if test_arg.arg_type == ArgType::FILEFILE { + let path = generate_random_path(&mut rng); + let path2 = generate_random_path(&mut rng); + arg.push_str(&format!("{} {} {}", path, test_arg.arg, path2)); + } else if test_arg.arg_type == ArgType::FILE { + let path = generate_random_path(&mut rng); + arg.push_str(&format!("{} {}", test_arg.arg, path)); + } + } + 4 => { + let random_str = generate_random_string(rng.gen_range(1..=10)); + arg.push_str(&random_str); + } + _ => { + let path = generate_random_path(&mut rng); + + let file_test_args: Vec = test_args + .iter() + .filter(|ta| ta.arg_type == ArgType::FILE) + .cloned() + .collect(); + + if let Some(test_arg) = file_test_args.choose(&mut rng) { + arg.push_str(&format!("{}{}", test_arg.arg, path)); + } + } + } + + arg +} + +fuzz_target!(|_data: &[u8]| { + let mut rng = rand::thread_rng(); + let max_args = rng.gen_range(1..=6); + let mut args = vec![OsString::from("test")]; + let uumain_exit_status; + + for _ in 0..max_args { + args.push(OsString::from(generate_test_arg())); + } + + // Save the original stdout file descriptor + let original_stdout_fd = unsafe { dup(STDOUT_FILENO) }; + println!("Running test {:?}", &args[1..]); + // Create a pipe to capture stdout + let mut pipe_fds = [-1; 2]; + unsafe { libc::pipe(pipe_fds.as_mut_ptr()) }; + + { + // Redirect stdout to the write end of the pipe + unsafe { dup2(pipe_fds[1], STDOUT_FILENO) }; + + // Run uumain with the provided arguments + uumain_exit_status = uumain(args.clone().into_iter()); + + // Restore original stdout + unsafe { dup2(original_stdout_fd, STDOUT_FILENO) }; + unsafe { libc::close(original_stdout_fd) }; + } + // Close the write end of the pipe + unsafe { libc::close(pipe_fds[1]) }; + + // Read captured output from the read end of the pipe + let mut captured_output = Vec::new(); + let mut read_buffer = [0; 1024]; + loop { + let bytes_read = unsafe { + libc::read( + pipe_fds[0], + read_buffer.as_mut_ptr() as *mut libc::c_void, + read_buffer.len(), + ) + }; + if bytes_read <= 0 { + break; + } + captured_output.extend_from_slice(&read_buffer[..bytes_read as usize]); + } + + // Close the read end of the pipe + unsafe { libc::close(pipe_fds[0]) }; + + // Convert captured output to a string + let my_output = String::from_utf8_lossy(&captured_output) + .to_string() + .trim() + .to_owned(); + + // Run GNU test with the provided arguments and compare the output + match run_gnu_test(&args[1..]) { + Ok((gnu_output, gnu_exit_status)) => { + let gnu_output = gnu_output.trim().to_owned(); + println!("gnu_exit_status {}", gnu_exit_status); + println!("uumain_exit_status {}", uumain_exit_status); + if my_output != gnu_output || uumain_exit_status != gnu_exit_status { + println!("Discrepancy detected!"); + println!("Test: {:?}", &args[1..]); + println!("My output: {}", my_output); + println!("GNU output: {}", gnu_output); + println!("My exit status: {}", uumain_exit_status); + println!("GNU exit status: {}", gnu_exit_status); + panic!(); + } else { + println!( + "Outputs and exit statuses matched for expression {:?}", + &args[1..] + ); + } + } + Err(_) => { + println!("GNU test execution failed for expression {:?}", &args[1..]); + } + } +}); diff --git a/oranda.json b/oranda.json index b0a93c19aff..7c52ddc2796 100644 --- a/oranda.json +++ b/oranda.json @@ -2,6 +2,9 @@ "project": { "name": "uutils coreutils" }, + "build": { + "path_prefix": "coreutils" + }, "components": { "changelog": true }, diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index d6487dc490e..fc2cd16add2 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Michael Gehring -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/bin/uudoc.rs b/src/bin/uudoc.rs index 5ac8582262d..77c7a2fcfdd 100644 --- a/src/bin/uudoc.rs +++ b/src/bin/uudoc.rs @@ -42,6 +42,7 @@ fn main() -> io::Result<()> { [Introduction](index.md)\n\ * [Installation](installation.md)\n\ * [Build from source](build.md)\n\ + * [Platform support](platforms.md)\n\ * [Contributing](contributing.md)\n\ * [GNU test coverage](test_coverage.md)\n\ * [Extensions](extensions.md)\n\ @@ -53,7 +54,7 @@ fn main() -> io::Result<()> { println!("Gathering utils per platform"); let utils_per_platform = { let mut map = HashMap::new(); - for platform in ["unix", "macos", "windows"] { + for platform in ["unix", "macos", "windows", "unix_android"] { let platform_utils: Vec = String::from_utf8( std::process::Command::new("./util/show-utils.sh") .arg(format!("--features=feat_os_{}", platform)) @@ -61,6 +62,7 @@ fn main() -> io::Result<()> { .stdout, ) .unwrap() + .trim() .split(' ') .map(ToString::to_string) .collect(); @@ -75,6 +77,7 @@ fn main() -> io::Result<()> { .stdout, ) .unwrap() + .trim() .split(' ') .map(ToString::to_string) .collect(); @@ -83,9 +86,47 @@ fn main() -> io::Result<()> { map }; - println!("Writing to utils"); let mut utils = utils.entries().collect::>(); utils.sort(); + + println!("Writing util per platform table"); + { + let mut platform_table_file = File::create("docs/src/platform_table.md").unwrap(); + + // sum, cksum, b2sum, etc. are all available on all platforms, but not in the data structure + // otherwise, we check the map for the util name. + let check_supported = |name: &str, platform: &str| { + if name.ends_with("sum") || utils_per_platform[platform].iter().any(|u| u == name) { + "✓" + } else { + " " + } + }; + writeln!( + platform_table_file, + "| util | Linux | macOS | Windows | FreeBSD | Android |\n\ + | ---------------- | ----- | ----- | ------- | ------- | ------- |" + )?; + for (&name, _) in &utils { + if name == "[" { + continue; + } + // The alignment is not necessary, but makes the output a bit more + // pretty when viewed as plain markdown. + writeln!( + platform_table_file, + "| {:<16} | {:<5} | {:<5} | {:<7} | {:<7} | {:<7} |", + format!("**{name}**"), + check_supported(name, "linux"), + check_supported(name, "macos"), + check_supported(name, "windows"), + check_supported(name, "unix"), + check_supported(name, "unix_android"), + )?; + } + } + + println!("Writing to utils"); for (&name, (_, command)) in utils { if name == "[" { continue; diff --git a/src/uu/arch/src/arch.rs b/src/uu/arch/src/arch.rs index 96eba1ef947..0d71a818379 100644 --- a/src/uu/arch/src/arch.rs +++ b/src/uu/arch/src/arch.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Smigle00 -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/base32/src/base32.rs b/src/uu/base32/src/base32.rs index 740e2d70be5..2ef63fbc0b9 100644 --- a/src/uu/base32/src/base32.rs +++ b/src/uu/base32/src/base32.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. diff --git a/src/uu/base32/src/base_common.rs b/src/uu/base32/src/base_common.rs index 78698e8b941..ba2ef922977 100644 --- a/src/uu/base32/src/base_common.rs +++ b/src/uu/base32/src/base_common.rs @@ -1,9 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jordy Dickinson -// (c) Jian Zeng -// (c) Alex Lyon -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. diff --git a/src/uu/base64/src/base64.rs b/src/uu/base64/src/base64.rs index e502482e331..4e4a3c29375 100644 --- a/src/uu/base64/src/base64.rs +++ b/src/uu/base64/src/base64.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jordy Dickinson -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index ed7faee6566..6c9baca6fce 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jimmy Lu -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. @@ -11,6 +9,7 @@ use clap::{crate_version, Arg, ArgAction, Command}; use std::path::{is_separator, PathBuf}; use uucore::display::Quotable; use uucore::error::{UResult, UUsageError}; +use uucore::line_ending::LineEnding; use uucore::{format_usage, help_about, help_usage}; static ABOUT: &str = help_about!("basename.md"); @@ -54,9 +53,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { return Err(UUsageError::new(1, "missing operand".to_string())); } + let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO)); + let opt_suffix = matches.get_one::(options::SUFFIX).is_some(); let opt_multiple = matches.get_flag(options::MULTIPLE); - let opt_zero = matches.get_flag(options::ZERO); let multiple_paths = opt_suffix || opt_multiple; let name_args_count = matches .get_many::(options::NAME) @@ -105,7 +105,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .collect() }; - let line_ending = if opt_zero { "\0" } else { "\n" }; for path in paths { print!("{}{}", basename(path, suffix), line_ending); } diff --git a/src/uu/basenc/src/basenc.rs b/src/uu/basenc/src/basenc.rs index 3ec8cede01a..0ee8a816bd6 100644 --- a/src/uu/basenc/src/basenc.rs +++ b/src/uu/basenc/src/basenc.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jordy Dickinson -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index 2c4117a329f..8ce8052517b 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -1,10 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jordi Boggiano -// (c) Evgeniy Klyuchikov -// (c) Joshua S. Miller -// (c) Árni Dagur -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. @@ -192,7 +187,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { NumberingMode::None }; - let show_nonprint = vec![ + let show_nonprint = [ options::SHOW_ALL.to_owned(), options::SHOW_NONPRINTING_ENDS.to_owned(), options::SHOW_NONPRINTING_TABS.to_owned(), @@ -201,7 +196,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .iter() .any(|v| matches.get_flag(v)); - let show_ends = vec![ + let show_ends = [ options::SHOW_ENDS.to_owned(), options::SHOW_ALL.to_owned(), options::SHOW_NONPRINTING_ENDS.to_owned(), @@ -209,7 +204,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .iter() .any(|v| matches.get_flag(v)); - let show_tabs = vec![ + let show_tabs = [ options::SHOW_ALL.to_owned(), options::SHOW_TABS.to_owned(), options::SHOW_NONPRINTING_TABS.to_owned(), diff --git a/src/uu/cat/src/splice.rs b/src/uu/cat/src/splice.rs index 26802c7e671..5a9e8738ed2 100644 --- a/src/uu/cat/src/splice.rs +++ b/src/uu/cat/src/splice.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use super::{CatResult, FdReadable, InputHandle}; use nix::unistd; diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index 63ae3abea63..ec111c853fd 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (vars) RFILE #![allow(clippy::upper_case_acronyms)] diff --git a/src/uu/chcon/src/errors.rs b/src/uu/chcon/src/errors.rs index 0bd61ec4ab3..10d5735a0c6 100644 --- a/src/uu/chcon/src/errors.rs +++ b/src/uu/chcon/src/errors.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::ffi::OsString; use std::fmt::Write; use std::io; diff --git a/src/uu/chcon/src/fts.rs b/src/uu/chcon/src/fts.rs index 89dd6184d44..a81cb39b658 100644 --- a/src/uu/chcon/src/fts.rs +++ b/src/uu/chcon/src/fts.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::ffi::{CStr, CString, OsStr}; use std::marker::PhantomData; use std::os::raw::{c_int, c_long, c_short}; diff --git a/src/uu/chgrp/src/chgrp.rs b/src/uu/chgrp/src/chgrp.rs index bd01e132b47..fba2cef1611 100644 --- a/src/uu/chgrp/src/chgrp.rs +++ b/src/uu/chgrp/src/chgrp.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index a798860376d..b007bb1d735 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Alex Lyon -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. @@ -438,25 +436,25 @@ mod tests { fn test_extract_negative_modes() { // "chmod -w -r file" becomes "chmod -w,-r file". clap does not accept "-w,-r" as MODE. // Therefore, "w" is added as pseudo mode to pass clap. - let (c, a) = extract_negative_modes(vec!["-w", "-r", "file"].iter().map(OsString::from)); + let (c, a) = extract_negative_modes(["-w", "-r", "file"].iter().map(OsString::from)); assert_eq!(c, Some("-w,-r".to_string())); - assert_eq!(a, vec!["w", "file"]); + assert_eq!(a, ["w", "file"]); // "chmod -w file -r" becomes "chmod -w,-r file". clap does not accept "-w,-r" as MODE. // Therefore, "w" is added as pseudo mode to pass clap. - let (c, a) = extract_negative_modes(vec!["-w", "file", "-r"].iter().map(OsString::from)); + let (c, a) = extract_negative_modes(["-w", "file", "-r"].iter().map(OsString::from)); assert_eq!(c, Some("-w,-r".to_string())); - assert_eq!(a, vec!["w", "file"]); + assert_eq!(a, ["w", "file"]); // "chmod -w -- -r file" becomes "chmod -w -r file", where "-r" is interpreted as file. // Again, "w" is needed as pseudo mode. - let (c, a) = extract_negative_modes(vec!["-w", "--", "-r", "f"].iter().map(OsString::from)); + let (c, a) = extract_negative_modes(["-w", "--", "-r", "f"].iter().map(OsString::from)); assert_eq!(c, Some("-w".to_string())); - assert_eq!(a, vec!["w", "--", "-r", "f"]); + assert_eq!(a, ["w", "--", "-r", "f"]); // "chmod -- -r file" becomes "chmod -r file". - let (c, a) = extract_negative_modes(vec!["--", "-r", "file"].iter().map(OsString::from)); + let (c, a) = extract_negative_modes(["--", "-r", "file"].iter().map(OsString::from)); assert_eq!(c, None); - assert_eq!(a, vec!["--", "-r", "file"]); + assert_eq!(a, ["--", "-r", "file"]); } } diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index 67e71b815b9..8e97d565242 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index 2d1c3703e9d..6366775c36d 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Vsevolod Velichko -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index a46f69302a2..83d48ec1a99 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Michael Gehring -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index 26e70403793..1bb0020d5f0 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -1,18 +1,16 @@ // This file is part of the uutils coreutils package. // -// (c) Michael Gehring -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. // spell-checker:ignore (ToDO) delim mkdelim use std::cmp::Ordering; -use std::fmt::Display; use std::fs::File; use std::io::{self, stdin, BufRead, BufReader, Stdin}; use std::path::Path; use uucore::error::{FromIo, UResult}; +use uucore::line_ending::LineEnding; use uucore::{format_usage, help_about, help_usage}; use clap::{crate_version, Arg, ArgAction, ArgMatches, Command}; @@ -40,38 +38,6 @@ fn column_width(col: &str, opts: &ArgMatches) -> usize { } } -#[repr(u8)] -#[derive(Clone, Copy)] -enum LineEnding { - Newline = b'\n', - Nul = 0, -} - -impl From for u8 { - fn from(line_ending: LineEnding) -> Self { - line_ending as Self - } -} - -impl From for LineEnding { - fn from(is_zero_terminated: bool) -> Self { - if is_zero_terminated { - Self::Nul - } else { - Self::Newline - } - } -} - -impl Display for LineEnding { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::Newline => writeln!(f), - Self::Nul => write!(f, "\0"), - } - } -} - enum Input { Stdin(Stdin), FileIn(BufReader), @@ -168,7 +134,7 @@ fn comm(a: &mut LineReader, b: &mut LineReader, opts: &ArgMatches) { } if opts.get_flag(options::TOTAL) { - let line_ending = LineEnding::from(opts.get_flag(options::ZERO_TERMINATED)); + let line_ending = LineEnding::from_zero_flag(opts.get_flag(options::ZERO_TERMINATED)); print!("{total_col_1}{delim}{total_col_2}{delim}{total_col_3}{delim}total{line_ending}"); } } @@ -190,7 +156,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); let matches = uu_app().try_get_matches_from(args)?; - let line_ending = LineEnding::from(matches.get_flag(options::ZERO_TERMINATED)); + let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO_TERMINATED)); let filename1 = matches.get_one::(options::FILE_1).unwrap(); let filename2 = matches.get_one::(options::FILE_2).unwrap(); let mut f1 = open_file(filename1, line_ending).map_err_context(|| filename1.to_string())?; diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index e0a40d56e87..ce16357c6b0 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -3,9 +3,6 @@ // This file is part of the uutils coreutils package. // -// (c) Jordy Dickinson -// (c) Joshua S. Miller -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index d1925308e77..6c9a776c388 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. #![crate_name = "uu_csplit"] // spell-checker:ignore rustdoc #![allow(rustdoc::private_intra_doc_links)] diff --git a/src/uu/csplit/src/csplit_error.rs b/src/uu/csplit/src/csplit_error.rs index b81a331a226..1559a29f8bc 100644 --- a/src/uu/csplit/src/csplit_error.rs +++ b/src/uu/csplit/src/csplit_error.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::io; use thiserror::Error; diff --git a/src/uu/csplit/src/patterns.rs b/src/uu/csplit/src/patterns.rs index 652b024d8d7..fd96fd9fb9e 100644 --- a/src/uu/csplit/src/patterns.rs +++ b/src/uu/csplit/src/patterns.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (regex) SKIPTO UPTO ; (vars) ntimes use crate::csplit_error::CsplitError; diff --git a/src/uu/csplit/src/split_name.rs b/src/uu/csplit/src/split_name.rs index 19e3ac9c221..4d94b56a923 100644 --- a/src/uu/csplit/src/split_name.rs +++ b/src/uu/csplit/src/split_name.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (regex) diuox use regex::Regex; diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index 68ad566d7c4..89128175354 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Rolf Morel -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. @@ -15,6 +13,7 @@ use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write}; use std::path::Path; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError}; +use uucore::line_ending::LineEnding; use self::searcher::Searcher; use matcher::{ExactMatcher, Matcher, WhitespaceMatcher}; @@ -30,7 +29,7 @@ const AFTER_HELP: &str = help_section!("after help", "cut.md"); struct Options { out_delim: Option, - zero_terminated: bool, + line_ending: LineEnding, } enum Delimiter { @@ -42,7 +41,7 @@ struct FieldOptions { delimiter: Delimiter, out_delimiter: Option, only_delimited: bool, - zero_terminated: bool, + line_ending: LineEnding, } enum Mode { @@ -68,7 +67,7 @@ fn list_to_ranges(list: &str, complement: bool) -> Result, String> { } fn cut_bytes(reader: R, ranges: &[Range], opts: &Options) -> UResult<()> { - let newline_char = if opts.zero_terminated { b'\0' } else { b'\n' }; + let newline_char = opts.line_ending.into(); let mut buf_in = BufReader::new(reader); let mut out = stdout_writer(); let delim = opts @@ -259,7 +258,7 @@ fn cut_fields_implicit_out_delim( } fn cut_fields(reader: R, ranges: &[Range], opts: &FieldOptions) -> UResult<()> { - let newline_char = if opts.zero_terminated { b'\0' } else { b'\n' }; + let newline_char = opts.line_ending.into(); match opts.delimiter { Delimiter::String(ref delim) => { let matcher = ExactMatcher::new(delim.as_bytes()); @@ -376,7 +375,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .unwrap_or_default() .to_owned(), ), - zero_terminated: matches.get_flag(options::ZERO_TERMINATED), + line_ending: LineEnding::from_zero_flag(matches.get_flag(options::ZERO_TERMINATED)), }, ) }), @@ -391,7 +390,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .unwrap_or_default() .to_owned(), ), - zero_terminated: matches.get_flag(options::ZERO_TERMINATED), + line_ending: LineEnding::from_zero_flag(matches.get_flag(options::ZERO_TERMINATED)), }, ) }), @@ -411,6 +410,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let only_delimited = matches.get_flag(options::ONLY_DELIMITED); let whitespace_delimited = matches.get_flag(options::WHITESPACE_DELIMITED); let zero_terminated = matches.get_flag(options::ZERO_TERMINATED); + let line_ending = LineEnding::from_zero_flag(zero_terminated); match matches.get_one::(options::DELIMITER).map(|s| s.as_str()) { Some(_) if whitespace_delimited => { @@ -441,7 +441,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { delimiter: Delimiter::String(delim), out_delimiter: out_delim, only_delimited, - zero_terminated, + line_ending, }, )) } @@ -455,7 +455,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { }, out_delimiter: out_delim, only_delimited, - zero_terminated, + line_ending, }, )), } diff --git a/src/uu/cut/src/searcher.rs b/src/uu/cut/src/searcher.rs index 95d85c020a9..21424790eea 100644 --- a/src/uu/cut/src/searcher.rs +++ b/src/uu/cut/src/searcher.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Rolf Morel -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index adfb74128f0..745fd54239c 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Anthony Deschamps -// (c) Sylvestre Ledru -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. @@ -227,8 +224,20 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { DateSource::Human(relative_time) => { // Get the current DateTime for things like "1 year ago" let current_time = DateTime::::from(Local::now()); - let iter = std::iter::once(Ok(current_time + relative_time)); - Box::new(iter) + // double check the result is overflow or not of the current_time + relative_time + // it may cause a panic of chrono::datetime::DateTime add + match current_time.checked_add_signed(relative_time) { + Some(date) => { + let iter = std::iter::once(Ok(date)); + Box::new(iter) + } + None => { + return Err(USimpleError::new( + 1, + format!("invalid date {}", relative_time), + )); + } + } } DateSource::File(ref path) => { if path.is_dir() { diff --git a/src/uu/dd/src/conversion_tables.rs b/src/uu/dd/src/conversion_tables.rs index aca2ef9bc81..bdf6398ac7c 100644 --- a/src/uu/dd/src/conversion_tables.rs +++ b/src/uu/dd/src/conversion_tables.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Tyler Steele -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/dd/src/datastructures.rs b/src/uu/dd/src/datastructures.rs index 6830df63e3b..c0da8c67cbf 100644 --- a/src/uu/dd/src/datastructures.rs +++ b/src/uu/dd/src/datastructures.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Tyler Steele -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. // spell-checker:ignore ctable, outfile, iseek, oseek diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 4e1287939d5..4ac2aa78006 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Tyler Steele -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/dd/src/parseargs.rs b/src/uu/dd/src/parseargs.rs index 20a8da1ee7b..bccf98f825c 100644 --- a/src/uu/dd/src/parseargs.rs +++ b/src/uu/dd/src/parseargs.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Tyler Steele -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. // spell-checker:ignore ctty, ctable, iseek, oseek, iconvflags, oconvflags parseargs outfile oconv diff --git a/src/uu/dd/src/parseargs/unit_tests.rs b/src/uu/dd/src/parseargs/unit_tests.rs index 54e17b882e2..a190fd75bd2 100644 --- a/src/uu/dd/src/parseargs/unit_tests.rs +++ b/src/uu/dd/src/parseargs/unit_tests.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore fname, tname, fpath, specfile, testfile, unspec, ifile, ofile, outfile, fullblock, urand, fileio, atoe, atoibm, behaviour, bmax, bremain, btotal, cflags, creat, ctable, ctty, datastructures, doesnt, etoa, fileout, fname, gnudd, iconvflags, iseek, nocache, noctty, noerror, nofollow, nolinks, nonblock, oconvflags, oseek, outfile, parseargs, rlen, rmax, rposition, rremain, rsofar, rstat, sigusr, sigval, wlen, wstat, oconv use super::*; diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index ef158432367..9a3eeac6582 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Fangxu Hu -// (c) Sylvestre Ledru -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. // spell-checker:ignore itotal iused iavail ipcent pcent tmpfs squashfs lofs diff --git a/src/uu/dircolors/src/colors.rs b/src/uu/dircolors/src/colors.rs index d864a23b366..c0a981db89c 100644 --- a/src/uu/dircolors/src/colors.rs +++ b/src/uu/dircolors/src/colors.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (ToDO) EIGHTBIT ETERM MULTIHARDLINK cpio dtterm jfbterm konsole kterm mlterm rmvb rxvt stat'able svgz tmux webm xspf COLORTERM tzst avif tzst mjpg mjpeg webp dpkg rpmnew rpmorig rpmsave pub const INTERNAL_DB: &str = r#"# Configuration file for dircolors, a utility to help you set the diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index 19c3f7e31c1..2e3087d810b 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jian Zeng -// (c) Mitchell Mebane -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. @@ -168,9 +165,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { println!("{s}"); Ok(()) } - Err(s) => { - return Err(USimpleError::new(1, s)); - } + Err(s) => Err(USimpleError::new(1, s)), } } diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index cecd6aec8b9..9a56e9f5bd6 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Derek Chiang -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. @@ -9,6 +7,7 @@ use clap::{crate_version, Arg, ArgAction, Command}; use std::path::Path; use uucore::display::print_verbatim; use uucore::error::{UResult, UUsageError}; +use uucore::line_ending::LineEnding; use uucore::{format_usage, help_about, help_section, help_usage}; const ABOUT: &str = help_about!("dirname.md"); @@ -26,11 +25,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().after_help(AFTER_HELP).try_get_matches_from(args)?; - let separator = if matches.get_flag(options::ZERO) { - "\0" - } else { - "\n" - }; + let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO)); let dirnames: Vec = matches .get_many::(options::DIR) @@ -59,7 +54,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } } } - print!("{separator}"); + print!("{line_ending}"); } } diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index db385c720ea..14bda496772 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -34,6 +34,7 @@ use std::{error::Error, fmt::Display}; use uucore::display::{print_verbatim, Quotable}; use uucore::error::FromIo; use uucore::error::{set_exit_code, UError, UResult}; +use uucore::line_ending::LineEnding; use uucore::parse_glob; use uucore::parse_size::{parse_size, ParseSizeError}; use uucore::{ @@ -600,11 +601,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let time_format_str = parse_time_style(matches.get_one::("time-style").map(|s| s.as_str()))?; - let line_separator = if matches.get_flag(options::NULL) { - "\0" - } else { - "\n" - }; + let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::NULL)); let excludes = build_exclude_patterns(&matches)?; @@ -656,12 +653,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let time_str = tm.format(time_format_str).to_string(); print!("{}\t{}\t", convert_size(size), time_str); print_verbatim(stat.path).unwrap(); - print!("{line_separator}"); + print!("{line_ending}"); } } else if !summarize || index == len - 1 { print!("{}\t", convert_size(size)); print_verbatim(stat.path).unwrap(); - print!("{line_separator}"); + print!("{line_ending}"); } if options.total && index == (len - 1) { // The last element will be the total size of the the path under @@ -681,7 +678,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if options.total { print!("{}\ttotal", convert_size(grand_total)); - print!("{line_separator}"); + print!("{line_ending}"); } Ok(()) diff --git a/src/uu/echo/src/echo.rs b/src/uu/echo/src/echo.rs index 659dc836c23..cd9467714aa 100644 --- a/src/uu/echo/src/echo.rs +++ b/src/uu/echo/src/echo.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Derek Chiang -// (c) Christopher Brown -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index b293bc9bf66..e031e39e31f 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jordi Boggiano -// (c) Thomas Queiroz -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. @@ -23,6 +20,7 @@ use std::os::unix::process::ExitStatusExt; use std::process; use uucore::display::Quotable; use uucore::error::{UClapError, UResult, USimpleError, UUsageError}; +use uucore::line_ending::LineEnding; use uucore::{format_usage, help_about, help_section, help_usage, show_warning}; const ABOUT: &str = help_about!("env.md"); @@ -31,7 +29,7 @@ const AFTER_HELP: &str = help_section!("after help", "env.md"); struct Options<'a> { ignore_env: bool, - null: bool, + line_ending: LineEnding, running_directory: Option<&'a str>, files: Vec<&'a str>, unsets: Vec<&'a str>, @@ -41,11 +39,11 @@ struct Options<'a> { // print name=value env pairs on screen // if null is true, separate pairs with a \0, \n otherwise -fn print_env(null: bool) { +fn print_env(line_ending: LineEnding) { let stdout_raw = io::stdout(); let mut stdout = stdout_raw.lock(); for (n, v) in env::vars() { - write!(stdout, "{}={}{}", n, v, if null { '\0' } else { '\n' }).unwrap(); + write!(stdout, "{}={}{}", n, v, line_ending).unwrap(); } } @@ -64,7 +62,7 @@ fn parse_name_value_opt<'a>(opts: &mut Options<'a>, opt: &'a str) -> UResult(opts: &mut Options<'a>, opt: &'a str) -> UResult<()> { - if opts.null { + if opts.line_ending == LineEnding::Nul { Err(UUsageError::new( 125, "cannot specify --null (-0) with command".to_string(), @@ -181,7 +179,7 @@ fn run_env(args: impl uucore::Args) -> UResult<()> { let matches = app.try_get_matches_from(args).with_exit_code(125)?; let ignore_env = matches.get_flag("ignore-environment"); - let null = matches.get_flag("null"); + let line_ending = LineEnding::from_zero_flag(matches.get_flag("null")); let running_directory = matches.get_one::("chdir").map(|s| s.as_str()); let files = match matches.get_many::("file") { Some(v) => v.map(|s| s.as_str()).collect(), @@ -194,7 +192,7 @@ fn run_env(args: impl uucore::Args) -> UResult<()> { let mut opts = Options { ignore_env, - null, + line_ending, running_directory, files, unsets, @@ -302,7 +300,7 @@ fn run_env(args: impl uucore::Args) -> UResult<()> { if opts.program.is_empty() { // no program provided, so just dump all env vars to stdout - print_env(opts.null); + print_env(opts.line_ending); } else { // we need to execute a command let (prog, args) = build_command(&mut opts.program); diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 98b292771ea..fb73ce4b5b8 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Virgile Andreani -// (c) kwantam -// * 2015-04-28 ~ updated to work with both UTF-8 and non-UTF-8 encodings // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/groups/src/groups.rs b/src/uu/groups/src/groups.rs index dd1cd9b04ae..0f0dfce804a 100644 --- a/src/uu/groups/src/groups.rs +++ b/src/uu/groups/src/groups.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Alan Andrade -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. // diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index 2517a98ea45..931f8a65242 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -10,6 +10,7 @@ use std::ffi::OsString; use std::io::{self, BufWriter, ErrorKind, Read, Seek, SeekFrom, Write}; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult, USimpleError}; +use uucore::line_ending::LineEnding; use uucore::lines::lines; use uucore::{format_usage, help_about, help_usage, show}; @@ -184,7 +185,7 @@ fn arg_iterate<'a>( struct HeadOptions { pub quiet: bool, pub verbose: bool, - pub zeroed: bool, + pub line_ending: LineEnding, pub presume_input_pipe: bool, pub mode: Mode, pub files: Vec, @@ -197,7 +198,7 @@ impl HeadOptions { options.quiet = matches.get_flag(options::QUIET_NAME); options.verbose = matches.get_flag(options::VERBOSE_NAME); - options.zeroed = matches.get_flag(options::ZERO_NAME); + options.line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO_NAME)); options.presume_input_pipe = matches.get_flag(options::PRESUME_INPUT_PIPE); options.mode = Mode::from(matches)?; @@ -227,9 +228,8 @@ where Ok(()) } -fn read_n_lines(input: &mut impl std::io::BufRead, n: u64, zero: bool) -> std::io::Result<()> { +fn read_n_lines(input: &mut impl std::io::BufRead, n: u64, separator: u8) -> std::io::Result<()> { // Read the first `n` lines from the `input` reader. - let separator = if zero { b'\0' } else { b'\n' }; let mut reader = take_lines(input, n, separator); // Write those bytes to `stdout`. @@ -293,20 +293,12 @@ fn read_but_last_n_bytes(input: &mut impl std::io::BufRead, n: usize) -> std::io fn read_but_last_n_lines( input: impl std::io::BufRead, n: usize, - zero: bool, + separator: u8, ) -> std::io::Result<()> { - if zero { - let stdout = std::io::stdout(); - let mut stdout = stdout.lock(); - for bytes in take_all_but(lines(input, b'\0'), n) { - stdout.write_all(&bytes?)?; - } - } else { - let stdout = std::io::stdout(); - let mut stdout = stdout.lock(); - for bytes in take_all_but(lines(input, b'\n'), n) { - stdout.write_all(&bytes?)?; - } + let stdout = std::io::stdout(); + let mut stdout = stdout.lock(); + for bytes in take_all_but(lines(input, separator), n) { + stdout.write_all(&bytes?)?; } Ok(()) } @@ -350,7 +342,7 @@ fn read_but_last_n_lines( /// assert_eq!(find_nth_line_from_end(&mut input, 4, false).unwrap(), 0); /// assert_eq!(find_nth_line_from_end(&mut input, 1000, false).unwrap(), 0); /// ``` -fn find_nth_line_from_end(input: &mut R, n: u64, zeroed: bool) -> std::io::Result +fn find_nth_line_from_end(input: &mut R, n: u64, separator: u8) -> std::io::Result where R: Read + Seek, { @@ -370,14 +362,8 @@ where ))?; input.read_exact(buffer)?; for byte in buffer.iter().rev() { - match byte { - b'\n' if !zeroed => { - lines += 1; - } - 0u8 if zeroed => { - lines += 1; - } - _ => {} + if byte == &separator { + lines += 1; } // if it were just `n`, if lines == n + 1 { @@ -407,7 +393,7 @@ fn head_backwards_file(input: &mut std::fs::File, options: &HeadOptions) -> std: } } Mode::AllButLastLines(n) => { - let found = find_nth_line_from_end(input, n, options.zeroed)?; + let found = find_nth_line_from_end(input, n, options.line_ending.into())?; read_n_bytes( &mut std::io::BufReader::with_capacity(BUF_SIZE, input), found, @@ -426,7 +412,7 @@ fn head_file(input: &mut std::fs::File, options: &HeadOptions) -> std::io::Resul Mode::FirstLines(n) => read_n_lines( &mut std::io::BufReader::with_capacity(BUF_SIZE, input), n, - options.zeroed, + options.line_ending.into(), ), Mode::AllButLastBytes(_) | Mode::AllButLastLines(_) => head_backwards_file(input, options), } @@ -466,11 +452,13 @@ fn uu_head(options: &HeadOptions) -> UResult<()> { Mode::AllButLastBytes(n) => { read_but_last_n_bytes(&mut stdin, n.try_into().unwrap()) } - Mode::FirstLines(n) => read_n_lines(&mut stdin, n, options.zeroed), + Mode::FirstLines(n) => read_n_lines(&mut stdin, n, options.line_ending.into()), // unwrap is guaranteed to succeed because we checked the value of n above - Mode::AllButLastLines(n) => { - read_but_last_n_lines(&mut stdin, n.try_into().unwrap(), options.zeroed) - } + Mode::AllButLastLines(n) => read_but_last_n_lines( + &mut stdin, + n.try_into().unwrap(), + options.line_ending.into(), + ), } } (name, false) => { @@ -541,7 +529,7 @@ mod tests { #[test] fn test_args_modes() { let args = options("-n -10M -vz").unwrap(); - assert!(args.zeroed); + assert_eq!(args.line_ending, LineEnding::Nul); assert!(args.verbose); assert_eq!(args.mode, Mode::AllButLastLines(10 * 1024 * 1024)); } @@ -561,8 +549,11 @@ mod tests { assert!(options("-q").unwrap().quiet); assert!(options("--verbose").unwrap().verbose); assert!(options("-v").unwrap().verbose); - assert!(options("--zero-terminated").unwrap().zeroed); - assert!(options("-z").unwrap().zeroed); + assert_eq!( + options("--zero-terminated").unwrap().line_ending, + LineEnding::Nul + ); + assert_eq!(options("-z").unwrap().line_ending, LineEnding::Nul); assert_eq!(options("--lines 15").unwrap().mode, Mode::FirstLines(15)); assert_eq!(options("-n 15").unwrap().mode, Mode::FirstLines(15)); assert_eq!(options("--bytes 15").unwrap().mode, Mode::FirstBytes(15)); @@ -579,7 +570,7 @@ mod tests { assert!(!opts.verbose); assert!(!opts.quiet); - assert!(!opts.zeroed); + assert_eq!(opts.line_ending, LineEnding::Newline); assert_eq!(opts.mode, Mode::FirstLines(10)); assert!(opts.files.is_empty()); } @@ -631,17 +622,17 @@ mod tests { fn read_early_exit() { let mut empty = std::io::BufReader::new(std::io::Cursor::new(Vec::new())); assert!(read_n_bytes(&mut empty, 0).is_ok()); - assert!(read_n_lines(&mut empty, 0, false).is_ok()); + assert!(read_n_lines(&mut empty, 0, b'\n').is_ok()); } #[test] fn test_find_nth_line_from_end() { let mut input = Cursor::new("x\ny\nz\n"); - assert_eq!(find_nth_line_from_end(&mut input, 0, false).unwrap(), 6); - assert_eq!(find_nth_line_from_end(&mut input, 1, false).unwrap(), 4); - assert_eq!(find_nth_line_from_end(&mut input, 2, false).unwrap(), 2); - assert_eq!(find_nth_line_from_end(&mut input, 3, false).unwrap(), 0); - assert_eq!(find_nth_line_from_end(&mut input, 4, false).unwrap(), 0); - assert_eq!(find_nth_line_from_end(&mut input, 1000, false).unwrap(), 0); + assert_eq!(find_nth_line_from_end(&mut input, 0, b'\n').unwrap(), 6); + assert_eq!(find_nth_line_from_end(&mut input, 1, b'\n').unwrap(), 4); + assert_eq!(find_nth_line_from_end(&mut input, 2, b'\n').unwrap(), 2); + assert_eq!(find_nth_line_from_end(&mut input, 3, b'\n').unwrap(), 0); + assert_eq!(find_nth_line_from_end(&mut input, 4, b'\n').unwrap(), 0); + assert_eq!(find_nth_line_from_end(&mut input, 1000, b'\n').unwrap(), 0); } } diff --git a/src/uu/head/src/take.rs b/src/uu/head/src/take.rs index 47beba8a48d..da48afd6a86 100644 --- a/src/uu/head/src/take.rs +++ b/src/uu/head/src/take.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. //! Take all but the last elements of an iterator. use std::io::Read; diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index 7a8e40059be..49ad549257d 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Alan Andrade -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. @@ -44,6 +41,7 @@ use uucore::error::UResult; use uucore::error::{set_exit_code, USimpleError}; pub use uucore::libc; use uucore::libc::{getlogin, uid_t}; +use uucore::line_ending::LineEnding; use uucore::process::{getegid, geteuid, getgid, getuid}; use uucore::{format_usage, help_about, help_section, help_usage, show_error}; @@ -174,13 +172,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { " ".to_string() } }; - let line_ending = { - if state.zflag { - '\0' - } else { - '\n' - } - }; + let line_ending = LineEnding::from_zero_flag(state.zflag); if state.cflag { if state.selinux_supported { @@ -313,7 +305,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } if default_format { - id_print(&mut state, &groups); + id_print(&state, &groups); } print!("{line_ending}"); @@ -555,7 +547,7 @@ fn auditid() { println!("asid={}", auditinfo.ai_asid); } -fn id_print(state: &mut State, groups: &[u32]) { +fn id_print(state: &State, groups: &[u32]) { let uid = state.ids.as_ref().unwrap().uid; let gid = state.ids.as_ref().unwrap().gid; let euid = state.ids.as_ref().unwrap().euid; diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index e0307fe34b7..8aca020afa5 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -619,7 +619,7 @@ fn copy_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UR if !target_dir.is_dir() { return Err(InstallError::TargetDirIsntDir(target_dir.to_path_buf()).into()); } - for sourcepath in files.iter() { + for sourcepath in files { if let Err(err) = sourcepath .metadata() .map_err_context(|| format!("cannot stat {}", sourcepath.quote())) diff --git a/src/uu/install/src/mode.rs b/src/uu/install/src/mode.rs index 6c76dd01677..f9018e16f8e 100644 --- a/src/uu/install/src/mode.rs +++ b/src/uu/install/src/mode.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::fs; use std::path::Path; #[cfg(not(windows))] diff --git a/src/uu/join/src/join.rs b/src/uu/join/src/join.rs index de1a9181be7..afcb4d7d2e3 100644 --- a/src/uu/join/src/join.rs +++ b/src/uu/join/src/join.rs @@ -22,6 +22,7 @@ use std::num::IntErrorKind; use std::os::unix::ffi::OsStrExt; use uucore::display::Quotable; use uucore::error::{set_exit_code, UError, UResult, USimpleError}; +use uucore::line_ending::LineEnding; use uucore::{crash, crash_if_err, format_usage, help_about, help_usage}; const ABOUT: &str = help_about!("join.md"); @@ -62,13 +63,6 @@ enum FileNum { File2, } -#[repr(u8)] -#[derive(Copy, Clone)] -enum LineEnding { - Nul = 0, - Newline = b'\n', -} - #[derive(Copy, Clone, PartialEq)] enum Sep { Char(u8), @@ -683,9 +677,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { settings.headers = true; } - if matches.get_flag("z") { - settings.line_ending = LineEnding::Nul; - } + settings.line_ending = LineEnding::from_zero_flag(matches.get_flag("z")); let file1 = matches.get_one::("file1").unwrap(); let file2 = matches.get_one::("file2").unwrap(); diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index cead745cd54..7927681531c 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jeremiah Peschka -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. @@ -54,6 +52,7 @@ use unicode_width::UnicodeWidthStr; use uucore::libc::{dev_t, major, minor}; #[cfg(unix)] use uucore::libc::{S_IXGRP, S_IXOTH, S_IXUSR}; +use uucore::line_ending::LineEnding; use uucore::quoting_style::{escape_name, QuotingStyle}; use uucore::{ display::Quotable, @@ -408,7 +407,7 @@ pub struct Config { context: bool, selinux_supported: bool, group_directories_first: bool, - eol: char, + line_ending: LineEnding, } // Fields that can be removed or added to the long format @@ -1005,11 +1004,7 @@ impl Config { } }, group_directories_first: options.get_flag(options::GROUP_DIRECTORIES_FIRST), - eol: if options.get_flag(options::ZERO) { - '\0' - } else { - '\n' - }, + line_ending: LineEnding::from_zero_flag(options.get_flag(options::ZERO)), }) } } @@ -2173,7 +2168,7 @@ fn display_total(items: &[PathData], config: &Config, out: &mut BufWriter 0 { - write!(out, "{}", config.eol)?; + write!(out, "{}", config.line_ending)?; } } _ => { for name in names { - write!(out, "{}{}", name.contents, config.eol)?; + write!(out, "{}{}", name.contents, config.line_ending)?; } } }; @@ -2491,7 +2486,13 @@ fn display_item_long( let dfn = display_file_name(item, config, None, String::new(), out).contents; - write!(out, " {} {}{}", display_date(md, config), dfn, config.eol)?; + write!( + out, + " {} {}{}", + display_date(md, config), + dfn, + config.line_ending + )?; } else { #[cfg(unix)] let leading_char = { diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index ad7618cc8a0..ceafd235b01 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. @@ -101,12 +99,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { matches.get_one::("major"), matches.get_one::("minor"), ) { - (_, None) | (None, _) => { - return Err(UUsageError::new( - 1, - "Special files require major and minor device numbers.", - )); - } + (_, None) | (None, _) => Err(UUsageError::new( + 1, + "Special files require major and minor device numbers.", + )), (Some(&major), Some(&minor)) => { let dev = makedev(major, minor); let exit_code = match file_type { diff --git a/src/uu/mknod/src/parsemode.rs b/src/uu/mknod/src/parsemode.rs index 2767cb30376..0ec80c6b413 100644 --- a/src/uu/mknod/src/parsemode.rs +++ b/src/uu/mknod/src/parsemode.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (path) osrelease use libc::{mode_t, S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR}; diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 9c0860d922e..f99136810d1 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Sunrin SHIMURA -// Collaborator: Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 03d3881b1a8..6f64157890e 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Orvar Segerström -// (c) Sokovikov Evgeniy -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. @@ -364,7 +361,7 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UR None }; - for sourcepath in files.iter() { + for sourcepath in files { if let Some(ref pb) = count_progress { pb.set_message(sourcepath.to_string_lossy().to_string()); } diff --git a/src/uu/nl/src/helper.rs b/src/uu/nl/src/helper.rs index 39d13d565b8..fe550e6a063 100644 --- a/src/uu/nl/src/helper.rs +++ b/src/uu/nl/src/helper.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (ToDO) conv use crate::options; diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 115b4efa95e..5bb1eb9e4c6 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -344,7 +344,10 @@ fn nl(reader: &mut BufReader, settings: &Settings) -> UResult<()> { line ); // update line number for the potential next line - line_no += settings.line_increment; + match line_no.checked_add(settings.line_increment) { + Some(new_line_no) => line_no = new_line_no, + None => return Err(USimpleError::new(1, "line number overflow")), + } } else { let spaces = " ".repeat(settings.number_width + 1); println!("{spaces}{line}"); diff --git a/src/uu/numfmt/src/format.rs b/src/uu/numfmt/src/format.rs index eb75f7554fd..08bb0c2e774 100644 --- a/src/uu/numfmt/src/format.rs +++ b/src/uu/numfmt/src/format.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore powf use uucore::display::Quotable; diff --git a/src/uu/numfmt/src/options.rs b/src/uu/numfmt/src/options.rs index bef4a8ce308..07b364f18d8 100644 --- a/src/uu/numfmt/src/options.rs +++ b/src/uu/numfmt/src/options.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::str::FromStr; use crate::units::Unit; diff --git a/src/uu/numfmt/src/units.rs b/src/uu/numfmt/src/units.rs index 08c7e4d3bdd..585bae46141 100644 --- a/src/uu/numfmt/src/units.rs +++ b/src/uu/numfmt/src/units.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::fmt; pub const SI_BASES: [f64; 10] = [1., 1e3, 1e6, 1e9, 1e12, 1e15, 1e18, 1e21, 1e24, 1e27]; diff --git a/src/uu/od/src/byteorder_io.rs b/src/uu/od/src/byteorder_io.rs index c22097da2c5..545016ff358 100644 --- a/src/uu/od/src/byteorder_io.rs +++ b/src/uu/od/src/byteorder_io.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (ToDO) byteorder // workaround until https://github.com/BurntSushi/byteorder/issues/41 has been fixed diff --git a/src/uu/od/src/formatteriteminfo.rs b/src/uu/od/src/formatteriteminfo.rs index 00ee2ee206c..9e3c2e83600 100644 --- a/src/uu/od/src/formatteriteminfo.rs +++ b/src/uu/od/src/formatteriteminfo.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (ToDO) formatteriteminfo use std::fmt; diff --git a/src/uu/od/src/inputdecoder.rs b/src/uu/od/src/inputdecoder.rs index 318571cf325..6f08eba124e 100644 --- a/src/uu/od/src/inputdecoder.rs +++ b/src/uu/od/src/inputdecoder.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use half::f16; use std::io; diff --git a/src/uu/od/src/inputoffset.rs b/src/uu/od/src/inputoffset.rs index ddaf747f1d5..a196000551f 100644 --- a/src/uu/od/src/inputoffset.rs +++ b/src/uu/od/src/inputoffset.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum Radix { Decimal, diff --git a/src/uu/od/src/mockstream.rs b/src/uu/od/src/mockstream.rs index a1ce0dd6895..925d52f7e58 100644 --- a/src/uu/od/src/mockstream.rs +++ b/src/uu/od/src/mockstream.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // https://github.com/lazy-bitfield/rust-mockstream/pull/2 use std::io::{Cursor, Error, ErrorKind, Read, Result}; diff --git a/src/uu/od/src/multifilereader.rs b/src/uu/od/src/multifilereader.rs index 38e19258872..f7575e975de 100644 --- a/src/uu/od/src/multifilereader.rs +++ b/src/uu/od/src/multifilereader.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (ToDO) multifile curr fnames fname xfrd fillloop mockstream use std::fs::File; diff --git a/src/uu/od/src/output_info.rs b/src/uu/od/src/output_info.rs index 211574a61a6..96c01f906ed 100644 --- a/src/uu/od/src/output_info.rs +++ b/src/uu/od/src/output_info.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore formatteriteminfo blocksize thisblock use std::cmp; diff --git a/src/uu/od/src/parse_formats.rs b/src/uu/od/src/parse_formats.rs index c414abebe8e..2bb876d2b4b 100644 --- a/src/uu/od/src/parse_formats.rs +++ b/src/uu/od/src/parse_formats.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore formatteriteminfo docopt fvox fvoxw vals acdx use uucore::display::Quotable; diff --git a/src/uu/od/src/parse_inputs.rs b/src/uu/od/src/parse_inputs.rs index 3093843d4c6..74dc5a13a83 100644 --- a/src/uu/od/src/parse_inputs.rs +++ b/src/uu/od/src/parse_inputs.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use super::options; use clap::ArgMatches; diff --git a/src/uu/od/src/parse_nrofbytes.rs b/src/uu/od/src/parse_nrofbytes.rs index 7d3bca03db9..a5c81f68ba9 100644 --- a/src/uu/od/src/parse_nrofbytes.rs +++ b/src/uu/od/src/parse_nrofbytes.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use uucore::parse_size::{parse_size, ParseSizeError}; pub fn parse_number_of_bytes(s: &str) -> Result { diff --git a/src/uu/od/src/partialreader.rs b/src/uu/od/src/partialreader.rs index 8b51d8dee73..24918f5cfd8 100644 --- a/src/uu/od/src/partialreader.rs +++ b/src/uu/od/src/partialreader.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore mockstream abcdefgh bcdefgh use std::cmp; diff --git a/src/uu/od/src/peekreader.rs b/src/uu/od/src/peekreader.rs index 45cd554d084..239faab92ee 100644 --- a/src/uu/od/src/peekreader.rs +++ b/src/uu/od/src/peekreader.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (ToDO) tempbuffer abcdefgh abcdefghij //! Contains the trait `PeekRead` and type `PeekReader` implementing it. diff --git a/src/uu/od/src/prn_char.rs b/src/uu/od/src/prn_char.rs index 7ae6f084c36..db12d9d4fc4 100644 --- a/src/uu/od/src/prn_char.rs +++ b/src/uu/od/src/prn_char.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::str::from_utf8; use crate::formatteriteminfo::{FormatWriter, FormatterItemInfo}; @@ -82,7 +86,7 @@ pub fn format_ascii_dump(bytes: &[u8]) -> String { let mut result = String::new(); result.push('>'); - for c in bytes.iter() { + for c in bytes { if *c >= 0x20 && *c <= 0x7e { result.push_str(C_CHARS[*c as usize]); } else { diff --git a/src/uu/od/src/prn_float.rs b/src/uu/od/src/prn_float.rs index 49627557406..af632d66b24 100644 --- a/src/uu/od/src/prn_float.rs +++ b/src/uu/od/src/prn_float.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use half::f16; use std::f32; use std::f64; diff --git a/src/uu/od/src/prn_int.rs b/src/uu/od/src/prn_int.rs index 0946824c14c..c214b7525eb 100644 --- a/src/uu/od/src/prn_int.rs +++ b/src/uu/od/src/prn_int.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::formatteriteminfo::*; /// format string to print octal using `int_writer_unsigned` diff --git a/src/uu/paste/src/paste.rs b/src/uu/paste/src/paste.rs index 6e52727f7ce..45ba2d8dc40 100644 --- a/src/uu/paste/src/paste.rs +++ b/src/uu/paste/src/paste.rs @@ -8,11 +8,11 @@ // spell-checker:ignore (ToDO) delim use clap::{crate_version, Arg, ArgAction, Command}; -use std::fmt::Display; use std::fs::File; use std::io::{stdin, stdout, BufRead, BufReader, Read, Write}; use std::path::Path; use uucore::error::{FromIo, UResult, USimpleError}; +use uucore::line_ending::LineEnding; use uucore::{format_usage, help_about, help_usage}; const ABOUT: &str = help_about!("paste.md"); @@ -25,22 +25,6 @@ mod options { pub const ZERO_TERMINATED: &str = "zero-terminated"; } -#[repr(u8)] -#[derive(Clone, Copy)] -enum LineEnding { - Newline = b'\n', - Nul = 0, -} - -impl Display for LineEnding { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::Newline => writeln!(f), - Self::Nul => write!(f, "\0"), - } - } -} - // Wraps BufReader and stdin fn read_until( reader: Option<&mut BufReader>, @@ -64,11 +48,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .unwrap() .map(|s| s.to_owned()) .collect(); - let line_ending = if matches.get_flag(options::ZERO_TERMINATED) { - LineEnding::Nul - } else { - LineEnding::Newline - }; + let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO_TERMINATED)); paste(files, serial, delimiters, line_ending) } diff --git a/src/uu/pinky/src/pinky.rs b/src/uu/pinky/src/pinky.rs index 172a9e13803..8ac8f6c8446 100644 --- a/src/uu/pinky/src/pinky.rs +++ b/src/uu/pinky/src/pinky.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/printf/src/mod.rs b/src/uu/printf/src/mod.rs index 26710c101cb..759b823ccda 100644 --- a/src/uu/printf/src/mod.rs +++ b/src/uu/printf/src/mod.rs @@ -1 +1,5 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. mod cli; diff --git a/src/uu/printf/src/printf.rs b/src/uu/printf/src/printf.rs index bf79369ccab..a6205f7cb39 100644 --- a/src/uu/printf/src/printf.rs +++ b/src/uu/printf/src/printf.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. #![allow(dead_code)] // spell-checker:ignore (change!) each's // spell-checker:ignore (ToDO) LONGHELP FORMATSTRING templating parameterizing formatstr diff --git a/src/uu/readlink/src/readlink.rs b/src/uu/readlink/src/readlink.rs index e247c614695..7e9f7be15e6 100644 --- a/src/uu/readlink/src/readlink.rs +++ b/src/uu/readlink/src/readlink.rs @@ -14,6 +14,7 @@ use std::path::{Path, PathBuf}; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; use uucore::fs::{canonicalize, MissingHandling, ResolveMode}; +use uucore::line_ending::LineEnding; use uucore::{format_usage, help_about, help_usage, show_error}; const ABOUT: &str = help_about!("readlink.md"); @@ -67,6 +68,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { show_error!("ignoring --no-newline with multiple arguments"); no_trailing_delimiter = false; } + let line_ending = if no_trailing_delimiter { + None + } else { + Some(LineEnding::from_zero_flag(use_zero)) + }; for f in &files { let p = PathBuf::from(f); @@ -77,7 +83,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { }; match path_result { Ok(path) => { - show(&path, no_trailing_delimiter, use_zero).map_err_context(String::new)?; + show(&path, line_ending).map_err_context(String::new)?; } Err(err) => { if verbose { @@ -173,14 +179,11 @@ pub fn uu_app() -> Command { ) } -fn show(path: &Path, no_trailing_delimiter: bool, use_zero: bool) -> std::io::Result<()> { +fn show(path: &Path, line_ending: Option) -> std::io::Result<()> { let path = path.to_str().unwrap(); - if no_trailing_delimiter { - print!("{path}"); - } else if use_zero { - print!("{path}\0"); - } else { - println!("{path}"); + print!("{path}"); + if let Some(line_ending) = line_ending { + print!("{line_ending}"); } stdout().flush() } diff --git a/src/uu/realpath/src/realpath.rs b/src/uu/realpath/src/realpath.rs index cb7a09a41f3..e2b7d7557c8 100644 --- a/src/uu/realpath/src/realpath.rs +++ b/src/uu/realpath/src/realpath.rs @@ -21,6 +21,7 @@ use uucore::{ format_usage, fs::{canonicalize, MissingHandling, ResolveMode}, help_about, help_usage, + line_ending::LineEnding, }; use uucore::{error::UClapError, show, show_if_err}; @@ -52,7 +53,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .collect(); let strip = matches.get_flag(OPT_STRIP); - let zero = matches.get_flag(OPT_ZERO); + let line_ending = LineEnding::from_zero_flag(matches.get_flag(OPT_ZERO)); let quiet = matches.get_flag(OPT_QUIET); let logical = matches.get_flag(OPT_LOGICAL); let can_mode = if matches.get_flag(OPT_CANONICALIZE_EXISTING) { @@ -73,7 +74,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { for path in &paths { let result = resolve_path( path, - zero, + line_ending, resolve_mode, can_mode, relative_to.as_deref(), @@ -249,19 +250,18 @@ fn canonicalize_relative( /// symbolic links. fn resolve_path( p: &Path, - zero: bool, + line_ending: LineEnding, resolve: ResolveMode, can_mode: MissingHandling, relative_to: Option<&Path>, relative_base: Option<&Path>, ) -> std::io::Result<()> { let abs = canonicalize(p, can_mode, resolve)?; - let line_ending = if zero { b'\0' } else { b'\n' }; let abs = process_relative(abs, relative_base, relative_to); print_verbatim(abs)?; - stdout().write_all(&[line_ending])?; + stdout().write_all(&[line_ending.into()])?; Ok(()) } diff --git a/src/uu/runcon/src/errors.rs b/src/uu/runcon/src/errors.rs index b96cc87435e..5b628294060 100644 --- a/src/uu/runcon/src/errors.rs +++ b/src/uu/runcon/src/errors.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::ffi::OsString; use std::fmt::{Display, Formatter, Write}; use std::io; diff --git a/src/uu/runcon/src/runcon.rs b/src/uu/runcon/src/runcon.rs index a22bff47020..a802542b2a2 100644 --- a/src/uu/runcon/src/runcon.rs +++ b/src/uu/runcon/src/runcon.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (vars) RFILE use clap::builder::ValueParser; diff --git a/src/uu/seq/src/extendedbigdecimal.rs b/src/uu/seq/src/extendedbigdecimal.rs index 253fadfd5a3..388046ba368 100644 --- a/src/uu/seq/src/extendedbigdecimal.rs +++ b/src/uu/seq/src/extendedbigdecimal.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore bigdecimal extendedbigdecimal extendedbigint //! An arbitrary precision float that can also represent infinity, NaN, etc. //! diff --git a/src/uu/seq/src/extendedbigint.rs b/src/uu/seq/src/extendedbigint.rs index 46153bb7d4d..6828fba2df2 100644 --- a/src/uu/seq/src/extendedbigint.rs +++ b/src/uu/seq/src/extendedbigint.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore bigint extendedbigint extendedbigdecimal //! An arbitrary precision integer that can also represent infinity, NaN, etc. //! diff --git a/src/uu/seq/src/number.rs b/src/uu/seq/src/number.rs index 1bab62b143a..85bc327ff46 100644 --- a/src/uu/seq/src/number.rs +++ b/src/uu/seq/src/number.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore extendedbigdecimal extendedbigint //! A type to represent the possible start, increment, and end values for seq. //! diff --git a/src/uu/seq/src/numberparse.rs b/src/uu/seq/src/numberparse.rs index 23d94ea2b79..b22cf90c05c 100644 --- a/src/uu/seq/src/numberparse.rs +++ b/src/uu/seq/src/numberparse.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore extendedbigdecimal extendedbigint bigdecimal numberparse //! Parsing numbers for use in `seq`. //! diff --git a/src/uu/shuf/src/rand_read_adapter.rs b/src/uu/shuf/src/rand_read_adapter.rs index 9cf0ee8a4f5..728bc0cfbbd 100644 --- a/src/uu/shuf/src/rand_read_adapter.rs +++ b/src/uu/shuf/src/rand_read_adapter.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // Copyright 2018 Developers of the Rand project. // Copyright 2013 The Rust Project Developers. // diff --git a/src/uu/sort/src/check.rs b/src/uu/sort/src/check.rs index 3f02a4c3153..cc687aafcd7 100644 --- a/src/uu/sort/src/check.rs +++ b/src/uu/sort/src/check.rs @@ -54,7 +54,7 @@ pub fn check(path: &OsStr, settings: &GlobalSettings) -> UResult<()> { let mut prev_chunk: Option = None; let mut line_idx = 0; - for chunk in loaded_receiver.iter() { + for chunk in loaded_receiver { line_idx += 1; if let Some(prev_chunk) = prev_chunk.take() { // Check if the first element of the new chunk is greater than the last @@ -107,7 +107,7 @@ fn reader( settings: &GlobalSettings, ) -> UResult<()> { let mut carry_over = vec![]; - for recycled_chunk in receiver.iter() { + for recycled_chunk in receiver { let should_continue = chunks::read( sender, recycled_chunk, @@ -115,11 +115,7 @@ fn reader( &mut carry_over, &mut file, &mut iter::empty(), - if settings.zero_terminated { - b'\0' - } else { - b'\n' - }, + settings.line_ending.into(), settings, )?; if !should_continue { diff --git a/src/uu/sort/src/ext_sort.rs b/src/uu/sort/src/ext_sort.rs index 27cb12d0bb0..a8f4b2590a3 100644 --- a/src/uu/sort/src/ext_sort.rs +++ b/src/uu/sort/src/ext_sort.rs @@ -84,11 +84,7 @@ fn reader_writer< output: Output, tmp_dir: &mut TmpDirWrapper, ) -> UResult<()> { - let separator = if settings.zero_terminated { - b'\0' - } else { - b'\n' - }; + let separator = settings.line_ending.into(); // Heuristically chosen: Dividing by 10 seems to keep our memory usage roughly // around settings.buffer_size as a whole. diff --git a/src/uu/sort/src/merge.rs b/src/uu/sort/src/merge.rs index 7c682d88f11..c0457ffa4dc 100644 --- a/src/uu/sort/src/merge.rs +++ b/src/uu/sort/src/merge.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. //! Merge already sorted files. //! //! We achieve performance by splitting the tasks of sorting and writing, and reading and parsing between two threads. @@ -169,11 +173,7 @@ fn merge_without_limit>>( &request_receiver, &mut reader_files, &settings, - if settings.zero_terminated { - b'\0' - } else { - b'\n' - }, + settings.line_ending.into(), ) } }); @@ -215,7 +215,7 @@ fn reader( settings: &GlobalSettings, separator: u8, ) -> UResult<()> { - for (file_idx, recycled_chunk) in recycled_receiver.iter() { + for (file_idx, recycled_chunk) in recycled_receiver { if let Some(ReaderFile { file, sender, diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 80c2275e969..b40eb05c171 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -45,6 +45,7 @@ use std::str::Utf8Error; use unicode_width::UnicodeWidthStr; use uucore::display::Quotable; use uucore::error::{set_exit_code, strip_errno, UError, UResult, USimpleError, UUsageError}; +use uucore::line_ending::LineEnding; use uucore::parse_size::{ParseSizeError, Parser}; use uucore::version_cmp::version_cmp; use uucore::{format_usage, help_about, help_section, help_usage}; @@ -306,7 +307,7 @@ pub struct GlobalSettings { selectors: Vec, separator: Option, threads: String, - zero_terminated: bool, + line_ending: LineEnding, buffer_size: usize, compress_prog: Option, merge_batch_size: usize, @@ -383,7 +384,7 @@ impl Default for GlobalSettings { selectors: vec![], separator: None, threads: String::new(), - zero_terminated: false, + line_ending: LineEnding::Newline, buffer_size: DEFAULT_BUF_SIZE, compress_prog: None, merge_batch_size: 32, @@ -526,14 +527,11 @@ impl<'a> Line<'a> { } fn print(&self, writer: &mut impl Write, settings: &GlobalSettings) { - if settings.zero_terminated && !settings.debug { - writer.write_all(self.line.as_bytes()).unwrap(); - writer.write_all(b"\0").unwrap(); - } else if !settings.debug { - writer.write_all(self.line.as_bytes()).unwrap(); - writer.write_all(b"\n").unwrap(); - } else { + if settings.debug { self.print_debug(settings, writer).unwrap(); + } else { + writer.write_all(self.line.as_bytes()).unwrap(); + writer.write_all(&[settings.line_ending.into()]).unwrap(); } } @@ -1169,7 +1167,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { })?; } - settings.zero_terminated = matches.get_flag(options::ZERO_TERMINATED); + settings.line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO_TERMINATED)); settings.merge = matches.get_flag(options::MERGE); settings.check = matches.contains_id(options::check::CHECK); diff --git a/src/uu/sort/src/tmp_dir.rs b/src/uu/sort/src/tmp_dir.rs index ff14442b54c..14e17a0d64a 100644 --- a/src/uu/sort/src/tmp_dir.rs +++ b/src/uu/sort/src/tmp_dir.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::{ fs::File, path::{Path, PathBuf}, diff --git a/src/uu/split/src/platform/mod.rs b/src/uu/split/src/platform/mod.rs index cf5d8d3842c..5afc43eeb7f 100644 --- a/src/uu/split/src/platform/mod.rs +++ b/src/uu/split/src/platform/mod.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. #[cfg(unix)] pub use self::unix::instantiate_current_writer; #[cfg(unix)] diff --git a/src/uu/split/src/platform/unix.rs b/src/uu/split/src/platform/unix.rs index fedd66dc856..f4adb818834 100644 --- a/src/uu/split/src/platform/unix.rs +++ b/src/uu/split/src/platform/unix.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::env; use std::io::Write; use std::io::{BufWriter, Error, ErrorKind, Result}; diff --git a/src/uu/split/src/platform/windows.rs b/src/uu/split/src/platform/windows.rs index a2711fd3a1f..8b90789896f 100644 --- a/src/uu/split/src/platform/windows.rs +++ b/src/uu/split/src/platform/windows.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::io::Write; use std::io::{BufWriter, Error, ErrorKind, Result}; use std::path::Path; diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 9ffa064b85e..b3c9dc513c2 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. diff --git a/src/uu/stdbuf/build.rs b/src/uu/stdbuf/build.rs index a8472243a0d..7483aeacfef 100644 --- a/src/uu/stdbuf/build.rs +++ b/src/uu/stdbuf/build.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (ToDO) dylib libstdbuf deps liblibstdbuf use std::env; diff --git a/src/uu/stdbuf/src/libstdbuf/build.rs b/src/uu/stdbuf/src/libstdbuf/build.rs index fc8ddeac897..6dcd6a86912 100644 --- a/src/uu/stdbuf/src/libstdbuf/build.rs +++ b/src/uu/stdbuf/src/libstdbuf/build.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (ToDO) libstdbuf use cpp_build::Config; diff --git a/src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs b/src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs index ec99c386458..a29d01b78f3 100644 --- a/src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs +++ b/src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (ToDO) IOFBF IOLBF IONBF cstdio setvbuf use cpp::cpp; diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index e02dd28bc80..85dddbddd59 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -130,7 +130,7 @@ fn set_command_env(command: &mut process::Command, buffer_name: &str, buffer_typ } } -fn get_preload_env(tmp_dir: &mut TempDir) -> io::Result<(String, PathBuf)> { +fn get_preload_env(tmp_dir: &TempDir) -> io::Result<(String, PathBuf)> { let (preload, extension) = preload_strings(); let inject_path = tmp_dir.path().join("libstdbuf").with_extension(extension); @@ -152,8 +152,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let mut command = process::Command::new(command_values.next().unwrap()); let command_params: Vec<&str> = command_values.map(|s| s.as_ref()).collect(); - let mut tmp_dir = tempdir().unwrap(); - let (preload_env, libstdbuf) = get_preload_env(&mut tmp_dir).map_err_context(String::new)?; + let tmp_dir = tempdir().unwrap(); + let (preload_env, libstdbuf) = get_preload_env(&tmp_dir).map_err_context(String::new)?; command.env(preload_env, libstdbuf); set_command_env(&mut command, "_STDBUF_I", &options.stdin); set_command_env(&mut command, "_STDBUF_O", &options.stdout); diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index e9b5a8e07ae..6a17a630d47 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -33,7 +33,7 @@ fn bsd_sum(mut reader: Box) -> (usize, u16) { match reader.read(&mut buf) { Ok(n) if n != 0 => { bytes_read += n; - for &byte in buf[..n].iter() { + for &byte in &buf[..n] { checksum = checksum.rotate_right(1); checksum = checksum.wrapping_add(u16::from(byte)); } @@ -56,7 +56,7 @@ fn sysv_sum(mut reader: Box) -> (usize, u16) { match reader.read(&mut buf) { Ok(n) if n != 0 => { bytes_read += n; - for &byte in buf[..n].iter() { + for &byte in &buf[..n] { ret = ret.wrapping_add(u32::from(byte)); } } diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index 821ad639b56..e135fbe7f58 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!("error opening {}", f.quote()))?; + e.map_err_context(|| format!("error opening {}", f.quote()))?; } } } diff --git a/src/uu/tail/src/chunks.rs b/src/uu/tail/src/chunks.rs index 3aa380e20e0..7a1e5bc340b 100644 --- a/src/uu/tail/src/chunks.rs +++ b/src/uu/tail/src/chunks.rs @@ -495,7 +495,7 @@ impl LinesChunk { fn calculate_bytes_offset_from(&self, offset: usize) -> usize { let mut lines_offset = offset; let mut bytes_offset = 0; - for byte in self.get_buffer().iter() { + for byte in self.get_buffer() { if lines_offset == 0 { break; } diff --git a/src/uu/test/src/error.rs b/src/uu/test/src/error.rs index ced4b216af0..48238fa1356 100644 --- a/src/uu/test/src/error.rs +++ b/src/uu/test/src/error.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. /// Represents an error encountered while parsing a test expression #[derive(Debug)] pub enum ParseError { diff --git a/src/uu/test/src/parser.rs b/src/uu/test/src/parser.rs index db90098a104..2b847fa1514 100644 --- a/src/uu/test/src/parser.rs +++ b/src/uu/test/src/parser.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Daniel Rocco -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/test/src/test.rs b/src/uu/test/src/test.rs index b0a8fc61312..7e778f9b5e0 100644 --- a/src/uu/test/src/test.rs +++ b/src/uu/test/src/test.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) mahkoh (ju.orth [at] gmail [dot] com) -// (c) Daniel Rocco -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index baa28890c05..135d119bd5e 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Nick Platt -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. diff --git a/src/uu/uname/src/uname.rs b/src/uu/uname/src/uname.rs index 8b867923454..73ab07a6341 100644 --- a/src/uu/uname/src/uname.rs +++ b/src/uu/uname/src/uname.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Joao Oliveira -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/wc/src/count_fast.rs b/src/uu/wc/src/count_fast.rs index d151c9c9074..863625921bf 100644 --- a/src/uu/wc/src/count_fast.rs +++ b/src/uu/wc/src/count_fast.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::word_count::WordCount; use super::WordCountable; diff --git a/src/uu/wc/src/countable.rs b/src/uu/wc/src/countable.rs index b86b96fa2f1..64397446491 100644 --- a/src/uu/wc/src/countable.rs +++ b/src/uu/wc/src/countable.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. //! Traits and implementations for iterating over lines in a file-like object. //! //! This module provides a [`WordCountable`] trait and implementations diff --git a/src/uu/wc/src/utf8/mod.rs b/src/uu/wc/src/utf8/mod.rs index 31638e7589c..ea4f19392df 100644 --- a/src/uu/wc/src/utf8/mod.rs +++ b/src/uu/wc/src/utf8/mod.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore Sapin mod read; diff --git a/src/uu/wc/src/utf8/read.rs b/src/uu/wc/src/utf8/read.rs index 1b5bbbe7f76..4a92d85e688 100644 --- a/src/uu/wc/src/utf8/read.rs +++ b/src/uu/wc/src/utf8/read.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore bytestream use super::*; use std::error::Error; diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index 9fb8ca7a637..b79559b29c3 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -686,7 +686,7 @@ fn compute_number_width(inputs: &Inputs, settings: &Settings) -> usize { let mut minimum_width = 1; let mut total: u64 = 0; - for input in inputs.iter() { + for input in inputs { match input { Input::Stdin(_) => minimum_width = MINIMUM_WIDTH, Input::Path(path) => { diff --git a/src/uu/wc/src/word_count.rs b/src/uu/wc/src/word_count.rs index cf839175f96..3c18d692b2c 100644 --- a/src/uu/wc/src/word_count.rs +++ b/src/uu/wc/src/word_count.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::cmp::max; use std::ops::{Add, AddAssign}; diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index fbfff80d731..29929b13866 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uu/yes/src/splice.rs b/src/uu/yes/src/splice.rs index a0d41e06fa9..a95fc35af47 100644 --- a/src/uu/yes/src/splice.rs +++ b/src/uu/yes/src/splice.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. //! On Linux we can use vmsplice() to write data more efficiently. //! //! This does not always work. We're not allowed to splice to some targets, diff --git a/src/uucore/src/lib/features.rs b/src/uucore/src/lib/features.rs index f8a8d2d10df..8abccee2628 100644 --- a/src/uucore/src/lib/features.rs +++ b/src/uucore/src/lib/features.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // features ~ feature-gated modules (core/bundler file) #[cfg(feature = "encoding")] diff --git a/src/uucore/src/lib/features/encoding.rs b/src/uucore/src/lib/features/encoding.rs index a42044eea78..14fdbb38ee7 100644 --- a/src/uucore/src/lib/features/encoding.rs +++ b/src/uucore/src/lib/features/encoding.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uucore/src/lib/features/entries.rs b/src/uucore/src/lib/features/entries.rs index c0229aa3e96..c06c5116eba 100644 --- a/src/uucore/src/lib/features/entries.rs +++ b/src/uucore/src/lib/features/entries.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 5804a2235e2..3def63ad6b1 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Joseph Crail -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. @@ -845,7 +842,7 @@ mod tests { let path1 = temp_file.path(); let path2 = temp_file.path(); - assert_eq!(are_hardlinks_to_same_file(&path1, &path2), true); + assert!(are_hardlinks_to_same_file(&path1, &path2)); } #[cfg(unix)] @@ -860,7 +857,7 @@ mod tests { let path1 = temp_file1.path(); let path2 = temp_file2.path(); - assert_eq!(are_hardlinks_to_same_file(&path1, &path2), false); + assert!(!are_hardlinks_to_same_file(&path1, &path2)); } #[cfg(unix)] @@ -873,6 +870,6 @@ mod tests { let path2 = temp_file.path().with_extension("hardlink"); fs::hard_link(&path1, &path2).unwrap(); - assert_eq!(are_hardlinks_to_same_file(&path1, &path2), true); + assert!(are_hardlinks_to_same_file(&path1, &path2)); } } diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index 6f831fb9220..f526e7fde89 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -1,9 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jian Zeng -// (c) Fangxu Hu -// (c) Sylvestre Ledru -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. diff --git a/src/uucore/src/lib/features/memo.rs b/src/uucore/src/lib/features/memo.rs index 47d04f5b861..0603b01c51c 100644 --- a/src/uucore/src/lib/features/memo.rs +++ b/src/uucore/src/lib/features/memo.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. //! Main entry point for our implementation of printf. //! //! The [`printf`] and [`sprintf`] closely match the behavior of the diff --git a/src/uucore/src/lib/features/mode.rs b/src/uucore/src/lib/features/mode.rs index 9435e3201a6..cbaea71bf01 100644 --- a/src/uucore/src/lib/features/mode.rs +++ b/src/uucore/src/lib/features/mode.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Alex Lyon -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uucore/src/lib/features/pipes.rs b/src/uucore/src/lib/features/pipes.rs index a76322de8e8..75749f72148 100644 --- a/src/uucore/src/lib/features/pipes.rs +++ b/src/uucore/src/lib/features/pipes.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. /// Thin pipe-related wrappers around functions from the `nix` crate. use std::fs::File; #[cfg(any(target_os = "linux", target_os = "android"))] diff --git a/src/uucore/src/lib/features/process.rs b/src/uucore/src/lib/features/process.rs index 4a52f0fc4fa..8e7e4647980 100644 --- a/src/uucore/src/lib/features/process.rs +++ b/src/uucore/src/lib/features/process.rs @@ -1,8 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Maciej Dziardziel -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. diff --git a/src/uucore/src/lib/features/ringbuffer.rs b/src/uucore/src/lib/features/ringbuffer.rs index 08073fae084..d58c8c498b8 100644 --- a/src/uucore/src/lib/features/ringbuffer.rs +++ b/src/uucore/src/lib/features/ringbuffer.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. //! A fixed-size ring buffer. use std::collections::VecDeque; diff --git a/src/uucore/src/lib/features/signals.rs b/src/uucore/src/lib/features/signals.rs index c9f7295ee30..423eb19c95c 100644 --- a/src/uucore/src/lib/features/signals.rs +++ b/src/uucore/src/lib/features/signals.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Maciej Dziardziel -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. diff --git a/src/uucore/src/lib/features/sum.rs b/src/uucore/src/lib/features/sum.rs index c1cfaf5f84d..d4945421e49 100644 --- a/src/uucore/src/lib/features/sum.rs +++ b/src/uucore/src/lib/features/sum.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Yuan YangHao -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. diff --git a/src/uucore/src/lib/features/tokenize/mod.rs b/src/uucore/src/lib/features/tokenize/mod.rs index dfe44a0e56b..49611bbca5e 100644 --- a/src/uucore/src/lib/features/tokenize/mod.rs +++ b/src/uucore/src/lib/features/tokenize/mod.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. #[allow(clippy::module_inception)] mod num_format; pub mod sub; diff --git a/src/uucore/src/lib/features/tokenize/num_format/format_field.rs b/src/uucore/src/lib/features/tokenize/num_format/format_field.rs index 02998cde540..036ee286d25 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/format_field.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/format_field.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (vars) charf decf floatf intf scif strf Cninety //! Primitives used by Sub Tokenizer diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatter.rs b/src/uucore/src/lib/features/tokenize/num_format/formatter.rs index ed7d5a0f609..2a3fd1013eb 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatter.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatter.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. //! Primitives used by num_format and sub_modules. //! never dealt with above (e.g. Sub Tokenizer never uses these) diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/mod.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/mod.rs index 3df9f7129bc..f8b5da86c21 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/mod.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/mod.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (ToDO) arrnum arr_num mult basenum bufferval refd vals arrfloat conv intermed addl pub fn arrnum_int_mult(arr_num: &[u8], basenum: u8, base_ten_int_fact: u8) -> Vec { diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/tests.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/tests.rs index 903a3faf142..bf3747e1881 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/tests.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/tests.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (ToDO) arrnum mult #[cfg(test)] diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/cninetyninehexfloatf.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/cninetyninehexfloatf.rs index a5c51153efd..91a854f261e 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatters/cninetyninehexfloatf.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/cninetyninehexfloatf.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (vars) charf decf floatf intf scif strf Cninety // spell-checker:ignore (ToDO) arrnum diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/decf.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/decf.rs index 2ee53882e5d..35b981b4fba 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatters/decf.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/decf.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (vars) charf decf floatf intf scif strf Cninety //! formatter for %g %G decimal subs diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/float_common.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/float_common.rs index e0a29217c4a..1cf25b32f1e 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatters/float_common.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/float_common.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (vars) charf decf floatf intf scif strf Cninety // spell-checker:ignore (ToDO) arrnum diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/floatf.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/floatf.rs index cca2750dc55..59f2cb4085e 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatters/floatf.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/floatf.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (vars) charf decf floatf intf scif strf Cninety // spell-checker:ignore (ToDO) arrnum diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/intf.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/intf.rs index 0f6e78de6f6..11070113c26 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatters/intf.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/intf.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (vars) charf decf floatf intf scif strf Cninety // spell-checker:ignore (ToDO) arrnum diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/mod.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/mod.rs index e232300718b..95908917153 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatters/mod.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/mod.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (vars) charf cninetyninehexfloatf decf floatf intf scif strf Cninety mod base_conv; diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/scif.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/scif.rs index c871dc4e552..a0dfa86c1c1 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatters/scif.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/scif.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (vars) charf cninetyninehexfloatf decf floatf intf scif strf Cninety //! formatter for %e %E scientific notation subs diff --git a/src/uucore/src/lib/features/tokenize/num_format/mod.rs b/src/uucore/src/lib/features/tokenize/num_format/mod.rs index d40cf92deff..d2ce686ff37 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/mod.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/mod.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. pub mod format_field; mod formatter; mod formatters; diff --git a/src/uucore/src/lib/features/tokenize/num_format/num_format.rs b/src/uucore/src/lib/features/tokenize/num_format/num_format.rs index c9b1178b6ac..e9b676a8078 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/num_format.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/num_format.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (vars) charf cninetyninehexfloatf decf floatf intf scif strf Cninety //! handles creating printed output for numeric substitutions diff --git a/src/uucore/src/lib/features/tokenize/sub.rs b/src/uucore/src/lib/features/tokenize/sub.rs index 5bdb24dc633..4651dc8d859 100644 --- a/src/uucore/src/lib/features/tokenize/sub.rs +++ b/src/uucore/src/lib/features/tokenize/sub.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (vars) charf decf floatf intf scif strf Cninety //! Sub is a token that represents a diff --git a/src/uucore/src/lib/features/tokenize/token.rs b/src/uucore/src/lib/features/tokenize/token.rs index b522c99a4e0..c4f7bd6accc 100644 --- a/src/uucore/src/lib/features/tokenize/token.rs +++ b/src/uucore/src/lib/features/tokenize/token.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. //! Traits and enums dealing with Tokenization of printf Format String use std::io::Write; use std::iter::Peekable; diff --git a/src/uucore/src/lib/features/tokenize/unescaped_text.rs b/src/uucore/src/lib/features/tokenize/unescaped_text.rs index 29c657ed863..8ec6fd57618 100644 --- a/src/uucore/src/lib/features/tokenize/unescaped_text.rs +++ b/src/uucore/src/lib/features/tokenize/unescaped_text.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. //! UnescapedText is a tokenizer impl //! for tokenizing character literals, //! and escaped character literals (of allowed escapes), diff --git a/src/uucore/src/lib/features/utmpx.rs b/src/uucore/src/lib/features/utmpx.rs index 35c5ac5b02e..1b6ecbcf5c8 100644 --- a/src/uucore/src/lib/features/utmpx.rs +++ b/src/uucore/src/lib/features/utmpx.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. // diff --git a/src/uucore/src/lib/features/wide.rs b/src/uucore/src/lib/features/wide.rs index 6b9368f5000..68341cd6829 100644 --- a/src/uucore/src/lib/features/wide.rs +++ b/src/uucore/src/lib/features/wide.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Peter Atashian -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 02724e1bfcd..1d97522c7ec 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // library ~ (core/bundler file) // Copyright (C) ~ Alex Lyon @@ -22,6 +26,7 @@ pub use uucore_procs::*; pub use crate::mods::backup_control; pub use crate::mods::display; pub use crate::mods::error; +pub use crate::mods::line_ending; pub use crate::mods::os; pub use crate::mods::panic; pub use crate::mods::quoting_style; diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index cc8bdafd8ad..d1893dd9aae 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -36,8 +36,6 @@ use std::sync::atomic::AtomicBool; // This file is part of the uutils coreutils package. // -// (c) Alex Lyon -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uucore/src/lib/mods.rs b/src/uucore/src/lib/mods.rs index 71d288c69a5..cb66c004116 100644 --- a/src/uucore/src/lib/mods.rs +++ b/src/uucore/src/lib/mods.rs @@ -1,8 +1,13 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // mods ~ cross-platforms modules (core/bundler file) pub mod backup_control; pub mod display; pub mod error; +pub mod line_ending; pub mod os; pub mod panic; pub mod ranges; diff --git a/src/uucore/src/lib/mods/backup_control.rs b/src/uucore/src/lib/mods/backup_control.rs index 9998c7560d7..86c7cd72b1d 100644 --- a/src/uucore/src/lib/mods/backup_control.rs +++ b/src/uucore/src/lib/mods/backup_control.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. //! Implement GNU-style backup functionality. //! //! This module implements the backup functionality as described in the [GNU diff --git a/src/uucore/src/lib/mods/display.rs b/src/uucore/src/lib/mods/display.rs index 95288973a28..db92c488727 100644 --- a/src/uucore/src/lib/mods/display.rs +++ b/src/uucore/src/lib/mods/display.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. /// Utilities for printing paths, with special attention paid to special /// characters and invalid unicode. /// diff --git a/src/uucore/src/lib/mods/error.rs b/src/uucore/src/lib/mods/error.rs index f0f62569d82..82644ae8a50 100644 --- a/src/uucore/src/lib/mods/error.rs +++ b/src/uucore/src/lib/mods/error.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // TODO fix broken links #![allow(rustdoc::broken_intra_doc_links)] //! All utils return exit with an exit code. Usually, the following scheme is used: diff --git a/src/uucore/src/lib/mods/line_ending.rs b/src/uucore/src/lib/mods/line_ending.rs new file mode 100644 index 00000000000..6fe608e7d9e --- /dev/null +++ b/src/uucore/src/lib/mods/line_ending.rs @@ -0,0 +1,53 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. +//! Provides consistent newline/zero terminator handling for `-z`/`--zero` flags. +//! +//! See the [`LineEnding`] struct for more information. +use std::fmt::Display; + +/// Line ending of either `\n` or `\0` +/// +/// Used by various utilities that have the option to separate lines by nul +/// characters instead of `\n`. Usually, this is specified with the `-z` or +/// `--zero` flag. +/// +/// The [`Display`] implementation writes the character corresponding to the +/// variant to the formatter. +#[repr(u8)] +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub enum LineEnding { + #[default] + Newline = b'\n', + Nul = 0, +} + +impl Display for LineEnding { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Newline => writeln!(f), + Self::Nul => write!(f, "\0"), + } + } +} + +impl From for u8 { + fn from(line_ending: LineEnding) -> Self { + line_ending as Self + } +} + +impl LineEnding { + /// Create a [`LineEnding`] from a `-z`/`--zero` flag + /// + /// If `is_zero_terminated` is true, [`LineEnding::Nul`] is returned, + /// otherwise [`LineEnding::Newline`]. + pub fn from_zero_flag(is_zero_terminated: bool) -> Self { + if is_zero_terminated { + Self::Nul + } else { + Self::Newline + } + } +} diff --git a/src/uucore/src/lib/mods/os.rs b/src/uucore/src/lib/mods/os.rs index dd06f473906..55bf844b533 100644 --- a/src/uucore/src/lib/mods/os.rs +++ b/src/uucore/src/lib/mods/os.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. /// Test if the program is running under WSL // ref: @@ diff --git a/src/uucore/src/lib/mods/panic.rs b/src/uucore/src/lib/mods/panic.rs index 5a1e20d8090..f42b29581e9 100644 --- a/src/uucore/src/lib/mods/panic.rs +++ b/src/uucore/src/lib/mods/panic.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. //! Custom panic hooks that allow silencing certain types of errors. //! //! Use the [`mute_sigpipe_panic`] function to silence panics caused by diff --git a/src/uucore/src/lib/mods/quoting_style.rs b/src/uucore/src/lib/mods/quoting_style.rs index a6efb2898cd..1b9a76aae22 100644 --- a/src/uucore/src/lib/mods/quoting_style.rs +++ b/src/uucore/src/lib/mods/quoting_style.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::char::from_digit; use std::ffi::OsStr; diff --git a/src/uucore/src/lib/mods/ranges.rs b/src/uucore/src/lib/mods/ranges.rs index 76a61b9a687..29f40218363 100644 --- a/src/uucore/src/lib/mods/ranges.rs +++ b/src/uucore/src/lib/mods/ranges.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Rolf Morel -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uucore/src/lib/mods/update_control.rs b/src/uucore/src/lib/mods/update_control.rs index e46afd18522..bd429251452 100644 --- a/src/uucore/src/lib/mods/update_control.rs +++ b/src/uucore/src/lib/mods/update_control.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) John Shin -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uucore/src/lib/mods/version_cmp.rs b/src/uucore/src/lib/mods/version_cmp.rs index 828b7f2a668..d881a73a183 100644 --- a/src/uucore/src/lib/mods/version_cmp.rs +++ b/src/uucore/src/lib/mods/version_cmp.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::cmp::Ordering; /// Compares the non-digit parts of a version. diff --git a/src/uucore/src/lib/parser.rs b/src/uucore/src/lib/parser.rs index fc3e46b5c6c..a0de6c0d4ef 100644 --- a/src/uucore/src/lib/parser.rs +++ b/src/uucore/src/lib/parser.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. pub mod parse_glob; pub mod parse_size; pub mod parse_time; diff --git a/src/uucore/src/lib/parser/parse_glob.rs b/src/uucore/src/lib/parser/parse_glob.rs index a321d470b0d..9215dd7bf7d 100644 --- a/src/uucore/src/lib/parser/parse_glob.rs +++ b/src/uucore/src/lib/parser/parse_glob.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. //! Parsing a glob Pattern from a string. //! //! Use the [`from_str`] function to parse a [`Pattern`] from a string. diff --git a/src/uucore/src/lib/parser/parse_time.rs b/src/uucore/src/lib/parser/parse_time.rs index 1a7b66e9002..727ee28b1bf 100644 --- a/src/uucore/src/lib/parser/parse_time.rs +++ b/src/uucore/src/lib/parser/parse_time.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Alex Lyon -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. diff --git a/src/uucore/src/lib/parser/shortcut_value_parser.rs b/src/uucore/src/lib/parser/shortcut_value_parser.rs index 07ed49cb357..49bb2b62b71 100644 --- a/src/uucore/src/lib/parser/shortcut_value_parser.rs +++ b/src/uucore/src/lib/parser/shortcut_value_parser.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore abcdefgh use clap::{ builder::{PossibleValue, TypedValueParser}, diff --git a/src/uucore_procs/src/lib.rs b/src/uucore_procs/src/lib.rs index b78da782210..ef1ba87cf61 100644 --- a/src/uucore_procs/src/lib.rs +++ b/src/uucore_procs/src/lib.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // Copyright (C) ~ Roy Ivy III ; MIT license // spell-checker:ignore backticks uuhelp diff --git a/tests/benches/factor/benches/gcd.rs b/tests/benches/factor/benches/gcd.rs index a9d2a8c55e8..61545145f98 100644 --- a/tests/benches/factor/benches/gcd.rs +++ b/tests/benches/factor/benches/gcd.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use uu_factor::numeric; diff --git a/tests/benches/factor/benches/table.rs b/tests/benches/factor/benches/table.rs index 59e8db1f3bc..f666d72d510 100644 --- a/tests/benches/factor/benches/table.rs +++ b/tests/benches/factor/benches/table.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use array_init::array_init; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use uu_factor::{table::*, Factors}; diff --git a/tests/by-util/test_arch.rs b/tests/by-util/test_arch.rs index 603e1bc49e1..daf4e32f52b 100644 --- a/tests/by-util/test_arch.rs +++ b/tests/by-util/test_arch.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_base32.rs b/tests/by-util/test_base32.rs index 395c96c2c62..b8e72cb0415 100644 --- a/tests/by-util/test_base32.rs +++ b/tests/by-util/test_base32.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) Jian Zeng -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. // diff --git a/tests/by-util/test_base64.rs b/tests/by-util/test_base64.rs index 7cd44eefd14..b46507faeff 100644 --- a/tests/by-util/test_base64.rs +++ b/tests/by-util/test_base64.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_basename.rs b/tests/by-util/test_basename.rs index 88b0c71c8de..73b44ff7522 100644 --- a/tests/by-util/test_basename.rs +++ b/tests/by-util/test_basename.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (words) reallylongexecutable use crate::common::util::TestScenario; diff --git a/tests/by-util/test_basenc.rs b/tests/by-util/test_basenc.rs index 401c23d45a2..6c71b63f79c 100644 --- a/tests/by-util/test_basenc.rs +++ b/tests/by-util/test_basenc.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_cat.rs b/tests/by-util/test_cat.rs index c32828a838a..27f40356de5 100644 --- a/tests/by-util/test_cat.rs +++ b/tests/by-util/test_cat.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore NOFILE #[cfg(not(windows))] diff --git a/tests/by-util/test_chcon.rs b/tests/by-util/test_chcon.rs index bea5462b4ca..71405e451d0 100644 --- a/tests/by-util/test_chcon.rs +++ b/tests/by-util/test_chcon.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (jargon) xattributes #![cfg(feature = "feat_selinux")] diff --git a/tests/by-util/test_chgrp.rs b/tests/by-util/test_chgrp.rs index cf6c62ff7f8..07966b67b33 100644 --- a/tests/by-util/test_chgrp.rs +++ b/tests/by-util/test_chgrp.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (words) nosuchgroup groupname use crate::common::util::TestScenario; diff --git a/tests/by-util/test_chmod.rs b/tests/by-util/test_chmod.rs index 9e3c7d2da7f..be730a8c0ad 100644 --- a/tests/by-util/test_chmod.rs +++ b/tests/by-util/test_chmod.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::{AtPath, TestScenario, UCommand}; use once_cell::sync::Lazy; use std::fs::{metadata, set_permissions, OpenOptions, Permissions}; diff --git a/tests/by-util/test_chown.rs b/tests/by-util/test_chown.rs index 7a1a4a6bd7f..0a2e23c6d32 100644 --- a/tests/by-util/test_chown.rs +++ b/tests/by-util/test_chown.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (words) agroupthatdoesntexist auserthatdoesntexist cuuser groupname notexisting passgrp use crate::common::util::{is_ci, run_ucmd_as_root, CmdResult, TestScenario}; @@ -744,55 +748,7 @@ fn test_chown_file_notexisting() { } #[test] -fn test_chown_no_change_to_user_from_user() { - let scene = TestScenario::new(util_name!()); - let at = &scene.fixtures; - - let result = scene.cmd("whoami").run(); - if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") { - return; - } - let user_name = String::from(result.stdout_str().trim()); - assert!(!user_name.is_empty()); - - let file = "f"; - at.touch(file); - scene - .ucmd() - .arg("-v") - .arg("--from=42") - .arg("43") - .arg(file) - .succeeds() - .stdout_only(format!("ownership of '{file}' retained as {user_name}\n")); -} - -#[test] -fn test_chown_no_change_to_user_from_group() { - let scene = TestScenario::new(util_name!()); - let at = &scene.fixtures; - - let result = scene.cmd("whoami").run(); - if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") { - return; - } - let user_name = String::from(result.stdout_str().trim()); - assert!(!user_name.is_empty()); - - let file = "f"; - at.touch(file); - scene - .ucmd() - .arg("-v") - .arg("--from=:42") - .arg("43") - .arg(file) - .succeeds() - .stdout_only(format!("ownership of '{file}' retained as {user_name}\n")); -} - -#[test] -fn test_chown_no_change_to_user_from_user_group() { +fn test_chown_no_change_to_user() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; @@ -803,81 +759,22 @@ fn test_chown_no_change_to_user_from_user_group() { let user_name = String::from(result.stdout_str().trim()); assert!(!user_name.is_empty()); - let file = "f"; - at.touch(file); - scene - .ucmd() - .arg("-v") - .arg("--from=42:42") - .arg("43") - .arg(file) - .succeeds() - .stdout_only(format!("ownership of '{file}' retained as {user_name}\n")); -} - -#[test] -fn test_chown_no_change_to_group_from_user() { - let scene = TestScenario::new(util_name!()); - let at = &scene.fixtures; - - let result = scene.cmd("whoami").run(); - if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") { - return; - } - let user_name = String::from(result.stdout_str().trim()); - assert!(!user_name.is_empty()); - - let result = scene.cmd("id").arg("-ng").run(); - if skipping_test_is_okay(&result, "id: cannot find name for group ID") { - return; - } - let group_name = String::from(result.stdout_str().trim()); - assert!(!group_name.is_empty()); - - let file = "f"; - at.touch(file); - scene - .ucmd() - .arg("-v") - .arg("--from=42") - .arg(":43") - .arg(file) - .succeeds() - .stdout_only(format!("ownership of '{file}' retained as {group_name}\n")); -} - -#[test] -fn test_chown_no_change_to_group_from_group() { - let scene = TestScenario::new(util_name!()); - let at = &scene.fixtures; - - let result = scene.cmd("whoami").run(); - if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") { - return; + for (i, from) in ["42", ":42", "42:42"].iter().enumerate() { + let file = i.to_string(); + at.touch(&file); + scene + .ucmd() + .arg("-v") + .arg(format!("--from={from}")) + .arg("43") + .arg(&file) + .succeeds() + .stdout_only(format!("ownership of '{file}' retained as {user_name}\n")); } - let user_name = String::from(result.stdout_str().trim()); - assert!(!user_name.is_empty()); - let result = scene.cmd("id").arg("-ng").run(); - if skipping_test_is_okay(&result, "id: cannot find name for group ID") { - return; - } - let group_name = String::from(result.stdout_str().trim()); - assert!(!group_name.is_empty()); - - let file = "f"; - at.touch(file); - scene - .ucmd() - .arg("-v") - .arg("--from=:42") - .arg(":43") - .arg(file) - .succeeds() - .stdout_only(format!("ownership of '{file}' retained as {group_name}\n")); } #[test] -fn test_chown_no_change_to_group_from_user_group() { +fn test_chown_no_change_to_group() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; @@ -894,53 +791,22 @@ fn test_chown_no_change_to_group_from_user_group() { let group_name = String::from(result.stdout_str().trim()); assert!(!group_name.is_empty()); - let file = "f"; - at.touch(file); - scene - .ucmd() - .arg("-v") - .arg("--from=42:42") - .arg(":43") - .arg(file) - .succeeds() - .stdout_only(format!("ownership of '{file}' retained as {group_name}\n")); -} - -#[test] -fn test_chown_no_change_to_user_group_from_user() { - let scene = TestScenario::new(util_name!()); - let at = &scene.fixtures; - - let result = scene.cmd("whoami").run(); - if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") { - return; - } - let user_name = String::from(result.stdout_str().trim()); - assert!(!user_name.is_empty()); - - let result = scene.cmd("id").arg("-ng").run(); - if skipping_test_is_okay(&result, "id: cannot find name for group ID") { - return; + for (i, from) in ["42", ":42", "42:42"].iter().enumerate() { + let file = i.to_string(); + at.touch(&file); + scene + .ucmd() + .arg("-v") + .arg(format!("--from={from}")) + .arg(":43") + .arg(&file) + .succeeds() + .stdout_only(format!("ownership of '{file}' retained as {group_name}\n")); } - let group_name = String::from(result.stdout_str().trim()); - assert!(!group_name.is_empty()); - - let file = "f"; - at.touch(file); - scene - .ucmd() - .arg("-v") - .arg("--from=42") - .arg("43:43") - .arg(file) - .succeeds() - .stdout_only(format!( - "ownership of '{file}' retained as {user_name}:{group_name}\n" - )); } #[test] -fn test_chown_no_change_to_user_group_from_group() { +fn test_chown_no_change_to_user_group() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; @@ -957,48 +823,18 @@ fn test_chown_no_change_to_user_group_from_group() { let group_name = String::from(result.stdout_str().trim()); assert!(!group_name.is_empty()); - let file = "f"; - at.touch(file); - scene - .ucmd() - .arg("-v") - .arg("--from=:42") - .arg("43:43") - .arg(file) - .succeeds() - .stdout_only(format!( - "ownership of '{file}' retained as {user_name}:{group_name}\n" - )); -} - -#[test] -fn test_chown_no_change_to_user_group_from_user_group() { - let scene = TestScenario::new(util_name!()); - let at = &scene.fixtures; - - let result = scene.cmd("whoami").run(); - if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") { - return; - } - let user_name = String::from(result.stdout_str().trim()); - assert!(!user_name.is_empty()); - let result = scene.cmd("id").arg("-ng").run(); - if skipping_test_is_okay(&result, "id: cannot find name for group ID") { - return; + for (i, from) in ["42", ":42", "42:42"].iter().enumerate() { + let file = i.to_string(); + at.touch(&file); + scene + .ucmd() + .arg("-v") + .arg(format!("--from={from}")) + .arg("43:43") + .arg(&file) + .succeeds() + .stdout_only(format!( + "ownership of '{file}' retained as {user_name}:{group_name}\n" + )); } - let group_name = String::from(result.stdout_str().trim()); - assert!(!group_name.is_empty()); - - let file = "f"; - at.touch(file); - scene - .ucmd() - .arg("-v") - .arg("--from=42:42") - .arg("43:43") - .arg(file) - .succeeds() - .stdout_only(format!( - "ownership of '{file}' retained as {user_name}:{group_name}\n" - )); } diff --git a/tests/by-util/test_chroot.rs b/tests/by-util/test_chroot.rs index 697be8775a8..1fc2231d57a 100644 --- a/tests/by-util/test_chroot.rs +++ b/tests/by-util/test_chroot.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (words) araba newroot userspec chdir pwd's isroot #[cfg(not(target_os = "android"))] diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 41ddc2ee0b1..a9d9b272b4c 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (words) asdf algo algos use crate::common::util::TestScenario; diff --git a/tests/by-util/test_comm.rs b/tests/by-util/test_comm.rs index 42c8358bbab..e2bcc1c443f 100644 --- a/tests/by-util/test_comm.rs +++ b/tests/by-util/test_comm.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (words) defaultcheck nocheck use crate::common::util::TestScenario; diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 18f3829a2ba..f72316b5daa 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (flags) reflink (fs) tmpfs (linux) rlimit Rlim NOFILE clob btrfs ROOTDIR USERDIR procfs outfile use crate::common::util::TestScenario; @@ -2022,12 +2026,12 @@ fn test_cp_reflink_always_override() { const USERDIR: &str = "dir/"; const MOUNTPOINT: &str = "mountpoint/"; - let src1_path: &str = &vec![MOUNTPOINT, USERDIR, "src1"].concat(); - let src2_path: &str = &vec![MOUNTPOINT, USERDIR, "src2"].concat(); - let dst_path: &str = &vec![MOUNTPOINT, USERDIR, "dst"].concat(); + let src1_path: &str = &[MOUNTPOINT, USERDIR, "src1"].concat(); + let src2_path: &str = &[MOUNTPOINT, USERDIR, "src2"].concat(); + let dst_path: &str = &[MOUNTPOINT, USERDIR, "dst"].concat(); scene.fixtures.mkdir(ROOTDIR); - scene.fixtures.mkdir(vec![ROOTDIR, USERDIR].concat()); + scene.fixtures.mkdir([ROOTDIR, USERDIR].concat()); // Setup: // Because neither `mkfs.btrfs` not btrfs `mount` options allow us to have a mountpoint owned diff --git a/tests/by-util/test_csplit.rs b/tests/by-util/test_csplit.rs index eecaccfaf26..b83d5e0eede 100644 --- a/tests/by-util/test_csplit.rs +++ b/tests/by-util/test_csplit.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; use glob::glob; diff --git a/tests/by-util/test_cut.rs b/tests/by-util/test_cut.rs index a82950beb92..7f86c803e8f 100644 --- a/tests/by-util/test_cut.rs +++ b/tests/by-util/test_cut.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; static INPUT: &str = "lists.txt"; diff --git a/tests/by-util/test_date.rs b/tests/by-util/test_date.rs index 669f02e331d..a65f02fa4c7 100644 --- a/tests/by-util/test_date.rs +++ b/tests/by-util/test_date.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; use regex::Regex; #[cfg(all(unix, not(target_os = "macos")))] @@ -395,3 +399,12 @@ fn test_invalid_date_string() { .no_stdout() .stderr_contains("invalid date"); } + +#[test] +fn test_date_overflow() { + new_ucmd!() + .arg("-d68888888888888sms") + .fails() + .no_stdout() + .stderr_contains("invalid date"); +} diff --git a/tests/by-util/test_dd.rs b/tests/by-util/test_dd.rs index b43f32c240a..fe38acca47b 100644 --- a/tests/by-util/test_dd.rs +++ b/tests/by-util/test_dd.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore fname, tname, fpath, specfile, testfile, unspec, ifile, ofile, outfile, fullblock, urand, fileio, atoe, atoibm, availible, behaviour, bmax, bremain, btotal, cflags, creat, ctable, ctty, datastructures, doesnt, etoa, fileout, fname, gnudd, iconvflags, iseek, nocache, noctty, noerror, nofollow, nolinks, nonblock, oconvflags, oseek, outfile, parseargs, rlen, rmax, rposition, rremain, rsofar, rstat, sigusr, sigval, wlen, wstat abcdefghijklm abcdefghi nabcde nabcdefg abcdefg use crate::common::util::TestScenario; diff --git a/tests/by-util/test_df.rs b/tests/by-util/test_df.rs index 926d1be5d61..227121ef4df 100644 --- a/tests/by-util/test_df.rs +++ b/tests/by-util/test_df.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore udev pcent iuse itotal iused ipcent use std::collections::HashSet; diff --git a/tests/by-util/test_dir.rs b/tests/by-util/test_dir.rs index fd94f3a8f5d..3d16f8a67c6 100644 --- a/tests/by-util/test_dir.rs +++ b/tests/by-util/test_dir.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; use regex::Regex; diff --git a/tests/by-util/test_dircolors.rs b/tests/by-util/test_dircolors.rs index 2d83c76b53d..d4fa0a3b0a3 100644 --- a/tests/by-util/test_dircolors.rs +++ b/tests/by-util/test_dircolors.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore overridable use crate::common::util::TestScenario; diff --git a/tests/by-util/test_dirname.rs b/tests/by-util/test_dirname.rs index ae689041be6..8471b48c44b 100644 --- a/tests/by-util/test_dirname.rs +++ b/tests/by-util/test_dirname.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_echo.rs b/tests/by-util/test_echo.rs index 1c07a6737ec..3a8e7f86b34 100644 --- a/tests/by-util/test_echo.rs +++ b/tests/by-util/test_echo.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (words) araba merci use crate::common::util::TestScenario; diff --git a/tests/by-util/test_env.rs b/tests/by-util/test_env.rs index bd206c8e58c..8ce55a1d3a2 100644 --- a/tests/by-util/test_env.rs +++ b/tests/by-util/test_env.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (words) bamf chdir rlimit prlimit COMSPEC use crate::common::util::TestScenario; diff --git a/tests/by-util/test_expand.rs b/tests/by-util/test_expand.rs index 88c1b1670a1..f6802358cc3 100644 --- a/tests/by-util/test_expand.rs +++ b/tests/by-util/test_expand.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; use uucore::display::Quotable; // spell-checker:ignore (ToDO) taaaa tbbbb tcccc diff --git a/tests/by-util/test_expr.rs b/tests/by-util/test_expr.rs index 235a9112057..665f89615e4 100644 --- a/tests/by-util/test_expr.rs +++ b/tests/by-util/test_expr.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore αbcdef ; (people) kkos use crate::common::util::TestScenario; diff --git a/tests/by-util/test_factor.rs b/tests/by-util/test_factor.rs index cf374496430..a14a673a8d3 100644 --- a/tests/by-util/test_factor.rs +++ b/tests/by-util/test_factor.rs @@ -1,7 +1,5 @@ // This file is part of the uutils coreutils package. // -// (c) kwantam -// // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. #![allow(clippy::unreadable_literal)] @@ -165,15 +163,12 @@ fn test_random() { let mut factors = Vec::new(); while product < min { // log distribution---higher probability for lower numbers - let factor; - loop { + let factor = loop { let next = rng.gen_range(0_f64..log_num_primes).exp2().floor() as usize; if next < NUM_PRIMES { - factor = primes[next]; - break; + break primes[next]; } - } - let factor = factor; + }; match product.checked_mul(factor) { Some(p) => { @@ -317,7 +312,7 @@ fn run(input_string: &[u8], output_string: &[u8]) { fn test_primes_with_exponents() { let mut input_string = String::new(); let mut output_string = String::new(); - for primes in PRIMES_BY_BITS.iter() { + for primes in PRIMES_BY_BITS { for &prime in *primes { input_string.push_str(&(format!("{prime} "))[..]); output_string.push_str(&(format!("{prime}: {prime}\n"))[..]); diff --git a/tests/by-util/test_false.rs b/tests/by-util/test_false.rs index c6c6634043e..01916ec622a 100644 --- a/tests/by-util/test_false.rs +++ b/tests/by-util/test_false.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] use std::fs::OpenOptions; diff --git a/tests/by-util/test_fmt.rs b/tests/by-util/test_fmt.rs index 84a19d34d9f..7d23cbd52f1 100644 --- a/tests/by-util/test_fmt.rs +++ b/tests/by-util/test_fmt.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_fold.rs b/tests/by-util/test_fold.rs index b61d9f5ed73..6895f51b6e4 100644 --- a/tests/by-util/test_fold.rs +++ b/tests/by-util/test_fold.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index 3650047b21a..4bf06308dd6 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; // spell-checker:ignore checkfile, nonames, testf, ntestf macro_rules! get_hash( diff --git a/tests/by-util/test_hostid.rs b/tests/by-util/test_hostid.rs index b42ec211d0c..e9336116bca 100644 --- a/tests/by-util/test_hostid.rs +++ b/tests/by-util/test_hostid.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; use regex::Regex; diff --git a/tests/by-util/test_hostname.rs b/tests/by-util/test_hostname.rs index 3c01a1197a9..84cb73e2ecf 100644 --- a/tests/by-util/test_hostname.rs +++ b/tests/by-util/test_hostname.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_install.rs b/tests/by-util/test_install.rs index d76ce1e0147..7387748c619 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (words) helloworld nodir objdump n'source use crate::common::util::{is_ci, TestScenario}; diff --git a/tests/by-util/test_join.rs b/tests/by-util/test_join.rs index f6fbe14c350..e2e5dc8688b 100644 --- a/tests/by-util/test_join.rs +++ b/tests/by-util/test_join.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (words) autoformat nocheck use crate::common::util::TestScenario; diff --git a/tests/by-util/test_kill.rs b/tests/by-util/test_kill.rs index d3602329827..a9094ecf6a7 100644 --- a/tests/by-util/test_kill.rs +++ b/tests/by-util/test_kill.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; use regex::Regex; use std::os::unix::process::ExitStatusExt; diff --git a/tests/by-util/test_link.rs b/tests/by-util/test_link.rs index 3c068af93df..8d48931c424 100644 --- a/tests/by-util/test_link.rs +++ b/tests/by-util/test_link.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] @@ -58,7 +62,7 @@ fn test_link_one_argument() { #[test] fn test_link_three_arguments() { let (_, mut ucmd) = at_and_ucmd!(); - let arguments = vec![ + let arguments = [ "test_link_argument1", "test_link_argument2", "test_link_argument3", diff --git a/tests/by-util/test_ln.rs b/tests/by-util/test_ln.rs index 3be07c4d7a7..dc31f726116 100644 --- a/tests/by-util/test_ln.rs +++ b/tests/by-util/test_ln.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; use std::path::PathBuf; diff --git a/tests/by-util/test_logname.rs b/tests/by-util/test_logname.rs index b0cda1a9d91..8833975556d 100644 --- a/tests/by-util/test_logname.rs +++ b/tests/by-util/test_logname.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::{is_ci, TestScenario}; use std::env; diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 15ded8e6b22..f1815035834 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (words) READMECAREFULLY birthtime doesntexist oneline somebackup lrwx somefile somegroup somehiddenbackup somehiddenfile tabsize aaaaaaaa bbbb cccc dddddddd ncccc neee naaaaa nbcdef nfffff #[cfg(any(unix, feature = "feat_selinux"))] diff --git a/tests/by-util/test_mkdir.rs b/tests/by-util/test_mkdir.rs index 11a860d5a03..8a6eae27bdc 100644 --- a/tests/by-util/test_mkdir.rs +++ b/tests/by-util/test_mkdir.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[cfg(not(windows))] use libc::{mode_t, umask}; diff --git a/tests/by-util/test_mkfifo.rs b/tests/by-util/test_mkfifo.rs index d4ebab640a2..731b6c1d5cd 100644 --- a/tests/by-util/test_mkfifo.rs +++ b/tests/by-util/test_mkfifo.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_mknod.rs b/tests/by-util/test_mknod.rs index deea8bb4ef7..2d83d250d84 100644 --- a/tests/by-util/test_mknod.rs +++ b/tests/by-util/test_mknod.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_mktemp.rs b/tests/by-util/test_mktemp.rs index 4544b6b3093..611a42e43c8 100644 --- a/tests/by-util/test_mktemp.rs +++ b/tests/by-util/test_mktemp.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (words) gpghome use crate::common::util::TestScenario; diff --git a/tests/by-util/test_more.rs b/tests/by-util/test_more.rs index d94a921853e..b6ded2298d8 100644 --- a/tests/by-util/test_more.rs +++ b/tests/by-util/test_more.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; use is_terminal::IsTerminal; diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index ceaa4ba2271..eb8a30ac4e5 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; use filetime::FileTime; use std::thread::sleep; @@ -1278,7 +1282,7 @@ fn test_mv_verbose() { #[test] #[cfg(any(target_os = "linux", target_os = "android"))] // mkdir does not support -m on windows. Freebsd doesn't return a permission error either. -#[cfg(features = "mkdir")] +#[cfg(feature = "mkdir")] fn test_mv_permission_error() { let scene = TestScenario::new("mkdir"); let folder1 = "bar"; diff --git a/tests/by-util/test_nice.rs b/tests/by-util/test_nice.rs index 4e8d5a2ee35..994b0e85660 100644 --- a/tests/by-util/test_nice.rs +++ b/tests/by-util/test_nice.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore libc's use crate::common::util::TestScenario; diff --git a/tests/by-util/test_nl.rs b/tests/by-util/test_nl.rs index e178950b315..b58c0c206fb 100644 --- a/tests/by-util/test_nl.rs +++ b/tests/by-util/test_nl.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore binvalid finvalid hinvalid iinvalid linvalid ninvalid vinvalid winvalid use crate::common::util::TestScenario; @@ -464,3 +468,21 @@ fn test_invalid_regex_numbering() { .stderr_contains("invalid regular expression"); } } + +#[test] +fn test_line_number_overflow() { + new_ucmd!() + .arg(format!("--starting-line-number={}", i64::MAX)) + .pipe_in("a\nb") + .fails() + .stdout_is(format!("{}\ta\n", i64::MAX)) + .stderr_is("nl: line number overflow\n"); + + new_ucmd!() + .arg(format!("--starting-line-number={}", i64::MIN)) + .arg("--line-increment=-1") + .pipe_in("a\nb") + .fails() + .stdout_is(format!("{}\ta\n", i64::MIN)) + .stderr_is("nl: line number overflow\n"); +} diff --git a/tests/by-util/test_nohup.rs b/tests/by-util/test_nohup.rs index c14a2e494fc..b014c31aa08 100644 --- a/tests/by-util/test_nohup.rs +++ b/tests/by-util/test_nohup.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; use std::thread::sleep; diff --git a/tests/by-util/test_nproc.rs b/tests/by-util/test_nproc.rs index 2e3c5c603a7..22523352b5f 100644 --- a/tests/by-util/test_nproc.rs +++ b/tests/by-util/test_nproc.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore incorrectnumber use crate::common::util::TestScenario; diff --git a/tests/by-util/test_numfmt.rs b/tests/by-util/test_numfmt.rs index 561752db37f..2c2e95d0bb1 100644 --- a/tests/by-util/test_numfmt.rs +++ b/tests/by-util/test_numfmt.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (paths) gnutest use crate::common::util::TestScenario; diff --git a/tests/by-util/test_paste.rs b/tests/by-util/test_paste.rs index da92daa32f1..0fbdb75d268 100644 --- a/tests/by-util/test_paste.rs +++ b/tests/by-util/test_paste.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; struct TestData<'b> { diff --git a/tests/by-util/test_pathchk.rs b/tests/by-util/test_pathchk.rs index 771fbd0a93f..f497cfe898d 100644 --- a/tests/by-util/test_pathchk.rs +++ b/tests/by-util/test_pathchk.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_pr.rs b/tests/by-util/test_pr.rs index b62fa4a9683..195d4056798 100644 --- a/tests/by-util/test_pr.rs +++ b/tests/by-util/test_pr.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (ToDO) Sdivide use crate::common::util::{TestScenario, UCommand}; diff --git a/tests/by-util/test_printenv.rs b/tests/by-util/test_printenv.rs index fa7d420e13f..c9eb3c60eed 100644 --- a/tests/by-util/test_printenv.rs +++ b/tests/by-util/test_printenv.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_printf.rs b/tests/by-util/test_printf.rs index e9b25954fea..d7ba5679ecf 100644 --- a/tests/by-util/test_printf.rs +++ b/tests/by-util/test_printf.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_ptx.rs b/tests/by-util/test_ptx.rs index db4a4f3ccb2..a106972ac29 100644 --- a/tests/by-util/test_ptx.rs +++ b/tests/by-util/test_ptx.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_pwd.rs b/tests/by-util/test_pwd.rs index 1e43f5be6ba..89341c0c33d 100644 --- a/tests/by-util/test_pwd.rs +++ b/tests/by-util/test_pwd.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (words) symdir somefakedir use std::path::PathBuf; diff --git a/tests/by-util/test_readlink.rs b/tests/by-util/test_readlink.rs index f0867158386..973e30a3597 100644 --- a/tests/by-util/test_readlink.rs +++ b/tests/by-util/test_readlink.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore regfile use crate::common::util::{get_root_path, TestScenario}; diff --git a/tests/by-util/test_realpath.rs b/tests/by-util/test_realpath.rs index 707378c97b0..c3a15fba40e 100644 --- a/tests/by-util/test_realpath.rs +++ b/tests/by-util/test_realpath.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::{get_root_path, TestScenario}; #[cfg(windows)] diff --git a/tests/by-util/test_relpath.rs b/tests/by-util/test_relpath.rs index 65cbd391e8f..8a3c91802e1 100644 --- a/tests/by-util/test_relpath.rs +++ b/tests/by-util/test_relpath.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; use std::borrow::Cow; use std::path::Path; diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index 737c4fa79b0..73f99566c40 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::process::Stdio; use crate::common::util::TestScenario; @@ -478,7 +482,7 @@ fn test_rm_prompts() { // Needed for talking with stdin on platforms where CRLF or LF matters const END_OF_LINE: &str = if cfg!(windows) { "\r\n" } else { "\n" }; - let mut answers = vec![ + let mut answers = [ "rm: descend into directory 'a'?", "rm: remove write-protected regular empty file 'a/empty-no-write'?", "rm: remove symbolic link 'a/slink'?", diff --git a/tests/by-util/test_rmdir.rs b/tests/by-util/test_rmdir.rs index 56e801d7e15..086d43748ab 100644 --- a/tests/by-util/test_rmdir.rs +++ b/tests/by-util/test_rmdir.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; const DIR: &str = "dir"; diff --git a/tests/by-util/test_runcon.rs b/tests/by-util/test_runcon.rs index dd4445625bc..7635fea49cb 100644 --- a/tests/by-util/test_runcon.rs +++ b/tests/by-util/test_runcon.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (jargon) xattributes #![cfg(feature = "feat_selinux")] diff --git a/tests/by-util/test_seq.rs b/tests/by-util/test_seq.rs index de078191251..8f879263b2c 100644 --- a/tests/by-util/test_seq.rs +++ b/tests/by-util/test_seq.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore lmnop xlmnop use crate::common::util::TestScenario; use std::process::Stdio; diff --git a/tests/by-util/test_shred.rs b/tests/by-util/test_shred.rs index d98b840c47f..83d2890ed0b 100644 --- a/tests/by-util/test_shred.rs +++ b/tests/by-util/test_shred.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_shuf.rs b/tests/by-util/test_shuf.rs index 44282b8a304..13df0fa483f 100644 --- a/tests/by-util/test_shuf.rs +++ b/tests/by-util/test_shuf.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] @@ -71,7 +75,7 @@ fn test_echo() { #[test] fn test_head_count() { let repeat_limit = 5; - let input_seq = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let input_seq = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let input = input_seq .iter() .map(ToString::to_string) @@ -102,7 +106,7 @@ fn test_head_count() { #[test] fn test_repeat() { let repeat_limit = 15000; - let input_seq = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let input_seq = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let input = input_seq .iter() .map(ToString::to_string) diff --git a/tests/by-util/test_sleep.rs b/tests/by-util/test_sleep.rs index 76e98e012b6..dd99c74060b 100644 --- a/tests/by-util/test_sleep.rs +++ b/tests/by-util/test_sleep.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use rstest::rstest; // spell-checker:ignore dont diff --git a/tests/by-util/test_stdbuf.rs b/tests/by-util/test_stdbuf.rs index 3347157069d..e31c532e22a 100644 --- a/tests/by-util/test_stdbuf.rs +++ b/tests/by-util/test_stdbuf.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. #[cfg(not(target_os = "windows"))] use crate::common::util::TestScenario; diff --git a/tests/by-util/test_stty.rs b/tests/by-util/test_stty.rs index e85c1108221..a9a9209b034 100644 --- a/tests/by-util/test_stty.rs +++ b/tests/by-util/test_stty.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore parenb parmrk ixany iuclc onlcr ofdel icanon noflsh use crate::common::util::TestScenario; diff --git a/tests/by-util/test_sum.rs b/tests/by-util/test_sum.rs index 0a43a304394..13f453ba113 100644 --- a/tests/by-util/test_sum.rs +++ b/tests/by-util/test_sum.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_sync.rs b/tests/by-util/test_sync.rs index 9cae3b8a0cf..9a824cd4861 100644 --- a/tests/by-util/test_sync.rs +++ b/tests/by-util/test_sync.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; use std::fs; use tempfile::tempdir; diff --git a/tests/by-util/test_tac.rs b/tests/by-util/test_tac.rs index cc98ec61609..fa5f67f133f 100644 --- a/tests/by-util/test_tac.rs +++ b/tests/by-util/test_tac.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore axxbxx bxxaxx axxx axxxx xxaxx xxax xxxxa axyz zyax zyxa use crate::common::util::TestScenario; diff --git a/tests/by-util/test_tee.rs b/tests/by-util/test_tee.rs index 51d552d6726..6f04edfc37a 100644 --- a/tests/by-util/test_tee.rs +++ b/tests/by-util/test_tee.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; // tests for basic tee functionality. diff --git a/tests/by-util/test_test.rs b/tests/by-util/test_test.rs index bf5c50b7f43..91af9033a8a 100644 --- a/tests/by-util/test_test.rs +++ b/tests/by-util/test_test.rs @@ -1,9 +1,6 @@ // // This file is part of the uutils coreutils package. // -// (c) mahkoh (ju.orth [at] gmail [dot] com) -// (c) Daniel Rocco -// // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. // diff --git a/tests/by-util/test_timeout.rs b/tests/by-util/test_timeout.rs index 8e6e5db5572..6c4a00eb552 100644 --- a/tests/by-util/test_timeout.rs +++ b/tests/by-util/test_timeout.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore dont use crate::common::util::TestScenario; diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index 0ebbee1d7b2..942446a3383 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore (formats) cymdhm cymdhms mdhm mdhms ymdhm ymdhms datetime mktime use crate::common::util::{AtPath, TestScenario}; diff --git a/tests/by-util/test_tr.rs b/tests/by-util/test_tr.rs index 4e437609ef1..7c475a492ef 100644 --- a/tests/by-util/test_tr.rs +++ b/tests/by-util/test_tr.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. // spell-checker:ignore aabbaa aabbcc aabc abbb abcc abcdefabcdef abcdefghijk abcdefghijklmn abcdefghijklmnop ABCDEFGHIJKLMNOPQRS abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFZZ abcxyz ABCXYZ abcxyzabcxyz ABCXYZABCXYZ acbdef alnum amzamz AMZXAMZ bbbd cclass cefgm cntrl compl dabcdef dncase Gzabcdefg PQRST upcase wxyzz xdigit xycde xyyye xyyz xyzzzzxyzzzz ZABCDEF Zamz Cdefghijkl Cdefghijklmn use crate::common::util::TestScenario; diff --git a/tests/by-util/test_true.rs b/tests/by-util/test_true.rs index 1675b3903f9..750c60132e8 100644 --- a/tests/by-util/test_true.rs +++ b/tests/by-util/test_true.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] use std::fs::OpenOptions; diff --git a/tests/by-util/test_tsort.rs b/tests/by-util/test_tsort.rs index 62a74c31d0e..18889451629 100644 --- a/tests/by-util/test_tsort.rs +++ b/tests/by-util/test_tsort.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_tty.rs b/tests/by-util/test_tty.rs index 87dcbac8578..0f2c588063a 100644 --- a/tests/by-util/test_tty.rs +++ b/tests/by-util/test_tty.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::fs::File; use crate::common::util::TestScenario; diff --git a/tests/by-util/test_uname.rs b/tests/by-util/test_uname.rs index 5076334e54c..3676eefbaaf 100644 --- a/tests/by-util/test_uname.rs +++ b/tests/by-util/test_uname.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_unexpand.rs b/tests/by-util/test_unexpand.rs index c833c93e40b..ddbe3343efa 100644 --- a/tests/by-util/test_unexpand.rs +++ b/tests/by-util/test_unexpand.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_uniq.rs b/tests/by-util/test_uniq.rs index 57f0ec111a7..97a829b9f7a 100644 --- a/tests/by-util/test_uniq.rs +++ b/tests/by-util/test_uniq.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::io::Write; // spell-checker:ignore nabcd diff --git a/tests/by-util/test_unlink.rs b/tests/by-util/test_unlink.rs index 5313c9eabc9..055f47f1076 100644 --- a/tests/by-util/test_unlink.rs +++ b/tests/by-util/test_unlink.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_uptime.rs b/tests/by-util/test_uptime.rs index 628f4cead6d..3967d025251 100644 --- a/tests/by-util/test_uptime.rs +++ b/tests/by-util/test_uptime.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; use regex::Regex; diff --git a/tests/by-util/test_users.rs b/tests/by-util/test_users.rs index 6a54aa8d274..766378a9dca 100644 --- a/tests/by-util/test_users.rs +++ b/tests/by-util/test_users.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; #[test] diff --git a/tests/by-util/test_vdir.rs b/tests/by-util/test_vdir.rs index f6498567fbf..97d5b847fb8 100644 --- a/tests/by-util/test_vdir.rs +++ b/tests/by-util/test_vdir.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::TestScenario; use regex::Regex; diff --git a/tests/by-util/test_wc.rs b/tests/by-util/test_wc.rs index aba5ed350a6..6417470c57f 100644 --- a/tests/by-util/test_wc.rs +++ b/tests/by-util/test_wc.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use crate::common::util::{vec_of_size, TestScenario}; // spell-checker:ignore (flags) lwmcL clmwL ; (path) bogusfile emptyfile manyemptylines moby notrailingnewline onelongemptyline onelongword weirdchars diff --git a/tests/by-util/test_yes.rs b/tests/by-util/test_yes.rs index a674f8245c2..f40d6d5b8e2 100644 --- a/tests/by-util/test_yes.rs +++ b/tests/by-util/test_yes.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. use std::ffi::OsStr; use std::process::{ExitStatus, Stdio}; diff --git a/tests/common/mod.rs b/tests/common/mod.rs index f73cd42af24..05e2b13824c 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. #[macro_use] pub mod macros; pub mod random; diff --git a/tests/common/util.rs b/tests/common/util.rs index 995312f08e2..8ef5f517aee 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -541,7 +541,7 @@ impl CmdResult { let contents = String::from_utf8(read_scenario_fixture(&self.tmpd, file_rel_path)).unwrap(); let possible_values = template_vars.iter().map(|vars| { let mut contents = contents.clone(); - for kv in vars.iter() { + for kv in vars { contents = contents.replace(&kv.0, &kv.1); } contents @@ -2211,12 +2211,12 @@ impl UChild { let join_handle = thread::spawn(move || { let mut writer = BufWriter::new(stdin); - match writer.write_all(&content).and_then(|_| writer.flush()) { + match writer.write_all(&content).and_then(|()| writer.flush()) { Err(error) if !ignore_stdin_write_error => Err(io::Error::new( io::ErrorKind::Other, format!("failed to write to stdin of child: {error}"), )), - Ok(_) | Err(_) => Ok(()), + Ok(()) | Err(_) => Ok(()), } }); @@ -2263,12 +2263,12 @@ impl UChild { pub fn try_write_in>>(&mut self, data: T) -> io::Result<()> { let stdin = self.raw.stdin.as_mut().unwrap(); - match stdin.write_all(&data.into()).and_then(|_| stdin.flush()) { + match stdin.write_all(&data.into()).and_then(|()| stdin.flush()) { Err(error) if !self.ignore_stdin_write_error => Err(io::Error::new( io::ErrorKind::Other, format!("failed to write to stdin of child: {error}"), )), - Ok(_) | Err(_) => Ok(()), + Ok(()) | Err(_) => Ok(()), } } @@ -2505,11 +2505,11 @@ pub fn expected_result(ts: &TestScenario, args: &[&str]) -> std::result::Result< /// This is a convenience wrapper to run a ucmd with root permissions. /// It can be used to test programs when being root is needed -/// This runs 'sudo -E --non-interactive target/debug/coreutils util_name args` +/// This runs `sudo -E --non-interactive target/debug/coreutils util_name args` /// This is primarily designed to run in an environment where whoami is in $path /// and where non-interactive sudo is possible. /// To check if i) non-interactive sudo is possible and ii) if sudo works, this runs: -/// 'sudo -E --non-interactive whoami' first. +/// `sudo -E --non-interactive whoami` first. /// /// This return an `Err()` if run inside CICD because there's no 'sudo'. /// @@ -3279,7 +3279,7 @@ mod tests { std::assert_eq!(error.to_string(), "kill: Timeout of '0s' reached"); } Err(error) => panic!("Assertion failed: Expected error with timeout but was: {error}"), - Ok(_) => panic!("Assertion failed: Expected timeout of `try_kill`."), + Ok(()) => panic!("Assertion failed: Expected timeout of `try_kill`."), } } diff --git a/tests/fixtures/install/helloworld.rs b/tests/fixtures/install/helloworld.rs index 47ad8c63411..bb2a816fc00 100644 --- a/tests/fixtures/install/helloworld.rs +++ b/tests/fixtures/install/helloworld.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. fn main() { println!("Hello World!"); } diff --git a/tests/test_util_name.rs b/tests/test_util_name.rs index bf0ea2fa321..45edc7dc782 100644 --- a/tests/test_util_name.rs +++ b/tests/test_util_name.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. #![allow(unused_imports)] mod common; diff --git a/tests/tests.rs b/tests/tests.rs index 02c3bfdaba2..8d4a6855c9e 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,3 +1,7 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. #[macro_use] mod common;