grep: Properly update match state when handling files

This commit is contained in:
Tim Schumacher 2022-03-14 18:08:16 +01:00 committed by Andreas Kling
parent c1004b095e
commit 21bbff0349
Notes: sideshowbarker 2024-07-17 17:04:54 +09:00

View file

@ -186,8 +186,10 @@ ErrorOr<int> serenity_main(Main::Arguments args)
return false;
};
bool did_match_something = false;
auto handle_file = [&matches, binary_mode, suppress_errors, count_lines, quiet_mode,
user_specified_multiple_files, &matched_line_count](StringView filename, bool print_filename) -> bool {
user_specified_multiple_files, &matched_line_count, &did_match_something](StringView filename, bool print_filename) -> bool {
auto file = Core::File::construct(filename);
if (!file->open(Core::OpenMode::ReadOnly)) {
if (!suppress_errors)
@ -208,7 +210,9 @@ ErrorOr<int> serenity_main(Main::Arguments args)
auto line = file->read_line(file_size);
auto is_binary = memchr(line.characters(), 0, line.length()) != nullptr;
if (matches(line, filename, line_number, print_filename, is_binary) && is_binary && binary_mode == BinaryFileMode::Binary)
auto matched = matches(line, filename, line_number, print_filename, is_binary);
did_match_something = did_match_something || matched;
if (matched && is_binary && binary_mode == BinaryFileMode::Binary)
break;
}
@ -236,7 +240,6 @@ ErrorOr<int> serenity_main(Main::Arguments args)
}
};
bool did_match_something = false;
if (!files.size() && !recursive) {
char* line = nullptr;
size_t line_len = 0;