1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

chore: delete show_info macro and replace with show_error

This commit is contained in:
Yağız can Değirmenci 2021-05-26 02:27:10 +03:00
parent cdd74afa3f
commit c78a7937f8
15 changed files with 60 additions and 69 deletions

View file

@ -347,7 +347,7 @@ fn cat_files(files: Vec<String>, options: &OutputOptions) -> Result<(), u32> {
for path in &files { for path in &files {
if let Err(err) = cat_path(path, &options, &mut state) { if let Err(err) = cat_path(path, &options, &mut state) {
show_info!("{}: {}", path, err); show_error!("{}: {}", path, err);
error_count += 1; error_count += 1;
} }
} }

View file

@ -97,7 +97,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if recursive { if recursive {
if bit_flag == FTS_PHYSICAL { if bit_flag == FTS_PHYSICAL {
if derefer == 1 { if derefer == 1 {
show_info!("-R --dereference requires -H or -L"); show_error!("-R --dereference requires -H or -L");
return 1; return 1;
} }
derefer = 0; derefer = 0;
@ -132,7 +132,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
dest_gid = meta.gid(); dest_gid = meta.gid();
} }
Err(e) => { Err(e) => {
show_info!("failed to get attributes of '{}': {}", file, e); show_error!("failed to get attributes of '{}': {}", file, e);
return 1; return 1;
} }
} }
@ -143,7 +143,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
dest_gid = g; dest_gid = g;
} }
_ => { _ => {
show_info!("invalid group: {}", matches.free[0].as_str()); show_error!("invalid group: {}", matches.free[0].as_str());
return 1; return 1;
} }
} }
@ -235,8 +235,8 @@ impl Chgrper {
if let Some(p) = may_exist { if let Some(p) = may_exist {
if p.parent().is_none() || self.is_bind_root(p) { if p.parent().is_none() || self.is_bind_root(p) {
show_info!("it is dangerous to operate recursively on '/'"); show_error!("it is dangerous to operate recursively on '/'");
show_info!("use --no-preserve-root to override this failsafe"); show_error!("use --no-preserve-root to override this failsafe");
return 1; return 1;
} }
} }
@ -250,12 +250,12 @@ impl Chgrper {
self.verbosity.clone(), self.verbosity.clone(),
) { ) {
Ok(n) => { Ok(n) => {
show_info!("{}", n); show_error!("{}", n);
0 0
} }
Err(e) => { Err(e) => {
if self.verbosity != Verbosity::Silent { if self.verbosity != Verbosity::Silent {
show_info!("{}", e); show_error!("{}", e);
} }
1 1
} }
@ -275,7 +275,7 @@ impl Chgrper {
for entry in WalkDir::new(root).follow_links(follow).min_depth(1) { for entry in WalkDir::new(root).follow_links(follow).min_depth(1) {
let entry = unwrap!(entry, e, { let entry = unwrap!(entry, e, {
ret = 1; ret = 1;
show_info!("{}", e); show_error!("{}", e);
continue; continue;
}); });
let path = entry.path(); let path = entry.path();
@ -290,13 +290,13 @@ impl Chgrper {
ret = match wrap_chgrp(path, &meta, self.dest_gid, follow, self.verbosity.clone()) { ret = match wrap_chgrp(path, &meta, self.dest_gid, follow, self.verbosity.clone()) {
Ok(n) => { Ok(n) => {
if !n.is_empty() { if !n.is_empty() {
show_info!("{}", n); show_error!("{}", n);
} }
0 0
} }
Err(e) => { Err(e) => {
if self.verbosity != Verbosity::Silent { if self.verbosity != Verbosity::Silent {
show_info!("{}", e); show_error!("{}", e);
} }
1 1
} }
@ -313,7 +313,7 @@ impl Chgrper {
unwrap!(path.metadata(), e, { unwrap!(path.metadata(), e, {
match self.verbosity { match self.verbosity {
Silent => (), Silent => (),
_ => show_info!("cannot access '{}': {}", path.display(), e), _ => show_error!("cannot access '{}': {}", path.display(), e),
} }
return None; return None;
}) })
@ -321,7 +321,7 @@ impl Chgrper {
unwrap!(path.symlink_metadata(), e, { unwrap!(path.symlink_metadata(), e, {
match self.verbosity { match self.verbosity {
Silent => (), Silent => (),
_ => show_info!("cannot dereference '{}': {}", path.display(), e), _ => show_error!("cannot dereference '{}': {}", path.display(), e),
} }
return None; return None;
}) })

View file

@ -316,7 +316,7 @@ impl Chmoder {
show_error!("{}", err); show_error!("{}", err);
} }
if self.verbose { if self.verbose {
show_info!( show_error!(
"failed to change mode of file '{}' from {:o} ({}) to {:o} ({})", "failed to change mode of file '{}' from {:o} ({}) to {:o} ({})",
file.display(), file.display(),
fperm, fperm,
@ -328,7 +328,7 @@ impl Chmoder {
Err(1) Err(1)
} else { } else {
if self.verbose || self.changes { if self.verbose || self.changes {
show_info!( show_error!(
"mode of '{}' changed from {:o} ({}) to {:o} ({})", "mode of '{}' changed from {:o} ({}) to {:o} ({})",
file.display(), file.display(),
fperm, fperm,

View file

@ -199,7 +199,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if recursive { if recursive {
if bit_flag == FTS_PHYSICAL { if bit_flag == FTS_PHYSICAL {
if derefer == 1 { if derefer == 1 {
show_info!("-R --dereference requires -H or -L"); show_error!("-R --dereference requires -H or -L");
return 1; return 1;
} }
derefer = 0; derefer = 0;
@ -227,7 +227,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
Ok((Some(uid), Some(gid))) => IfFrom::UserGroup(uid, gid), Ok((Some(uid), Some(gid))) => IfFrom::UserGroup(uid, gid),
Ok((None, None)) => IfFrom::All, Ok((None, None)) => IfFrom::All,
Err(e) => { Err(e) => {
show_info!("{}", e); show_error!("{}", e);
return 1; return 1;
} }
} }
@ -244,7 +244,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
dest_uid = Some(meta.uid()); dest_uid = Some(meta.uid());
} }
Err(e) => { Err(e) => {
show_info!("failed to get attributes of '{}': {}", file, e); show_error!("failed to get attributes of '{}': {}", file, e);
return 1; return 1;
} }
} }
@ -255,7 +255,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
dest_gid = g; dest_gid = g;
} }
Err(e) => { Err(e) => {
show_info!("{}", e); show_error!("{}", e);
return 1; return 1;
} }
} }
@ -377,8 +377,8 @@ impl Chowner {
if let Some(p) = may_exist { if let Some(p) = may_exist {
if p.parent().is_none() { if p.parent().is_none() {
show_info!("it is dangerous to operate recursively on '/'"); show_error!("it is dangerous to operate recursively on '/'");
show_info!("use --no-preserve-root to override this failsafe"); show_error!("use --no-preserve-root to override this failsafe");
return 1; return 1;
} }
} }
@ -395,13 +395,13 @@ impl Chowner {
) { ) {
Ok(n) => { Ok(n) => {
if !n.is_empty() { if !n.is_empty() {
show_info!("{}", n); show_error!("{}", n);
} }
0 0
} }
Err(e) => { Err(e) => {
if self.verbosity != Verbosity::Silent { if self.verbosity != Verbosity::Silent {
show_info!("{}", e); show_error!("{}", e);
} }
1 1
} }
@ -424,7 +424,7 @@ impl Chowner {
for entry in WalkDir::new(root).follow_links(follow).min_depth(1) { for entry in WalkDir::new(root).follow_links(follow).min_depth(1) {
let entry = unwrap!(entry, e, { let entry = unwrap!(entry, e, {
ret = 1; ret = 1;
show_info!("{}", e); show_error!("{}", e);
continue; continue;
}); });
let path = entry.path(); let path = entry.path();
@ -450,13 +450,13 @@ impl Chowner {
) { ) {
Ok(n) => { Ok(n) => {
if !n.is_empty() { if !n.is_empty() {
show_info!("{}", n); show_error!("{}", n);
} }
0 0
} }
Err(e) => { Err(e) => {
if self.verbosity != Verbosity::Silent { if self.verbosity != Verbosity::Silent {
show_info!("{}", e); show_error!("{}", e);
} }
1 1
} }
@ -472,7 +472,7 @@ impl Chowner {
unwrap!(path.metadata(), e, { unwrap!(path.metadata(), e, {
match self.verbosity { match self.verbosity {
Silent => (), Silent => (),
_ => show_info!("cannot access '{}': {}", path.display(), e), _ => show_error!("cannot access '{}': {}", path.display(), e),
} }
return None; return None;
}) })
@ -480,7 +480,7 @@ impl Chowner {
unwrap!(path.symlink_metadata(), e, { unwrap!(path.symlink_metadata(), e, {
match self.verbosity { match self.verbosity {
Silent => (), Silent => (),
_ => show_info!("cannot dereference '{}': {}", path.display(), e), _ => show_error!("cannot dereference '{}': {}", path.display(), e),
} }
return None; return None;
}) })

View file

@ -105,7 +105,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if out_format == OutputFmt::Unknown { if out_format == OutputFmt::Unknown {
match guess_syntax() { match guess_syntax() {
OutputFmt::Unknown => { OutputFmt::Unknown => {
show_info!("no SHELL environment variable, and no shell type option given"); show_error!("no SHELL environment variable, and no shell type option given");
return 1; return 1;
} }
fmt => out_format = fmt, fmt => out_format = fmt,
@ -130,7 +130,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
) )
} }
Err(e) => { Err(e) => {
show_info!("{}: {}", matches.free[0], e); show_error!("{}: {}", matches.free[0], e);
return 1; return 1;
} }
} }
@ -141,7 +141,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
0 0
} }
Err(s) => { Err(s) => {
show_info!("{}", s); show_error!("{}", s);
1 1
} }
} }

View file

@ -370,13 +370,13 @@ fn directory(paths: Vec<String>, b: Behavior) -> i32 {
// created ancestor directories will have the default mode. Hence it is safe to use // created ancestor directories will have the default mode. Hence it is safe to use
// fs::create_dir_all and then only modify the target's dir mode. // fs::create_dir_all and then only modify the target's dir mode.
if let Err(e) = fs::create_dir_all(path) { if let Err(e) = fs::create_dir_all(path) {
show_info!("{}: {}", path.display(), e); show_error!("{}: {}", path.display(), e);
all_successful = false; all_successful = false;
continue; continue;
} }
if b.verbose { if b.verbose {
show_info!("creating directory '{}'", path.display()); show_error!("creating directory '{}'", path.display());
} }
} }
@ -461,7 +461,7 @@ fn copy_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> i3
let mut all_successful = true; let mut all_successful = true;
for sourcepath in files.iter() { for sourcepath in files.iter() {
if !sourcepath.exists() { if !sourcepath.exists() {
show_info!( show_error!(
"cannot stat '{}': No such file or directory", "cannot stat '{}': No such file or directory",
sourcepath.display() sourcepath.display()
); );
@ -471,7 +471,7 @@ fn copy_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> i3
} }
if sourcepath.is_dir() { if sourcepath.is_dir() {
show_info!("omitting directory '{}'", sourcepath.display()); show_error!("omitting directory '{}'", sourcepath.display());
all_successful = false; all_successful = false;
continue; continue;
} }
@ -588,10 +588,10 @@ fn copy(from: &Path, to: &Path, b: &Behavior) -> Result<(), ()> {
) { ) {
Ok(n) => { Ok(n) => {
if !n.is_empty() { if !n.is_empty() {
show_info!("{}", n); show_error!("{}", n);
} }
} }
Err(e) => show_info!("{}", e), Err(e) => show_error!("{}", e),
} }
} }
@ -608,10 +608,10 @@ fn copy(from: &Path, to: &Path, b: &Behavior) -> Result<(), ()> {
match wrap_chgrp(to, &meta, group_id, false, Verbosity::Normal) { match wrap_chgrp(to, &meta, group_id, false, Verbosity::Normal) {
Ok(n) => { Ok(n) => {
if !n.is_empty() { if !n.is_empty() {
show_info!("{}", n); show_error!("{}", n);
} }
} }
Err(e) => show_info!("{}", e), Err(e) => show_error!("{}", e),
} }
} }
@ -626,12 +626,12 @@ fn copy(from: &Path, to: &Path, b: &Behavior) -> Result<(), ()> {
match set_file_times(to, accessed_time, modified_time) { match set_file_times(to, accessed_time, modified_time) {
Ok(_) => {} Ok(_) => {}
Err(e) => show_info!("{}", e), Err(e) => show_error!("{}", e),
} }
} }
if b.verbose { if b.verbose {
show_info!("'{}' -> '{}'", from.display(), to.display()); show_error!("'{}' -> '{}'", from.display(), to.display());
} }
Ok(()) Ok(())

View file

@ -23,7 +23,7 @@ pub fn parse(mode_string: &str, considering_dir: bool) -> Result<u32, String> {
pub fn chmod(path: &Path, mode: u32) -> Result<(), ()> { pub fn chmod(path: &Path, mode: u32) -> Result<(), ()> {
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
fs::set_permissions(path, fs::Permissions::from_mode(mode)).map_err(|err| { fs::set_permissions(path, fs::Permissions::from_mode(mode)).map_err(|err| {
show_info!("{}: chmod failed with error {}", path.display(), err); show_error!("{}: chmod failed with error {}", path.display(), err);
}) })
} }

View file

@ -101,7 +101,7 @@ fn exec(dirs: Vec<String>, recursive: bool, mode: u16, verbose: bool) -> i32 {
if !recursive { if !recursive {
if let Some(parent) = path.parent() { if let Some(parent) = path.parent() {
if parent != empty && !parent.exists() { if parent != empty && !parent.exists() {
show_info!( show_error!(
"cannot create directory '{}': No such file or directory", "cannot create directory '{}': No such file or directory",
path.display() path.display()
); );
@ -125,7 +125,7 @@ fn mkdir(path: &Path, recursive: bool, mode: u16, verbose: bool) -> i32 {
fs::create_dir fs::create_dir
}; };
if let Err(e) = create_dir(path) { if let Err(e) = create_dir(path) {
show_info!("{}: {}", path.display(), e.to_string()); show_error!("{}: {}", path.display(), e.to_string());
return 1; return 1;
} }

View file

@ -136,7 +136,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
let mode = match get_mode(&matches) { let mode = match get_mode(&matches) {
Ok(mode) => mode, Ok(mode) => mode,
Err(err) => { Err(err) => {
show_info!("{}", err); show_error!("{}", err);
return 1; return 1;
} }
}; };

View file

@ -157,7 +157,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
if matches.is_present(OPT_TMPDIR) && PathBuf::from(prefix).is_absolute() { if matches.is_present(OPT_TMPDIR) && PathBuf::from(prefix).is_absolute() {
show_info!( show_error!(
"invalid template, {}; with --tmpdir, it may not be absolute", "invalid template, {}; with --tmpdir, it may not be absolute",
template template
); );
@ -229,7 +229,7 @@ fn exec(
} }
Err(e) => { Err(e) => {
if !quiet { if !quiet {
show_info!("{}: {}", e, tmpdir.display()); show_error!("{}: {}", e, tmpdir.display());
} }
return 1; return 1;
} }
@ -244,7 +244,7 @@ fn exec(
Ok(f) => f, Ok(f) => f,
Err(e) => { Err(e) => {
if !quiet { if !quiet {
show_info!("failed to create tempfile: {}", e); show_error!("failed to create tempfile: {}", e);
} }
return 1; return 1;
} }

View file

@ -122,13 +122,13 @@ fn find_stdout() -> File {
.open(Path::new(NOHUP_OUT)) .open(Path::new(NOHUP_OUT))
{ {
Ok(t) => { Ok(t) => {
show_info!("ignoring input and appending output to '{}'", NOHUP_OUT); show_error!("ignoring input and appending output to '{}'", NOHUP_OUT);
t t
} }
Err(e1) => { Err(e1) => {
let home = match env::var("HOME") { let home = match env::var("HOME") {
Err(_) => { Err(_) => {
show_info!("failed to open '{}': {}", NOHUP_OUT, e1); show_error!("failed to open '{}': {}", NOHUP_OUT, e1);
exit!(internal_failure_code) exit!(internal_failure_code)
} }
Ok(h) => h, Ok(h) => h,
@ -143,12 +143,12 @@ fn find_stdout() -> File {
.open(&homeout) .open(&homeout)
{ {
Ok(t) => { Ok(t) => {
show_info!("ignoring input and appending output to '{}'", homeout_str); show_error!("ignoring input and appending output to '{}'", homeout_str);
t t
} }
Err(e2) => { Err(e2) => {
show_info!("failed to open '{}': {}", NOHUP_OUT, e1); show_error!("failed to open '{}': {}", NOHUP_OUT, e1);
show_info!("failed to open '{}': {}", homeout_str, e2); show_error!("failed to open '{}': {}", homeout_str, e2);
exit!(internal_failure_code) exit!(internal_failure_code)
} }
} }

View file

@ -216,7 +216,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
match result { match result {
Err(e) => { Err(e) => {
std::io::stdout().flush().expect("error flushing stdout"); std::io::stdout().flush().expect("error flushing stdout");
show_info!("{}", e); show_error!("{}", e);
1 1
} }
_ => 0, _ => 0,

View file

@ -749,7 +749,7 @@ impl Stater {
} }
} }
Err(e) => { Err(e) => {
show_info!("cannot stat '{}': {}", file, e); show_error!("cannot stat '{}': {}", file, e);
return 1; return 1;
} }
} }
@ -842,7 +842,7 @@ impl Stater {
} }
} }
Err(e) => { Err(e) => {
show_info!("cannot read file system information for '{}': {}", file, e); show_error!("cannot read file system information for '{}': {}", file, e);
return 1; return 1;
} }
} }
@ -1001,7 +1001,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
match Stater::new(matches) { match Stater::new(matches) {
Ok(stater) => stater.exec(), Ok(stater) => stater.exec(),
Err(e) => { Err(e) => {
show_info!("{}", e); show_error!("{}", e);
1 1
} }
} }

View file

@ -166,7 +166,7 @@ impl Write for MultiWriter {
let result = writer.write_all(buf); let result = writer.write_all(buf);
match result { match result {
Err(f) => { Err(f) => {
show_info!("{}: {}", writer.name, f.to_string()); show_error!("{}: {}", writer.name, f.to_string());
false false
} }
_ => true, _ => true,
@ -180,7 +180,7 @@ impl Write for MultiWriter {
let result = writer.flush(); let result = writer.flush();
match result { match result {
Err(f) => { Err(f) => {
show_info!("{}: {}", writer.name, f.to_string()); show_error!("{}: {}", writer.name, f.to_string());
false false
} }
_ => true, _ => true,
@ -213,7 +213,7 @@ impl Read for NamedReader {
fn read(&mut self, buf: &mut [u8]) -> Result<usize> { fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
match self.inner.read(buf) { match self.inner.read(buf) {
Err(f) => { Err(f) => {
show_info!("{}: {}", Path::new("stdin").display(), f.to_string()); show_error!("{}: {}", Path::new("stdin").display(), f.to_string());
Err(f) Err(f)
} }
okay => okay, okay => okay,

View file

@ -47,15 +47,6 @@ macro_rules! show_warning(
}) })
); );
/// Show an info message to stderr in a silimar style to GNU coreutils.
#[macro_export]
macro_rules! show_info(
($($args:tt)+) => ({
eprint!("{}: ", executable!());
eprintln!($($args)+);
})
);
/// Show a bad inocation help message in a similar style to GNU coreutils. /// Show a bad inocation help message in a similar style to GNU coreutils.
#[macro_export] #[macro_export]
macro_rules! show_usage_error( macro_rules! show_usage_error(