+
Skip to content

find: Use matcher_io.set_exit_code() #516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/find/matchers/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@
}

#[cfg(unix)]
fn print(&self, file_info: &WalkEntry, mut out: impl Write, print_error_message: bool) {
fn print(
&self,
file_info: &WalkEntry,
matcher_io: &mut MatcherIO,
mut out: impl Write,
print_error_message: bool,
) {
use nix::unistd::{Gid, Group, Uid, User};
use std::os::unix::fs::{MetadataExt, PermissionsExt};

Expand Down Expand Up @@ -183,14 +189,20 @@
e
)
.unwrap();
uucore::error::set_exit_code(1);
matcher_io.set_exit_code(1);

Check warning on line 192 in src/find/matchers/ls.rs

View check run for this annotation

Codecov / codecov/patch

src/find/matchers/ls.rs#L192

Added line #L192 was not covered by tests
}
}
}
}

#[cfg(windows)]
fn print(&self, file_info: &WalkEntry, mut out: impl Write, print_error_message: bool) {
fn print(
&self,
file_info: &WalkEntry,
matcher_io: &mut MatcherIO,
mut out: impl Write,
print_error_message: bool,
) {
use std::os::windows::fs::MetadataExt;

let metadata = file_info.metadata().unwrap();
Expand Down Expand Up @@ -246,7 +258,7 @@
e
)
.unwrap();
uucore::error::set_exit_code(1);
matcher_io.set_exit_code(1);
}
}
}
Expand All @@ -256,10 +268,11 @@
impl Matcher for Ls {
fn matches(&self, file_info: &WalkEntry, matcher_io: &mut MatcherIO) -> bool {
if let Some(file) = &self.output_file {
self.print(file_info, file, true);
self.print(file_info, matcher_io, file, true);

Check warning on line 271 in src/find/matchers/ls.rs

View check run for this annotation

Codecov / codecov/patch

src/find/matchers/ls.rs#L271

Added line #L271 was not covered by tests
} else {
self.print(
file_info,
matcher_io,
&mut *matcher_io.deps.get_output().borrow_mut(),
false,
);
Expand Down
18 changes: 10 additions & 8 deletions src/find/matchers/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ impl Printer {
}
}

fn print(&self, file_info: &WalkEntry, mut out: impl Write, print_error_message: bool) {
fn print(
&self,
file_info: &WalkEntry,
matcher_io: &mut MatcherIO,
mut out: impl Write,
print_error_message: bool,
) {
match write!(
out,
"{}{}",
Expand All @@ -54,7 +60,7 @@ impl Printer {
e
)
.unwrap();
uucore::error::set_exit_code(1);
matcher_io.set_exit_code(1);
}
}
}
Expand All @@ -65,10 +71,11 @@ impl Printer {
impl Matcher for Printer {
fn matches(&self, file_info: &WalkEntry, matcher_io: &mut MatcherIO) -> bool {
if let Some(file) = &self.output_file {
self.print(file_info, file, true);
self.print(file_info, matcher_io, file, true);
} else {
self.print(
file_info,
matcher_io,
&mut *matcher_io.deps.get_output().borrow_mut(),
false,
);
Expand Down Expand Up @@ -124,11 +131,6 @@ mod tests {
let deps = FakeDependencies::new();

assert!(matcher.matches(&abbbc, &mut deps.new_matcher_io()));

// Reset the exit code global variable in case we run another test after this one
// See https://github.com/uutils/coreutils/issues/5777
uucore::error::set_exit_code(0);

assert!(deps.get_output_as_string().is_empty());
}
}
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载