1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge branch 'main' into issue-4176-fix-timeout

This commit is contained in:
Terts Diepraam 2023-03-12 13:35:27 +01:00 committed by GitHub
commit 320929d83d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 64 additions and 65 deletions

26
Cargo.lock generated
View file

@ -61,17 +61,6 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi 0.1.19",
"libc",
"winapi",
]
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
@ -236,13 +225,13 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.0.26" version = "4.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2148adefda54e14492fb9bddcc600b4344c5d1a3123bd666dcb939c6f0e0e57e" checksum = "c3d7ae14b20b94cb02149ed21a86c423859cbe18dc7ed69845cace50e52b40a5"
dependencies = [ dependencies = [
"atty",
"bitflags", "bitflags",
"clap_lex", "clap_lex",
"is-terminal",
"once_cell", "once_cell",
"strsim", "strsim",
"termcolor", "termcolor",
@ -1808,20 +1797,19 @@ dependencies = [
[[package]] [[package]]
name = "rayon" name = "rayon"
version = "1.6.0" version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e060280438193c554f654141c9ea9417886713b7acd75974c85b18a69a88e0b" checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b"
dependencies = [ dependencies = [
"crossbeam-deque",
"either", "either",
"rayon-core", "rayon-core",
] ]
[[package]] [[package]]
name = "rayon-core" name = "rayon-core"
version = "1.10.1" version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3" checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d"
dependencies = [ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"crossbeam-deque", "crossbeam-deque",

View file

@ -269,7 +269,7 @@ bstr = "1.0"
bytecount = "0.6.3" bytecount = "0.6.3"
byteorder = "1.3.2" byteorder = "1.3.2"
chrono = { version="^0.4.23", default-features=false, features=["std", "alloc", "clock"]} chrono = { version="^0.4.23", default-features=false, features=["std", "alloc", "clock"]}
clap = { version = "4.0", features = ["wrap_help", "cargo"] } clap = { version = "4.1", features = ["wrap_help", "cargo"] }
clap_complete = "4.0" clap_complete = "4.0"
clap_mangen = "0.2" clap_mangen = "0.2"
compare = "0.1.0" compare = "0.1.0"
@ -308,7 +308,7 @@ platform-info = "1.0.2"
quick-error = "2.0.1" quick-error = "2.0.1"
rand = { version = "0.8", features = ["small_rng"] } rand = { version = "0.8", features = ["small_rng"] }
rand_core = "0.6" rand_core = "0.6"
rayon = "1.5" rayon = "1.7"
redox_syscall = "0.2" redox_syscall = "0.2"
regex = "1.7.1" regex = "1.7.1"
rust-ini = "0.18.0" rust-ini = "0.18.0"

View file

@ -11,10 +11,10 @@ cargo-fuzz = true
libfuzzer-sys = "0.4" libfuzzer-sys = "0.4"
[dependencies.uucore] [dependencies.uucore]
uucore = { workspace = true } path = "../src/uucore/"
[dependencies.uu_date] [dependencies.uu_date]
uu_date = { workspace = true } path = "../src/uu/date/"
# Prevent this from interfering with workspaces # Prevent this from interfering with workspaces
[workspace] [workspace]

View file

@ -56,7 +56,7 @@ where
I: PeekRead, I: PeekRead,
{ {
/// calls `peek_read` on the internal stream to (re)fill the buffer. Returns a /// calls `peek_read` on the internal stream to (re)fill the buffer. Returns a
/// MemoryDecoder providing access to the result or returns an i/o error. /// `MemoryDecoder` providing access to the result or returns an i/o error.
pub fn peek_read(&mut self) -> io::Result<MemoryDecoder> { pub fn peek_read(&mut self) -> io::Result<MemoryDecoder> {
match self match self
.input .input
@ -81,7 +81,7 @@ impl<'a, I> HasError for InputDecoder<'a, I>
where where
I: HasError, I: HasError,
{ {
/// calls has_error on the internal stream. /// calls `has_error` on the internal stream.
fn has_error(&self) -> bool { fn has_error(&self) -> bool {
self.input.has_error() self.input.has_error()
} }

View file

@ -28,17 +28,17 @@ mod prn_int;
use std::cmp; use std::cmp;
use std::fmt::Write; use std::fmt::Write;
use crate::byteorder_io::*; use crate::byteorder_io::ByteOrder;
use crate::formatteriteminfo::*; use crate::formatteriteminfo::FormatWriter;
use crate::inputdecoder::{InputDecoder, MemoryDecoder}; use crate::inputdecoder::{InputDecoder, MemoryDecoder};
use crate::inputoffset::{InputOffset, Radix}; use crate::inputoffset::{InputOffset, Radix};
use crate::multifilereader::*; use crate::multifilereader::{HasError, InputSource, MultifileReader};
use crate::output_info::OutputInfo; use crate::output_info::OutputInfo;
use crate::parse_formats::{parse_format_flags, ParsedFormatterItemInfo}; use crate::parse_formats::{parse_format_flags, ParsedFormatterItemInfo};
use crate::parse_inputs::{parse_inputs, CommandLineInputs}; use crate::parse_inputs::{parse_inputs, CommandLineInputs};
use crate::parse_nrofbytes::parse_number_of_bytes; use crate::parse_nrofbytes::parse_number_of_bytes;
use crate::partialreader::*; use crate::partialreader::PartialReader;
use crate::peekreader::*; use crate::peekreader::{PeekRead, PeekReader};
use crate::prn_char::format_ascii_dump; use crate::prn_char::format_ascii_dump;
use clap::ArgAction; use clap::ArgAction;
use clap::{crate_version, parser::ValueSource, Arg, ArgMatches, Command}; use clap::{crate_version, parser::ValueSource, Arg, ArgMatches, Command};
@ -48,10 +48,9 @@ use uucore::parse_size::ParseSizeError;
use uucore::{format_usage, help_about, help_section, help_usage, show_error, show_warning}; use uucore::{format_usage, help_about, help_section, help_usage, show_error, show_warning};
const PEEK_BUFFER_SIZE: usize = 4; // utf-8 can be 4 bytes const PEEK_BUFFER_SIZE: usize = 4; // utf-8 can be 4 bytes
const ABOUT: &str = help_about!("od.md"); const ABOUT: &str = help_about!("od.md");
const USAGE: &str = help_usage!("od.md"); const USAGE: &str = help_usage!("od.md");
const AFTER_HELP: &str = help_section!("after help", "od.md"); const AFTER_HELP: &str = help_section!("after help", "od.md");
pub(crate) mod options { pub(crate) mod options {
@ -460,7 +459,7 @@ pub fn uu_app() -> Command {
) )
} }
/// Loops through the input line by line, calling print_bytes to take care of the output. /// Loops through the input line by line, calling `print_bytes` to take care of the output.
fn odfunc<I>( fn odfunc<I>(
input_offset: &mut InputOffset, input_offset: &mut InputOffset,
input_decoder: &mut InputDecoder<I>, input_decoder: &mut InputDecoder<I>,

View file

@ -139,7 +139,7 @@ impl OutputInfo {
/// ``` /// ```
/// ///
/// This algorithm assumes the size of all types is a power of 2 (1, 2, 4, 8, 16, ...) /// This algorithm assumes the size of all types is a power of 2 (1, 2, 4, 8, 16, ...)
/// Increase MAX_BYTES_PER_UNIT to allow larger types. /// Increase `MAX_BYTES_PER_UNIT` to allow larger types.
fn calculate_alignment( fn calculate_alignment(
sf: &dyn TypeSizeInfo, sf: &dyn TypeSizeInfo,
byte_size_block: usize, byte_size_block: usize,

View file

@ -90,8 +90,8 @@ pub fn parse_inputs(matches: &dyn CommandLineOpts) -> Result<CommandLineInputs,
/// interprets inputs when --traditional is on the command line /// interprets inputs when --traditional is on the command line
/// ///
/// normally returns CommandLineInputs::FileAndOffset, but if no offset is found, /// normally returns `CommandLineInputs::FileAndOffset`, but if no offset is found,
/// it returns CommandLineInputs::FileNames (also to differentiate from the offset == 0) /// it returns `CommandLineInputs::FileNames` (also to differentiate from the offset == 0)
pub fn parse_inputs_traditional(input_strings: &[&str]) -> Result<CommandLineInputs, String> { pub fn parse_inputs_traditional(input_strings: &[&str]) -> Result<CommandLineInputs, String> {
match input_strings.len() { match input_strings.len() {
0 => Ok(CommandLineInputs::FileNames(vec!["-".to_string()])), 0 => Ok(CommandLineInputs::FileNames(vec!["-".to_string()])),

View file

@ -1,6 +1,6 @@
use std::str::from_utf8; use std::str::from_utf8;
use crate::formatteriteminfo::*; use crate::formatteriteminfo::{FormatWriter, FormatterItemInfo};
pub static FORMAT_ITEM_A: FormatterItemInfo = FormatterItemInfo { pub static FORMAT_ITEM_A: FormatterItemInfo = FormatterItemInfo {
byte_size: 1, byte_size: 1,

View file

@ -3,7 +3,7 @@ use std::f32;
use std::f64; use std::f64;
use std::num::FpCategory; use std::num::FpCategory;
use crate::formatteriteminfo::*; use crate::formatteriteminfo::{FormatWriter, FormatterItemInfo};
pub static FORMAT_ITEM_F16: FormatterItemInfo = FormatterItemInfo { pub static FORMAT_ITEM_F16: FormatterItemInfo = FormatterItemInfo {
byte_size: 2, byte_size: 2,

View file

@ -16,9 +16,13 @@ use std::fs;
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
use std::io; use std::io;
use std::io::prelude::*; use std::io::prelude::*;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
#[cfg(unix)]
use uucore::libc::S_IWUSR;
use uucore::{format_usage, show, show_if_err, util_name}; use uucore::{format_usage, show, show_if_err, util_name};
const BLOCK_SIZE: usize = 512; const BLOCK_SIZE: usize = 512;
@ -462,6 +466,18 @@ fn wipe_file(
if force { if force {
let metadata = fs::metadata(path).map_err_context(String::new)?; let metadata = fs::metadata(path).map_err_context(String::new)?;
let mut perms = metadata.permissions(); let mut perms = metadata.permissions();
#[cfg(unix)]
#[allow(clippy::useless_conversion)]
{
// NOTE: set_readonly(false) makes the file world-writable on Unix.
// NOTE: S_IWUSR type is u16 on macOS.
if (perms.mode() & u32::from(S_IWUSR)) == 0 {
perms.set_mode(u32::from(S_IWUSR));
}
}
#[cfg(not(unix))]
// TODO: Remove the following once https://github.com/rust-lang/rust-clippy/issues/10477 is resolved.
#[allow(clippy::permissions_set_readonly_false)]
perms.set_readonly(false); perms.set_readonly(false);
fs::set_permissions(path, perms).map_err_context(String::new)?; fs::set_permissions(path, perms).map_err_context(String::new)?;
} }

View file

@ -10,8 +10,9 @@ fn fix_negation(glob: &str) -> String {
let mut chars = glob.chars().collect::<Vec<_>>(); let mut chars = glob.chars().collect::<Vec<_>>();
let mut i = 0; let mut i = 0;
while i < chars.len() { // Add 3 to prevent out of bounds in loop
if chars[i] == '[' && i + 4 <= glob.len() && chars[i + 1] == '^' { while i + 3 < chars.len() {
if chars[i] == '[' && chars[i + 1] == '^' {
match chars[i + 3..].iter().position(|x| *x == ']') { match chars[i + 3..].iter().position(|x| *x == ']') {
None => (), None => (),
Some(j) => { Some(j) => {
@ -105,5 +106,8 @@ mod tests {
assert_eq!(fix_negation("[^]"), "[^]"); assert_eq!(fix_negation("[^]"), "[^]");
assert_eq!(fix_negation("[^"), "[^"); assert_eq!(fix_negation("[^"), "[^");
assert_eq!(fix_negation("[][^]"), "[][^]"); assert_eq!(fix_negation("[][^]"), "[][^]");
// Issue #4479
assert_eq!(fix_negation("ààà[^"), "ààà[^");
} }
} }

View file

@ -86,7 +86,7 @@ fn test_wrap() {
fn test_wrap_no_arg() { fn test_wrap_no_arg() {
for wrap_param in ["-w", "--wrap"] { for wrap_param in ["-w", "--wrap"] {
let ts = TestScenario::new(util_name!()); let ts = TestScenario::new(util_name!());
let expected_stderr = "The argument '--wrap <COLS>' requires a value but none was supplied"; let expected_stderr = "a value is required for '--wrap <COLS>' but none was supplied";
ts.ucmd() ts.ucmd()
.arg(wrap_param) .arg(wrap_param)
.fails() .fails()

View file

@ -79,7 +79,7 @@ fn test_wrap_no_arg() {
new_ucmd!() new_ucmd!()
.arg(wrap_param) .arg(wrap_param)
.fails() .fails()
.stderr_contains("The argument '--wrap <COLS>' requires a value but none was supplied") .stderr_contains("a value is required for '--wrap <COLS>' but none was supplied")
.no_stdout(); .no_stdout();
} }
} }

View file

@ -196,7 +196,7 @@ fn test_missing_files() {
.arg("groupname") .arg("groupname")
.fails() .fails()
.stderr_contains( .stderr_contains(
"error: The following required arguments were not provided:\n <FILE>...\n", "error: the following required arguments were not provided:\n <FILE>...\n",
); );
} }

View file

@ -15,7 +15,7 @@ fn test_missing_operand() {
assert!(result assert!(result
.stderr_str() .stderr_str()
.starts_with("error: The following required arguments were not provided")); .starts_with("error: the following required arguments were not provided"));
assert!(result.stderr_str().contains("<newroot>")); assert!(result.stderr_str().contains("<newroot>"));
} }

View file

@ -1495,7 +1495,7 @@ fn test_cp_reflink_bad() {
.arg(TEST_HELLO_WORLD_SOURCE) .arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_EXISTING_FILE) .arg(TEST_EXISTING_FILE)
.fails() .fails()
.stderr_contains("error: 'bad' isn't a valid value for '--reflink[=<WHEN>]'"); .stderr_contains("error: invalid value 'bad' for '--reflink[=<WHEN>]'");
} }
#[test] #[test]

View file

@ -52,7 +52,7 @@ fn test_link_one_argument() {
let file = "test_link_argument"; let file = "test_link_argument";
ucmd.args(&[file]) ucmd.args(&[file])
.fails() .fails()
.stderr_contains("requires 2 values"); .stderr_contains("2 values required");
} }
#[test] #[test]
@ -65,5 +65,5 @@ fn test_link_three_arguments() {
]; ];
ucmd.args(&arguments[..]) ucmd.args(&arguments[..])
.fails() .fails()
.stderr_contains("requires 2 values"); .stderr_contains("2 values required");
} }

View file

@ -92,14 +92,14 @@ fn test_mknod_character_device_requires_major_and_minor() {
.arg("1") .arg("1")
.arg("c") .arg("c")
.fails() .fails()
.stderr_contains("Invalid value 'c'"); .stderr_contains("invalid value 'c'");
new_ucmd!() new_ucmd!()
.arg("test_file") .arg("test_file")
.arg("c") .arg("c")
.arg("c") .arg("c")
.arg("1") .arg("1")
.fails() .fails()
.stderr_contains("Invalid value 'c'"); .stderr_contains("invalid value 'c'");
} }
#[test] #[test]
@ -109,7 +109,7 @@ fn test_mknod_invalid_arg() {
.arg("--foo") .arg("--foo")
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains("Found argument '--foo' which wasn't expected"); .stderr_contains("unexpected argument '--foo' found");
} }
#[test] #[test]

View file

@ -36,18 +36,12 @@ fn test_hex_rejects_sign_after_identifier() {
.args(&["-0x-123ABC"]) .args(&["-0x-123ABC"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains( .stderr_contains("unexpected argument '-0' found");
"Found argument '-0' which wasn't expected, or isn't valid in this context",
)
.stderr_contains("For more information try '--help'");
new_ucmd!() new_ucmd!()
.args(&["-0x+123ABC"]) .args(&["-0x+123ABC"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains( .stderr_contains("unexpected argument '-0' found");
"Found argument '-0' which wasn't expected, or isn't valid in this context",
)
.stderr_contains("For more information try '--help'");
} }
#[test] #[test]

View file

@ -999,7 +999,7 @@ fn test_conflict_check_out() {
.fails() .fails()
.stderr_contains( .stderr_contains(
// the rest of the message might be subject to change // the rest of the message might be subject to change
"error: The argument", "error: the argument",
); );
} }
} }

View file

@ -30,7 +30,7 @@ fn test_stdbuf_no_buffer_option_fails() {
ts.ucmd() ts.ucmd()
.args(&["head"]) .args(&["head"])
.fails() .fails()
.stderr_contains("The following required arguments were not provided:"); .stderr_contains("the following required arguments were not provided:");
} }
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]

View file

@ -194,7 +194,7 @@ fn test_error_filename_only() {
.args(&["file"]) .args(&["file"])
.fails() .fails()
.code_is(1) .code_is(1)
.stderr_contains("error: The following required arguments were not provided:"); .stderr_contains("error: the following required arguments were not provided:");
} }
#[test] #[test]

View file

@ -50,7 +50,5 @@ fn test_multiple_arguments() {
.arg("call_graph.txt") .arg("call_graph.txt")
.arg("invalid_file") .arg("invalid_file")
.fails() .fails()
.stderr_contains( .stderr_contains("unexpected argument 'invalid_file' found");
"Found argument 'invalid_file' which wasn't expected, or isn't valid in this context",
);
} }

View file

@ -151,7 +151,7 @@ fn test_arg1_arg2() {
#[test] #[test]
fn test_too_many_args() { fn test_too_many_args() {
const EXPECTED: &str = const EXPECTED: &str =
"error: The value 'u' was provided to '[FILE]...' but it wasn't expecting any more values"; "error: unexpected value 'u' for '[FILE]...' found; no more were expected";
let args = ["am", "i", "u"]; let args = ["am", "i", "u"];
new_ucmd!().args(&args).fails().stderr_contains(EXPECTED); new_ucmd!().args(&args).fails().stderr_contains(EXPECTED);