diff options
55 files changed, 3331 insertions, 1162 deletions
diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 75b867b71..ae6c24493 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -397,14 +397,14 @@ jobs: --arg multisize "$SIZE_MULTI" \ '{($date): { sha: $sha, size: $size, multisize: $multisize, }}' > size-result.json - name: Download the previous individual size result - uses: dawidd6/action-download-artifact@v3 + uses: dawidd6/action-download-artifact@v5 with: workflow: CICD.yml name: individual-size-result repo: uutils/coreutils path: dl - name: Download the previous size result - uses: dawidd6/action-download-artifact@v3 + uses: dawidd6/action-download-artifact@v5 with: workflow: CICD.yml name: size-result @@ -477,8 +477,8 @@ jobs: - { os: ubuntu-latest , target: x86_64-unknown-linux-gnu , features: feat_os_unix , use-cross: use-cross } - { os: ubuntu-latest , target: x86_64-unknown-linux-musl , features: feat_os_unix_musl , use-cross: use-cross } - { os: ubuntu-latest , target: x86_64-unknown-redox , features: feat_os_unix_redox , use-cross: redoxer , skip-tests: true } - - { os: macos-14 , target: aarch64-apple-darwin , features: feat_os_macos } # M1 CPU - - { os: macos-latest , target: x86_64-apple-darwin , features: feat_os_macos } + - { os: macos-latest , target: aarch64-apple-darwin , features: feat_os_macos } # M1 CPU + - { os: macos-13 , target: x86_64-apple-darwin , features: feat_os_macos } - { os: windows-latest , target: i686-pc-windows-msvc , features: feat_os_windows } - { os: windows-latest , target: x86_64-pc-windows-gnu , features: feat_os_windows } - { os: windows-latest , target: x86_64-pc-windows-msvc , features: feat_os_windows } diff --git a/.github/workflows/GnuTests.yml b/.github/workflows/GnuTests.yml index eefba654c..ef3f62a89 100644 --- a/.github/workflows/GnuTests.yml +++ b/.github/workflows/GnuTests.yml @@ -77,7 +77,7 @@ jobs: ref: ${{ steps.vars.outputs.repo_GNU_ref }} submodules: recursive - name: Retrieve reference artifacts - uses: dawidd6/action-download-artifact@v3 + uses: dawidd6/action-download-artifact@v5 # ref: <https://github.com/dawidd6/action-download-artifact> continue-on-error: true ## don't break the build for missing reference artifacts (may be expired or just not generated yet) with: diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 528c2ad49..d4aff652a 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -112,7 +112,7 @@ jobs: ~/.android/avd/*/*.lock - name: Create and cache emulator image if: steps.avd-cache.outputs.cache-hit != 'true' - uses: reactivecircus/android-emulator-runner@v2.30.1 + uses: reactivecircus/android-emulator-runner@v2.31.0 with: api-level: ${{ matrix.api-level }} target: ${{ matrix.target }} @@ -157,7 +157,7 @@ jobs: free -mh df -Th - name: Build and Test - uses: reactivecircus/android-emulator-runner@v2.30.1 + uses: reactivecircus/android-emulator-runner@v2.31.0 with: api-level: ${{ matrix.api-level }} target: ${{ matrix.target }} diff --git a/.vscode/cspell.dictionaries/workspace.wordlist.txt b/.vscode/cspell.dictionaries/workspace.wordlist.txt index c3c854a4c..ce4822f1e 100644 --- a/.vscode/cspell.dictionaries/workspace.wordlist.txt +++ b/.vscode/cspell.dictionaries/workspace.wordlist.txt @@ -166,6 +166,7 @@ RTLD_NEXT RTLD SIGINT SIGKILL +SIGSTOP SIGTERM SYS_fdatasync SYS_syncfs diff --git a/Cargo.lock b/Cargo.lock index 898b38981..a8dcda09c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1303,9 +1303,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.154" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libloading" @@ -1619,11 +1619,12 @@ dependencies = [ [[package]] name = "parse_datetime" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbf4e25b13841080e018a1e666358adfe5e39b6d353f986ca5091c210b586a1" +checksum = "a8720474e3dd4af20cea8716703498b9f3b690f318fa9d9d9e2e38eaf44b96d0" dependencies = [ "chrono", + "nom", "regex", ] @@ -1732,10 +1733,19 @@ dependencies = [ ] [[package]] +name = "proc-macro-crate" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +dependencies = [ + "toml_edit", +] + +[[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] @@ -1880,9 +1890,9 @@ checksum = "f1bfbf25d7eb88ddcbb1ec3d755d0634da8f7657b2cb8b74089121409ab8228f" [[package]] name = "regex" -version = "1.10.4" +version = "1.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" dependencies = [ "aho-corasick", "memchr", @@ -1930,9 +1940,9 @@ checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316" [[package]] name = "rstest" -version = "0.19.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5316d2a1479eeef1ea21e7f9ddc67c191d497abc8fc3ba2467857abbb68330" +checksum = "9afd55a67069d6e434a95161415f5beeada95a01c7b815508a82dcb0e1593682" dependencies = [ "futures", "futures-timer", @@ -1942,12 +1952,13 @@ dependencies = [ [[package]] name = "rstest_macros" -version = "0.19.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04a9df72cc1f67020b0d63ad9bfe4a323e459ea7eb68e03bd9824db49f9a4c25" +checksum = "4165dfae59a39dd41d8dec720d3cbfbc71f69744efb480a3920f5d4e0cc6798d" dependencies = [ "cfg-if", "glob", + "proc-macro-crate", "proc-macro2", "quote", "regex", @@ -2277,18 +2288,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", @@ -2338,6 +2349,23 @@ dependencies = [ ] [[package]] +name = "toml_datetime" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" + +[[package]] +name = "toml_edit" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] name = "trim-in-place" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2494,6 +2522,7 @@ version = "0.0.26" dependencies = [ "clap", "hex", + "regex", "uucore", ] @@ -3405,6 +3434,7 @@ dependencies = [ "number_prefix", "once_cell", "os_display", + "regex", "sha1", "sha2", "sha3", @@ -3794,6 +3824,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + +[[package]] name = "wyz" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3847,9 +3886,9 @@ dependencies = [ [[package]] name = "zip" -version = "1.2.2" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed14a57c18714abaa03196c0714ed36bab969d7457f72d12fb5c2e1ced4c24ae" +checksum = "f1f4a27345eb6f7aa7bd015ba7eb4175fa4e1b462a29874b779e0bbcf96c6ac7" dependencies = [ "arbitrary", "crc32fast", diff --git a/Cargo.toml b/Cargo.toml index 229d6b9f5..c7c15a0c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -289,7 +289,7 @@ half = "2.4.1" hostname = "0.4" indicatif = "0.17.8" itertools = "0.12.1" -libc = "0.2.154" +libc = "0.2.153" lscolors = { version = "0.16.0", default-features = false, features = [ "gnu_legacy", ] } @@ -304,7 +304,7 @@ num-traits = "0.2.19" number_prefix = "0.4" once_cell = "1.19.0" onig = { version = "~6.4", default-features = false } -parse_datetime = "0.5.0" +parse_datetime = "0.6.0" phf = "0.11.2" phf_codegen = "0.11.2" platform-info = "2.0.3" @@ -314,7 +314,7 @@ rand_core = "0.6.4" rayon = "1.10" redox_syscall = "0.5.1" regex = "1.10.4" -rstest = "0.19.0" +rstest = "0.21.0" rust-ini = "0.21.0" same-file = "1.0.6" self_cell = "1.0.4" @@ -490,7 +490,12 @@ sha1 = { version = "0.10.6", features = ["std"] } tempfile = { workspace = true } time = { workspace = true, features = ["local-offset"] } unindent = "0.2.3" -uucore = { workspace = true, features = ["entries", "process", "signals"] } +uucore = { workspace = true, features = [ + "entries", + "mode", + "process", + "signals", +] } walkdir = { workspace = true } hex-literal = "0.4.1" rstest = { workspace = true } @@ -24,6 +24,7 @@ allow = [ "BSD-2-Clause", "BSD-2-Clause-FreeBSD", "BSD-3-Clause", + "BSL-1.0", "CC0-1.0", "Unicode-DFS-2016", ] diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index f2848c071..45f3f22ec 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -9,7 +9,7 @@ cargo-fuzz = true [dependencies] libfuzzer-sys = "0.4.7" -libc = "0.2.154" +libc = "0.2.153" tempfile = "3.10.1" rand = { version = "0.8.5", features = ["small_rng"] } similar = "2.5.0" diff --git a/src/uu/cksum/Cargo.toml b/src/uu/cksum/Cargo.toml index f6a5a138a..208c01901 100644 --- a/src/uu/cksum/Cargo.toml +++ b/src/uu/cksum/Cargo.toml @@ -16,8 +16,9 @@ path = "src/cksum.rs" [dependencies] clap = { workspace = true } -uucore = { workspace = true, features = ["encoding", "sum"] } +uucore = { workspace = true, features = ["checksum", "encoding", "sum"] } hex = { workspace = true } +regex = { workspace = true } [[bin]] name = "cksum" diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index a50abada5..0c807c8c4 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -5,46 +5,27 @@ // spell-checker:ignore (ToDO) fname, algo use clap::{crate_version, value_parser, Arg, ArgAction, Command}; -use hex::decode; -use hex::encode; -use std::error::Error; use std::ffi::OsStr; -use std::fmt::Display; use std::fs::File; use std::io::{self, stdin, stdout, BufReader, Read, Write}; use std::iter; use std::path::Path; +use uucore::checksum::{ + calculate_blake2b_length, detect_algo, digest_reader, perform_checksum_validation, + ChecksumError, ALGORITHM_OPTIONS_BLAKE2B, ALGORITHM_OPTIONS_BSD, ALGORITHM_OPTIONS_CRC, + ALGORITHM_OPTIONS_SYSV, SUPPORTED_ALGORITHMS, +}; use uucore::{ encoding, - error::{FromIo, UError, UResult, USimpleError}, + error::{FromIo, UResult, USimpleError}, format_usage, help_about, help_section, help_usage, show, - sum::{ - div_ceil, Blake2b, Digest, DigestWriter, Md5, Sha1, Sha224, Sha256, Sha384, Sha512, Sm3, - BSD, CRC, SYSV, - }, + sum::{div_ceil, Digest}, }; const USAGE: &str = help_usage!("cksum.md"); const ABOUT: &str = help_about!("cksum.md"); const AFTER_HELP: &str = help_section!("after help", "cksum.md"); -const ALGORITHM_OPTIONS_SYSV: &str = "sysv"; -const ALGORITHM_OPTIONS_BSD: &str = "bsd"; -const ALGORITHM_OPTIONS_CRC: &str = "crc"; -const ALGORITHM_OPTIONS_MD5: &str = "md5"; -const ALGORITHM_OPTIONS_SHA1: &str = "sha1"; -const ALGORITHM_OPTIONS_SHA224: &str = "sha224"; -const ALGORITHM_OPTIONS_SHA256: &str = "sha256"; -const ALGORITHM_OPTIONS_SHA384: &str = "sha384"; -const ALGORITHM_OPTIONS_SHA512: &str = "sha512"; -const ALGORITHM_OPTIONS_BLAKE2B: &str = "blake2b"; -const ALGORITHM_OPTIONS_SM3: &str = "sm3"; - -#[derive(Debug)] -enum CkSumError { - RawMultipleFiles, -} - #[derive(Debug, PartialEq)] enum OutputFormat { Hexadecimal, @@ -52,94 +33,6 @@ enum OutputFormat { Base64, } -impl UError for CkSumError { - fn code(&self) -> i32 { - match self { - Self::RawMultipleFiles => 1, - } - } -} - -impl Error for CkSumError {} - -impl Display for CkSumError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::RawMultipleFiles => { - write!(f, "the --raw option is not supported with multiple files") - } - } - } -} - -fn detect_algo( - program: &str, - length: Option<usize>, -) -> (&'static str, Box<dyn Digest + 'static>, usize) { - match program { - ALGORITHM_OPTIONS_SYSV => ( - ALGORITHM_OPTIONS_SYSV, - Box::new(SYSV::new()) as Box<dyn Digest>, - 512, - ), - ALGORITHM_OPTIONS_BSD => ( - ALGORITHM_OPTIONS_BSD, - Box::new(BSD::new()) as Box<dyn Digest>, - 1024, - ), - ALGORITHM_OPTIONS_CRC => ( - ALGORITHM_OPTIONS_CRC, - Box::new(CRC::new()) as Box<dyn Digest>, - 256, - ), - ALGORITHM_OPTIONS_MD5 => ( - ALGORITHM_OPTIONS_MD5, - Box::new(Md5::new()) as Box<dyn Digest>, - 128, - ), - ALGORITHM_OPTIONS_SHA1 => ( - ALGORITHM_OPTIONS_SHA1, - Box::new(Sha1::new()) as Box<dyn Digest>, - 160, - ), - ALGORITHM_OPTIONS_SHA224 => ( - ALGORITHM_OPTIONS_SHA224, - Box::new(Sha224::new()) as Box<dyn Digest>, - 224, - ), - ALGORITHM_OPTIONS_SHA256 => ( - ALGORITHM_OPTIONS_SHA256, - Box::new(Sha256::new()) as Box<dyn Digest>, - 256, - ), - ALGORITHM_OPTIONS_SHA384 => ( - ALGORITHM_OPTIONS_SHA384, - Box::new(Sha384::new()) as Box<dyn Digest>, - 384, - ), - ALGORITHM_OPTIONS_SHA512 => ( - ALGORITHM_OPTIONS_SHA512, - Box::new(Sha512::new()) as Box<dyn Digest>, - 512, - ), - ALGORITHM_OPTIONS_BLAKE2B => ( - ALGORITHM_OPTIONS_BLAKE2B, - Box::new(if let Some(length) = length { - Blake2b::with_output_bytes(length) - } else { - Blake2b::new() - }) as Box<dyn Digest>, - 512, - ), - ALGORITHM_OPTIONS_SM3 => ( - ALGORITHM_OPTIONS_SM3, - Box::new(Sm3::new()) as Box<dyn Digest>, - 512, - ), - _ => unreachable!("unknown algorithm: clap should have prevented this case"), - } -} - struct Options { algo_name: &'static str, digest: Box<dyn Digest + 'static>, @@ -163,7 +56,7 @@ where { let files: Vec<_> = files.collect(); if options.output_format == OutputFormat::Raw && files.len() > 1 { - return Err(Box::new(CkSumError::RawMultipleFiles)); + return Err(Box::new(ChecksumError::RawMultipleFiles)); } for filename in files { @@ -189,8 +82,6 @@ where Box::new(file_buf) as Box<dyn Read> }); - let (sum_hex, sz) = digest_read(&mut options.digest, &mut file, options.output_bits) - .map_err_context(|| "failed to read input".to_string())?; if filename.is_dir() { show!(USimpleError::new( 1, @@ -198,6 +89,11 @@ where )); continue; } + + let (sum_hex, sz) = + digest_reader(&mut options.digest, &mut file, false, options.output_bits) + .map_err_context(|| "failed to read input".to_string())?; + let sum = match options.output_format { OutputFormat::Raw => { let bytes = match options.algo_name { @@ -205,7 +101,7 @@ where ALGORITHM_OPTIONS_SYSV | ALGORITHM_OPTIONS_BSD => { sum_hex.parse::<u16>().unwrap().to_be_bytes().to_vec() } - _ => decode(sum_hex).unwrap(), + _ => hex::decode(sum_hex).unwrap(), }; // Cannot handle multiple files anyway, output immediately. stdout().write_all(&bytes)?; @@ -214,7 +110,8 @@ where OutputFormat::Hexadecimal => sum_hex, OutputFormat::Base64 => match options.algo_name { ALGORITHM_OPTIONS_CRC | ALGORITHM_OPTIONS_SYSV | ALGORITHM_OPTIONS_BSD => sum_hex, - _ => encoding::encode(encoding::Format::Base64, &decode(sum_hex).unwrap()).unwrap(), + _ => encoding::encode(encoding::Format::Base64, &hex::decode(sum_hex).unwrap()) + .unwrap(), }, }; // The BSD checksum output is 5 digit integer @@ -270,39 +167,6 @@ where Ok(()) } -fn digest_read<T: Read>( - digest: &mut Box<dyn Digest>, - reader: &mut BufReader<T>, - output_bits: usize, -) -> io::Result<(String, usize)> { - digest.reset(); - - // Read bytes from `reader` and write those bytes to `digest`. - // - // If `binary` is `false` and the operating system is Windows, then - // `DigestWriter` replaces "\r\n" with "\n" before it writes the - // bytes into `digest`. Otherwise, it just inserts the bytes as-is. - // - // In order to support replacing "\r\n", we must call `finalize()` - // in order to support the possibility that the last character read - // from the reader was "\r". (This character gets buffered by - // `DigestWriter` and only written if the following character is - // "\n". But when "\r" is the last character read, we need to force - // it to be written.) - let mut digest_writer = DigestWriter::new(digest, true); - let output_size = std::io::copy(reader, &mut digest_writer)? as usize; - digest_writer.finalize(); - - if digest.output_bits() > 0 { - Ok((digest.result_str(), output_size)) - } else { - // Assume it's SHAKE. result_str() doesn't work with shake (as of 8/30/2016) - let mut bytes = vec![0; (output_bits + 7) / 8]; - digest.hash_finalize(&mut bytes); - Ok((encode(bytes), output_size)) - } -} - mod options { pub const ALGORITHM: &str = "algorithm"; pub const FILE: &str = "file"; @@ -312,8 +176,13 @@ mod options { pub const RAW: &str = "raw"; pub const BASE64: &str = "base64"; pub const CHECK: &str = "check"; + pub const STRICT: &str = "strict"; pub const TEXT: &str = "text"; pub const BINARY: &str = "binary"; + pub const STATUS: &str = "status"; + pub const WARN: &str = "warn"; + pub const IGNORE_MISSING: &str = "ignore-missing"; + pub const QUIET: &str = "quiet"; } /// Determines whether to prompt an asterisk (*) in the output. @@ -358,12 +227,11 @@ fn had_reset(args: &[String]) -> bool { * We handle this in this function to make sure they are self contained * and "easier" to understand */ -fn handle_tag_text_binary_flags(matches: &clap::ArgMatches, check: bool) -> UResult<(bool, bool)> { +fn handle_tag_text_binary_flags(matches: &clap::ArgMatches) -> UResult<(bool, bool)> { let untagged: bool = matches.get_flag(options::UNTAGGED); let tag: bool = matches.get_flag(options::TAG); let tag: bool = tag || !untagged; - let text_flag: bool = matches.get_flag(options::TEXT); let binary_flag: bool = matches.get_f |