Skip to content

Commit

Permalink
Merge branch 'main' into fix-touch-stat-follow
Browse files Browse the repository at this point in the history
  • Loading branch information
ysthakur committed Feb 27, 2024
2 parents 1e066e7 + aa0d15d commit 2a11b2b
Show file tree
Hide file tree
Showing 73 changed files with 2,495 additions and 854 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ env:
on:
pull_request:
push:
tags:
branches:
- main

Expand Down
33 changes: 17 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ binary-heap-plus = "0.5.0"
bstr = "1.9"
bytecount = "0.6.7"
byteorder = "1.5.0"
chrono = { version = "^0.4.33", default-features = false, features = [
chrono = { version = "^0.4.34", default-features = false, features = [
"std",
"alloc",
"clock",
Expand All @@ -284,7 +284,7 @@ fts-sys = "0.2"
fundu = "2.0.0"
gcd = "2.3"
glob = "0.3.1"
half = "2.3"
half = "2.4"
hostname = "0.3"
indicatif = "0.17"
itertools = "0.12.1"
Expand All @@ -298,7 +298,7 @@ nix = { version = "0.27", default-features = false }
nom = "7.1.3"
notify = { version = "=6.0.1", features = ["macos_kqueue"] }
num-bigint = "0.4.4"
num-traits = "0.2.17"
num-traits = "0.2.18"
number_prefix = "0.4"
once_cell = "1.19.0"
onig = { version = "~6.4", default-features = false }
Expand All @@ -319,13 +319,13 @@ self_cell = "1.0.3"
selinux = "0.4"
signal-hook = "0.3.17"
smallvec = { version = "1.13", features = ["union"] }
tempfile = "3.10.0"
tempfile = "3.10.1"
uutils_term_grid = "0.3"
terminal_size = "0.3.0"
textwrap = { version = "0.16.0", features = ["terminal_size"] }
textwrap = { version = "0.16.1", features = ["terminal_size"] }
thiserror = "1.0"
time = { version = "0.3" }
unicode-segmentation = "1.10.1"
unicode-segmentation = "1.11.0"
unicode-width = "0.1.11"
utf-8 = "0.7.6"
walkdir = "2.4"
Expand Down
3 changes: 3 additions & 0 deletions fuzz/fuzz_targets/fuzz_printf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use uu_printf::uumain;

use rand::seq::SliceRandom;
use rand::Rng;
use std::env;
use std::ffi::OsString;

mod fuzz_common;
Expand Down Expand Up @@ -82,6 +83,8 @@ fuzz_target!(|_data: &[u8]| {
args.extend(printf_input.split_whitespace().map(OsString::from));
let rust_result = generate_and_run_uumain(&args, uumain, None);

// TODO remove once uutils printf supports localization
env::set_var("LC_ALL", "C");
let gnu_result = match run_gnu_cmd(CMD_PATH, &args[1..], false, None) {
Ok(result) => result,
Err(error_result) => {
Expand Down
11 changes: 6 additions & 5 deletions src/uu/base32/src/base_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,24 @@ pub fn base_app(about: &'static str, usage: &str) -> Command {
.short('d')
.long(options::DECODE)
.help("decode data")
.action(ArgAction::SetTrue),
.action(ArgAction::SetTrue)
.overrides_with(options::DECODE),
)
.arg(
Arg::new(options::IGNORE_GARBAGE)
.short('i')
.long(options::IGNORE_GARBAGE)
.help("when decoding, ignore non-alphabetic characters")
.action(ArgAction::SetTrue),
.action(ArgAction::SetTrue)
.overrides_with(options::IGNORE_GARBAGE),
)
.arg(
Arg::new(options::WRAP)
.short('w')
.long(options::WRAP)
.value_name("COLS")
.help(
"wrap encoded lines after COLS character (default 76, 0 to disable wrapping)",
),
.help("wrap encoded lines after COLS character (default 76, 0 to disable wrapping)")
.overrides_with(options::WRAP),
)
// "multiple" arguments are used to check whether there is more than one
// file passed in.
Expand Down
2 changes: 1 addition & 1 deletion src/uu/basename/basename.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# basename

```
basename NAME [SUFFIX]
basename [-z] NAME [SUFFIX]
basename OPTION... NAME...
```

Expand Down
100 changes: 33 additions & 67 deletions src/uu/basename/src/basename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,86 +27,48 @@ pub mod options {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();

// Since options have to go before names,
// if the first argument is not an option, then there is no option,
// and that implies there is exactly one name (no option => no -a option),
// so simple format is used
if args.len() > 1 && !args[1].starts_with('-') {
if args.len() > 3 {
return Err(UUsageError::new(
1,
format!("extra operand {}", args[3].to_string().quote()),
));
}
let suffix = if args.len() > 2 { args[2].as_ref() } else { "" };
println!("{}", basename(&args[1], suffix));
return Ok(());
}

//
// Argument parsing
//
let matches = uu_app().try_get_matches_from(args)?;

// too few arguments
if !matches.contains_id(options::NAME) {
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::<String>(options::SUFFIX).is_some();
let opt_multiple = matches.get_flag(options::MULTIPLE);
let multiple_paths = opt_suffix || opt_multiple;
let name_args_count = matches
let mut name_args = matches
.get_many::<String>(options::NAME)
.map(|n| n.len())
.unwrap_or(0);

// too many arguments
if !multiple_paths && name_args_count > 2 {
return Err(UUsageError::new(
1,
format!(
"extra operand {}",
matches
.get_many::<String>(options::NAME)
.unwrap()
.nth(2)
.unwrap()
.quote()
),
));
.unwrap_or_default()
.collect::<Vec<_>>();
if name_args.is_empty() {
return Err(UUsageError::new(1, "missing operand".to_string()));
}

let suffix = if opt_suffix {
matches.get_one::<String>(options::SUFFIX).unwrap()
} else if !opt_multiple && name_args_count > 1 {
let multiple_paths =
matches.get_one::<String>(options::SUFFIX).is_some() || matches.get_flag(options::MULTIPLE);
let suffix = if multiple_paths {
matches
.get_many::<String>(options::NAME)
.unwrap()
.nth(1)
.unwrap()
.get_one::<String>(options::SUFFIX)
.cloned()
.unwrap_or_default()
} else {
""
// "simple format"
match name_args.len() {
0 => panic!("already checked"),
1 => String::default(),
2 => name_args.pop().unwrap().clone(),
_ => {
return Err(UUsageError::new(
1,
format!("extra operand {}", name_args[2].quote(),),
));
}
}
};

//
// Main Program Processing
//

let paths: Vec<_> = if multiple_paths {
matches.get_many::<String>(options::NAME).unwrap().collect()
} else {
matches
.get_many::<String>(options::NAME)
.unwrap()
.take(1)
.collect()
};

for path in paths {
print!("{}{}", basename(path, suffix), line_ending);
for path in name_args {
print!("{}{}", basename(path, &suffix), line_ending);
}

Ok(())
Expand All @@ -123,27 +85,31 @@ pub fn uu_app() -> Command {
.short('a')
.long(options::MULTIPLE)
.help("support multiple arguments and treat each as a NAME")
.action(ArgAction::SetTrue),
.action(ArgAction::SetTrue)
.overrides_with(options::MULTIPLE),
)
.arg(
Arg::new(options::NAME)
.action(clap::ArgAction::Append)
.value_hint(clap::ValueHint::AnyPath)
.hide(true),
.hide(true)
.trailing_var_arg(true),
)
.arg(
Arg::new(options::SUFFIX)
.short('s')
.long(options::SUFFIX)
.value_name("SUFFIX")
.help("remove a trailing SUFFIX; implies -a"),
.help("remove a trailing SUFFIX; implies -a")
.overrides_with(options::SUFFIX),
)
.arg(
Arg::new(options::ZERO)
.short('z')
.long(options::ZERO)
.help("end each output line with NUL, not newline")
.action(ArgAction::SetTrue),
.action(ArgAction::SetTrue)
.overrides_with(options::ZERO),
)
}

Expand Down
14 changes: 8 additions & 6 deletions src/uu/basenc/src/basenc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ const ENCODINGS: &[(&str, Format, &str)] = &[
pub fn uu_app() -> Command {
let mut command = base_common::base_app(ABOUT, USAGE);
for encoding in ENCODINGS {
command = command.arg(
Arg::new(encoding.0)
.long(encoding.0)
.help(encoding.2)
.action(ArgAction::SetTrue),
);
let raw_arg = Arg::new(encoding.0)
.long(encoding.0)
.help(encoding.2)
.action(ArgAction::SetTrue);
let overriding_arg = ENCODINGS
.iter()
.fold(raw_arg, |arg, enc| arg.overrides_with(enc.0));
command = command.arg(overriding_arg);
}
command
}
Expand Down
2 changes: 1 addition & 1 deletion src/uu/chmod/src/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let recursive = matches.get_flag(options::RECURSIVE);
let fmode = match matches.get_one::<String>(options::REFERENCE) {
Some(fref) => match fs::metadata(fref) {
Ok(meta) => Some(meta.mode()),
Ok(meta) => Some(meta.mode() & 0o7777),
Err(err) => {
return Err(USimpleError::new(
1,
Expand Down
1 change: 0 additions & 1 deletion src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use std::os::unix::ffi::OsStrExt;
#[cfg(unix)]
use std::os::unix::fs::{FileTypeExt, PermissionsExt};
use std::path::{Path, PathBuf, StripPrefixError};
use std::string::ToString;

use clap::{builder::ValueParser, crate_version, Arg, ArgAction, ArgMatches, Command};
use filetime::FileTime;
Expand Down
Loading

0 comments on commit 2a11b2b

Please sign in to comment.